Sharing records between threads

  • Hi!


    I have defined a record type with some values that I will need in both the foreground task and the background task. I want to have a shared instance of this record type that can be seen by both tasks. What is the best way to do this? I want to avoid duplicating code if it is in any way possible, so I don't want do define the same record type in both tasks.


    Thanks in advance!


    /RoboticsMan

  • I believe only one task can have a declared value for the data. The others must declare the name but not the value.


    TRob1


    PERS DataExample NameHere:=1;


    BackgroundTask1


    PERS DataExample NameHere;


    BackgroundTask2


    PERS DataExample NameHere;

  • My question was more about the record type itself. Is there any way around having to define the same type in both tasks? As far as I know, a record type that has been defined in one task can only be seen in that task. So if I want to use the same type in another task, I will have to define it again, right? I would like to avoid that.


    /RoboticsMan

  • Just like my answer in your other thread. The solution is to install a module with the RECORD as shared. This will make the datatype available in all tasks. You can then create PERS data with the same name in several tasks to send data between tasks. But again. This stuff can be tricky depending on how many tasks you have, and how many background tasks are installed that you don't know about. It is quite normal to have a MODULE with records in each task. Normally you set those modules also to auto-load but instead of shared you just load them to AllMotionTasks. But in your case that probably wont work.

    In robotstudio when connected to your system, look under controller tab:
    > Configuration > Controller > Automatic Loading of Modules.

    I seem to remember that you need to perform a p-start for the module to load, this will clear the system of all modules so make a backup first.

    Also if you have a RECORD used as a datatype in your main RECORD that you use for programming. You can load that as shared+hidden in one module and the main RECORD as shared in another module. This will make the unused RECORDS invisible in the user level.

    Edit: I know i suck at explaining, i am trying my best :smiling_face:

Advertising from our partners