Skip to main content

Configuring a Network Variable Exchange

The following steps are necessary for exchanging network variables between the sender device and receiver device:

1. Creating a network variable list in the sender device and generating an export file

Requirements: An application is inserted in the device tree of the PLC that has been employed as the sender device.

  1. 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: icon_nvl_sender.png "NVL_Sender").

  2. Double-click the NVL object to open the respective editor and type the declarations of the network variables. Example:

    VAR_GLOBAL

    iglobvar:INT;

    bglobvar:BOOL;

    strglobvar:STRING;

    END_VAR

  3. 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.

  4. Note: You can also convert an existing GVL into a network variable list by configuring its network variable properties.

  5. In the Properties dialog of the NVL_Sender, click the Link to File tab. Define a file name <export>.gvl and a location in the file system for the export file of the GVL. Select the Export before compile option.

  6. Click Build → Build to compile the application.

The export file for the network variable list is now located in the defined folder.

2. Creating an associated network variable list in the receiver device

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.

  1. Select the application of the receiver in the device tree and click Add Object → Network Variable List (Receiver).

    The Add Network Variable List (Receiver) dialog opens.

  2. In the dialog, select the previously created NVL of the sender device and specify a name (example: icon_nvl_receiver.png "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.

3. Testing the network variable exchange

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.

  1. Below the application in the sender device, create a program that increments a network variable.

    Example: iglobvar:=iglobvar+1;

  2. Configure the application task so that this program calls it.

  3. 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;

  4. Configure the application task so that this program calls it.

  5. Download both applications to the controllers and start them. (Set the application as active, login, download, and start)

  6. In the online views of the editors of both programs, check whether the values of iglobvar match in the receiver and the sender.

Configuration of network variable communication between V2.3 and V3 PLCs

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.

  1. Open the Properties dialog of the GVL in the V2.3 project (sender).

  2. 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:

  3. Insert a Network Variable List (Sender) object named "dummy23" below the dummy application.

  4. 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.

  5. Fill dummy23 with the same variable declarations as in the V2.3 GVL.

  6. Define a location for an export file "dummy23.gvl" on the Link To File tab of the Properties for dummy23.

  7. Set the application of the dummy controller to active and click Build → Generate Code (F11).

    When the application is successfully compiled, CODESYS automatically creates the dummy23.gvl export file.

  8. Set the application of the physical PLC as active and right-click to open the Add Object dialog.

  9. Select Network Variable List (Receiver) and specify a name (example: "NVL_from_23").

  10. Select the Import from file option and select dummy23.gvl, which was generated previously.

  11. 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)