I use ‘PV_xgetadr’ function to access any variable in other task.
However, as seen in the pictures, I get an error when I reference the pointer variable in .typ.
When I define it as a reference in .var, I do not experience any problems.
But I prefer .typ for code integrity.
Is there a solution to this?
Unfortunately, it is not possible to do this. You can’t include a dynamic variable as part of a structure (at least within IEC languages like Structured Text). The entire structure would have to be dynamic. Your options are:
Use a non-structure variable to reference a non-structure variable
Use a non-structure variable to reference a member of a structure variable
Use a structure variable to reference a structure variable
Additionally, I’d recommend that you avoid using this method to access one program’s local variable(s) from another program. This will make things very tricky for readability and debugging later on. If the variable is to be accessed by multiple programs, it should be global. If it is not used by other programs, it should be local, and therefore should only be used by the program it is declared in.
You could also have a both a global and local copy of the variable. For instance, a global variable called gRequestSave and a local variable called CmdSave. One way to implement this is a scenario in which any program can request a save, but the local program will then only act on that request (and set CmdSave) if it is in a state to do so.