0

could anyone please help me with more information about how pointers, references and interface references behave during an online change?

What do I have do watch out for? I understand from other answers that pointers may be dangerous if these are not written during each cycle, but I will primarily use Interfaces and References.

krakers
  • 111
  • 10

1 Answers1

1

When an online change is made, variables, function blocks and other program parts may move in a different memory location. Therefore, if the pointer address is old information, it might refer to a memory address containing something else.

So if the pointers are used, they should be updated regularly with the ADR command, like you said.

When using references and interfaces, I don't see any problems with online change because the system should handle them automatically. In TwinCAT 3, the system will readdress variables automatically (source: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/9007199390694027.html&id=) and because it is Codesys based, I think it is the same with other systems.

When using references, it might be a good idea to check that the reference is valid. In TwinCAT 3 there is a function __ISVALIDREF and it should be also in other Codesys based systems.

Quirzo
  • 1,183
  • 8
  • 10
  • Thanks, now I only have to check if the Beckhoff functionality is supported in Codesys "core" also. :) I was planning to pass a reference to something in FB_init(), from your answer i reckon that will work because the references are updated even if FB_init() is not called? – krakers Aug 22 '17 at 06:06
  • I'm not absolutely sure, but I think it should work. You should try to test it somehow in the local soft PLC, maybe by changing the code a lot and many times? Or copying the referenced block/variable to a different memory location with memcpy function. – Quirzo Aug 23 '17 at 05:22