Can I change an address of a OPC UA variable via script?
Hi, I am wondering if someone knows if there its possibility to change the PLC identifier of a variable via script. I.e. I would like the variable bellow to a different address in the PLC
PLC identifier: |var|CODESYS Control Win V3 x64.Application.GVL.astItem[0].iStatus
New identifier
|var|CODESYS Control Win V3 x64.Application.GVL.Robot[1].iStatus
Best reply by HmiGuide
Instead of changing the Opc UA address on client side, you can solve this in the PLC with a variable of type: iStatusRef: REFERENCE TO INT:=iStatus1;
Variable definition of referenced variables.
{attribute 'global_init_slot' := '1000'} // defines initialization order. A lower value means an earlier initialization
VAR_GLOBAL
{attribute 'symbol' := 'none'}
iStatus1: INT:=100;
{attribute 'symbol' := 'none'}
iStatus2: INT:=200;
END_VAR
Variable definition of OpcUa variable
{attribute 'symbol' := 'readwrite'}
{attribute 'global_init_slot' := '2000'} // defines initialization order. A lower value means an earlier initialization
// https://docs.automation.boschrexroth.com/doc/3513354743/attribute-global-init-slot/6-06/en/
VAR_GLOBAL
// reference must be initialized
iStatusRef: REFERENCE TO INT:=iStatus1;
END_VAR
PLC example program which changes the reference
IF (iSelect=1) THEN
iStatusRef REF= iStatus1;
ELSE
iStatusRef REF= iStatus2;
END_IF