CDS 3.5 Network Variables


I’m converting my codesys 2.3 application to 3.5 (hotel system has been extended by websockets).
Ive got 1000 netvar lists in total (500 senders and 500 receivers). I have to stay with netvars, because there are 880 controllers in the project. I’ve got config CSV file with list of IP addresses and COB-IDs for each used netvar list which I use to change the destination address and COB-IDs of the lists.

In Codesys 2.3 there is a possibility to change netvars lists COB-ID and addresses using functions from libraries. But how to achieve this in CDS 3.5?

Also is there any way to create netvar lists using import file created in excel? It will be pain in the *** to click 500 senders and then create second controller, add another 500 lists and then add them again to first controller as a receiver.

Not sure about the library question for setting COB-ID, but the creation of the lists should be possible using the Codesys python scripting engine. You will have to dig in the documentation to see how to add that device type however.;product=ScriptEngine;version=

Step 1: Make a directory in c: drive, called C:\Python
Step 2: Copy all python files to this folder
Step 3 Run script with following syntax:
C:\Program Files\CODESYS\CODESYS\Common\CODESYS.exe —runscript::C:\Python\ example

import os
project = e_projects.create_new_project()
print("The comppiler version of the project is {0}".format(project.compiler_version))
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), "C:\\Python\\MyProject.project")
print("Project saved...")

# Add device
myDevice8202 = e_device_catalog.find_device_type("0750-8212", "LATEST")
devices = project.add_device(myDevice8212[0], 1)
print("Added PFC with latest firmware...")
devices[0].ip_address = "" 

# Add modules
moduleDI = e_device_catalog.find_device_type("0750-1415", "LATEST")
moduleDO = e_device_catalog.find_device_type("0750-1515", "LATEST")
modules = devices[0].add_module(moduleDI[0], 0, 1)
modules = devices[0].add_module(moduleDO[0], 1, 1)
print("The GUID is {0}".format(devices[0].device_guid))

# Assign IO variable names with CSV file
scriptDir = os.path.dirname(os.path.realpath(__file__))
deviceName = project.get_device("PFC200_2ETH_RS")
inputPath = os.path.join(scriptDir, "my_io_mapping.csv")
print("Imported I/O mapping")

# Create PLC_PRG
proj = projects.primary
#proj = project.active_application
plcs = project.find("Application", True)
app = plcs[0] 

# Create Subroutine
myPOU = app.create_pou("MyTest")
implementation = myPOU.textual_declaration.replace("""PROGRAM MyTest
	bValue : BYTE;
	bValue := bValue + 1; 
	MyOutputs := bValue;""")

# Call the Subroute
myMain = app.find("PLC_PRG")

# Uncomment to Save project
# project.save_as(desktop)

# Connect to PLC

# Get the online application
app = project.active_application 
onlineapp = online.create_online_application(app)

# Create a boot application (while online)

# set status of application to "run", if not in "run"
if onlineapp.is_logged_in:
    if not onlineapp.application_state ==
system.delay(5000) #wait 5 sec
#Codesys: Disconnect the device(s) - Codesys 


//CoDeSys Mapping Export V1.2
//Mapped variable;//Parameter name @ counter in device;//Unit;//Description;//IEC address;//Device name;
//Important: change only first, third or fourth column in Excel or add variable name before first ;
;K-BUS diagnostics;;K-BUS diagnostics;%IB0;Kbus
;K-BUS error;;K-BUS general error flag;%IX0.0;Kbus
;_IN;;Input Channels;%IW1;_8DI_24_VDC_3ms_2_wire
MyInput1;_IN@1;;Digital input;%IX1.0;_8DI_24_VDC_3ms_2_wire
MyInput2;_IN@2;;Digital input;%IX1.1;_8DI_24_VDC_3ms_2_wire
MyInput3;_IN@3;;Digital input;%IX1.2;_8DI_24_VDC_3ms_2_wire
MyInput4;_IN@4;;Digital input;%IX1.3;_8DI_24_VDC_3ms_2_wire
MyInput5;_IN@5;;Digital input;%IX1.4;_8DI_24_VDC_3ms_2_wire
MyInput6;_IN@6;;Digital input;%IX1.5;_8DI_24_VDC_3ms_2_wire
MyInput7;_IN@7;;Digital input;%IX1.6;_8DI_24_VDC_3ms_2_wire
MyInput8;_IN@8;;Digital input;%IX1.7;_8DI_24_VDC_3ms_2_wire
MyOutputs;_OUT;;Output Channels;%QW0;_8DO_24_VDC_0_5A_2_wire
;_OUT@1;;Digital output;%QX0.0;_8DO_24_VDC_0_5A_2_wire

just after posting I found typo in program :smiley:

1 Like