Adding Data Server and Data Sources in the Project

For the exchange of data with application(s) on another device via a data server you must insert a Data Server object and at least one Data Source object in the device tree under your application.

Requirement: The device tree contains more than 1 device, each with an error-free compilable application.

  1. In the device tree, select the application that is also to use the variables of an application under a different device. Insert a Data Server object.

  2. Insert a Data Source object under the Data Server object. CODESYS offers the applications that are possible as data sources. You can give the data source a specific name.

Example

The device tree currently contains 3 device entries: Dev1, Dev2, MyPlc.

The application App1 below MyPlc wishes to use the data from device Dev1 and from device Dev2.

1. Compile App1 with the command Create ‣ Compile. Under App1, insert a DataServer object and below that a Data source object.

2. Select the type CODESYS PLC for the data source. CODESYS then offers: Dev1/App_Dev1 and Dev2/App_Dev2.

3. First select the application from Dev1 and name it “DataSource_Dev1”. By clicking on Open this data source is inserted in the Device tree.

4. Insert the application from Device2 as the second data source under App1. Name this “DataSource_Dev2”.

5. Program PLC_PRG below App_Dev1 as follows:

PROGRAM PLC_PRG
VAR
dev1_iVar : INT;
dev1_dwVar  :DWORD;
dev1_fb1inst : fb1;
showvar : INT;
END_VAR
showvar :=dev1_fb1inst.fb1out;

6. Insert a function block FB1 below App_Dev1 and program it as follows:

FUNCTION_BLOCK FB1
VAR_INPUT
fb1in : INT;
END_VAR
VAR_OUTPUT
fb1out : INT;
END_VAR
VAR
fb1var : INT;
END_VAR
fb1out := fb1in+fb1var;

7. Program a POU PLC_PRG below App_Dev2 as follows:

VAR
dev2_iVar : INT;
dev2_dwVar : DWORD;
res1 : INT;
res2 : DWORD;
END_VAR
res1 := dev2_iVar+1;
res2 := dev2_dwVar+1;

7. Set App_Dev1 as the active application and load it to the controller: Set the network path in the communication settings in the device editor to Dev1, commands Online ‣ LoginOnline ‣ Downoad. Then log out again: Online ‣ Logout.

8. Set App_Dev2 as the active application and load it to the controller: Set the network path in the Communication Settings in the device editor to Dev2, Online ‣ LoginOnline ‣ Load. Then log out again: Online ‣ Logout.

9. You can now configure both sources.

Continuation of the example: Configuring the Data Sources

See also