The following steps are necessary for exchanging network variables between the sender device and receiver device:
Requirements: An application is inserted in the device tree of the PLC that has been employed as the sender device.
-
Select the application and insert a Network Variable List (Sender) object. In the Add Network Variable List (Sender) dialog, configure the following settings: network type:
UDP(example:
"NVL_Sender"). -
Double-click the NVL object to open the respective editor and type the declarations of the network variables. Example:
VAR_GLOBALiglobvar:INT;bglobvar:BOOL;strglobvar:STRING;END_VAR -
Right-click the NVL object in the device tree to open the Properties. In the Properties dialog, open the Network Variables tab. This shows the following settings: Network type: UDP; List identifier: 1; Pack variables; Cyclic transmission: every 50 ms.
-
Note: You can also convert an existing GVL into a network variable list by configuring its network variable properties.
-
In the Properties dialog of the NVL_Sender, click the Link to File tab. Define a file name
<export>.gvland a location in the file system for the export file of the GVL. Select the Export before compile option. -
Click to compile the application.
The export file for the network variable list is now located in the defined folder.
Requirements: A sender device and a receiver device exist in the device tree. An application with a task configuration is inserted below the device. An NVL or a GVL is created below the sender device as network variable list to be sent.
-
Select the application of the receiver in the device tree and click .
The Add Network Variable List (Receiver) dialog opens.
-
In the dialog, select the previously created NVL of the sender device and specify a name (example:
"NVL_Receiver"). CODESYS automatically populates this receiver list with the variable declarations from the sender list.Note: As an alternative, you can select the Import from file option and load the export file that was generated previously from the sender list.
Requirements: A network variable list (sender) exists in the sender device, a network variable list (receiver) exists in the receiver device, and both lists have identical variable declarations.
-
Below the application in the sender device, create a program that increments a network variable.
Example:
iglobvar:=iglobvar+1; -
Configure the application task so that this program calls it.
-
Below the application in the receiver device, create a program that writes the value of this network variable to a local variable.
Example:
ilocalvar:=iglobvar; -
Configure the application task so that this program calls it.
-
Download both applications to the controllers and start them. (Set the application as active, login, download, and start)
-
In the online views of the editors of both programs, check whether the values of
iglobvarmatch in the receiver and the sender.
Requirements: A global variable list exists in a V2.3 project with network variables that you want to read into your V3 project. In the V3 project, in the device tree, below the PLC, there is an application with a program that uses the variables.
-
Open the Properties dialog of the GVL in the V2.3 project (sender).
-
Insert another PLC into the project as a dummy with an application and a task. Then create the V2.3 GVL below it as follows:
-
Insert a Network Variable List (Sender) object named "dummy23" below the dummy application.
-
Right-click dummy23 to open the Properties dialog. Click the Network Properties tab. Type the same network properties as the GVL in the V2.3 project.
-
Fill dummy23 with the same variable declarations as in the V2.3 GVL.
-
Define a location for an export file "dummy23.gvl" on the Link To File tab of the Properties for dummy23.
-
Set the application of the dummy controller to active and click (F11).
When the application is successfully compiled, CODESYS automatically creates the
dummy23.gvlexport file. -
Set the application of the physical PLC as active and right-click to open the Add Object dialog.
-
Select Network Variable List (Receiver) and specify a name (example: "NVL_from_23").
-
Select the Import from file option and select
dummy23.gvl, which was generated previously. -
Check NVL_from_23, which has just been created. You have to get the same variable declarations as those in the sender GVL in the V2.3 project.
For more information, see: Network Variable List (Sender) and Network Variable List (Receiver)