CDS 3.5 Network Variables

Hello,

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.

Problem:
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.
https://help.codesys.com/webapp/idx-scriptingengine;product=ScriptEngine;version=3.5.17.0

HowTo:
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 3.5.19.20\CODESYS\Common\CODESYS.exe —runscript::C:\Python\myscript_3.py

myscript_3.py 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")
project.save_as(desktop)
print("Project saved...")
project.save()

# 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 = "192.168.4.17" 

# 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")
deviceName.modules[0].import_io_mappings_from_csv(inputPath)
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
VAR
	bValue : BYTE;
END_VAR""")
myPOU.textual_implementation.replace("""
	bValue := bValue + 1; 
	MyOutputs := bValue;""")

# Call the Subroute
myMain = app.find("PLC_PRG")
myMain[0].textual_implementation.replace("""MyTest();""")

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

# Connect to PLC
devices[0].connect()

# 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:
    onlineapp.create_boot_application()
    if not onlineapp.application_state == ApplicationState.run:
        onlineapp.start()
	
system.delay(5000) #wait 5 sec
#Codesys: Disconnect the device(s) - Codesys 
devices[0].disconnect()

my_io_mapping.csv

//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