Home (version 5) discussion
CODESYS 4 Linux
home
(Thread)
Home (version 5) discussion
Last updated: 2019-08-05
Home (version 2) discussion
CODESYS 4 Linux
home
(Thread)
Home (version 2) discussion
Last updated: 2018-12-05
Home (version 8) discussion
CODESYS 4 Linux
home
(Thread)
Home (version 8) discussion
Last updated: 2019-12-18
Home (version 7) discussion
CODESYS 4 Linux
home
(Thread)
Home (version 7) discussion
Last updated: 2019-08-05
Home (version 9) discussion
CODESYS 4 Linux
home
(Thread)
Home (version 9) discussion
Last updated: 2020-03-07
Home (version 1) discussion
CODESYS 4 Linux
home
(Thread)
Home (version 1) discussion
Last updated: 2018-10-12
Manual Installation (version 3) discussion
CODESYS 4 Linux
home
(Thread)
Manual Installation (version 3) discussion
Last updated: 2018-10-13
Manual Installation (version 1) discussion
CODESYS 4 Linux
home
(Thread)
Manual Installation (version 1) discussion
Last updated: 2018-10-13
codesys-4-linux: Artifact 5dd379670e5263002d4b1a6e
CODESYS 4 Linux
tickets
(Bin)
Last updated: 2019-11-19
codesys-4-linux: Artifact 5dd379670e5263002d4b1a6f
CODESYS 4 Linux
tickets
(Bin)
Last updated: 2019-11-19
codesys-4-linux: Artifact 5dd379670e5263002d4b1a70
CODESYS 4 Linux
tickets
(Bin)
Last updated: 2019-11-19
Ticket #1: Open and close a project
Scripting
snippets
(Ticket)
proj = projects.open(filepath) ... Proj.close() ~~~Open and close a project Scripting 0 snippets Ticket tickets Open and close a project 2020-02-08 02:18:39.203000 Unlicense False 0 ingo Ticket #1: Open and close a project 0 False /tol/scripting/snippets/1/ None 2020-02-07 22:24:57.145000 None 1 scripting ~~~python proj = projects.open(filepath) ... Proj.close() False False 1
Last updated: 2020-02-08
Ticket #2: Iterate over the device tree
Scripting
snippets
(Ticket)
def printtree_rec(treeobj, depth=0): name = treeobj.get_name(False) if treeobj.is_device: deviceid = treeobj.get_device_identification() print("{0} - {1} {2}".format("--"*depth, name, deviceid)) for child in treeobj.get_children(False): printtree_rec(child, depth+1) def printTree(proj): for obj in proj.get_children(): printtree_rec(obj) ~~~Iterate over the device tree Scripting 0 snippets Ticket tickets Iterate over the device tree 2020-02-08 02:18:39.197000 Declined False 0 ingo Ticket #2: Iterate over the device tree 0 False /tol/scripting/snippets/2/ None 2020-02-07 22:30:59.809000 None 2 scripting ~~~python def printtree_rec(treeobj, depth=0): name = treeobj.get_name(False) if treeobj.is_device: deviceid = treeobj.get_device_identification() print("{0} - {1} {2}".format("--"*depth, name, deviceid)) for child in treeobj.get_children(False): printtree_rec(child, depth+1) def printTree(proj): for obj in proj.get_children(): printtree_rec(obj) False False 3
Last updated: 2020-02-08
Ticket #3: Create an FB
Scripting
snippets
(Ticket)
Only Structured Text can be edited directly! For the graphical languages you have to import the POU from PLCopenXML or the codesys native format. See IScriptTextualObjectMarker, IScriptObjectWithTextualDeclaration, IScriptObjectWithTextualImplementation and IScriptTextDocument for the textual language and the methods importxml() and importnative() from IScriptObject2 and IScriptProject2 for the import. Find the Scripting object, for example withfind(), and use the method remove() to delete an object. proj = projects.primary found = proj.find("Application", True) app = found[0] # Create FB mypou = app.create_pou("MyPou") # Change declaration of the FB implementation = mypou.textual_declaration.replace("""FUNCTION_BLOCK MyPou VAR_INPUT iValue : INT; END_VAR VAR_OUTPUT END_VAR VAR END_VAR""") # Change implementation of the FB mypou.textual_implementation.replace("""iValue := iValue + 1;""") # Add method to FB dosomething = mypou.create_method("DoSomething", "INT") # Change declaration of the method dosomething.textual_declaration.replace("""METHOD DoSomething : INT VAR_INPUT iVal1 : INT; iVal2 : INT; END_VAR""") # Change implementation of the method dosomething.textual_implementation.replace("""DoSomething := iVal1 + iVal2;""") # Find the pou and delete it found = app.find("MyPou") if found and len(found) == 1: found[0].remove() else: print("POU 'MyPou' was not found") Create an FB Scripting 0 snippets Ticket tickets Create an FB 2020-02-08 02:18:39.199000 Unlicense False 0 ingo Ticket #3: Create an FB 0 False /tol/scripting/snippets/3/ None 2020-02-07 22:35:19.851000 None 3 scripting Only Structured Text can be edited directly! For the graphical languages you have to import the POU from PLCopenXML or the codesys native format. See IScriptTextualObjectMarker, IScriptObjectWithTextualDeclaration, IScriptObjectWithTextualImplementation and IScriptTextDocument for the textual language and the methods importxml() and importnative() from IScriptObject2 and IScriptProject2 for the import. Find the Scripting object, for example withfind(), and use the method remove() to delete an object. proj = projects.primary found = proj.find("Application", True) app = found[0] # Create FB mypou = app.create_pou("MyPou") # Change declaration of the FB implementation = mypou.textual_declaration.replace("""FUNCTION_BLOCK MyPou VAR_INPUT iValue : INT; END_VAR VAR_OUTPUT END_VAR VAR END_VAR""") # Change implementation of the FB mypou.textual_implementation.replace("""iValue := iValue + 1;""") # Add method to FB dosomething = mypou.create_method("DoSomething", "INT") # Change declaration of the method dosomething.textual_declaration.replace("""METHOD DoSomething : INT VAR_INPUT iVal1 : INT; iVal2 : INT; END_VAR""") # Change implementation of the method dosomething.textual_implementation.replace("""DoSomething := iVal1 + iVal2;""") # Find the pou and delete it found = app.find("MyPou") if found and len(found) == 1: found[0].remove() else: print("POU 'MyPou' was not found") False False 3
Last updated: 2020-02-08
Ticket #5: Export as PLCOpen XML
Scripting
snippets
(Ticket)
class ER(ExportReporter): def error(self, object, message): system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) def warning(self, object, message): system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message)) def nonexportable(self, object): system.write_message(Severity.Information, "Object not exportable: %s" % object) @property def aborting(self): return False; reporter = ER() proj = projects.open(filename) proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True) proj.close() Export as PLCOpen XML Scripting 0 snippets Ticket tickets Export as PLCOpen XML 2020-02-08 02:18:39.201000 Unlicense False 0 ingo Ticket #5: Export as PLCOpen XML 0 False /tol/scripting/snippets/5/ None 2020-02-07 22:40:17.745000 None 5 scripting class ER(ExportReporter): def error(self, object, message): system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) def warning(self, object, message): system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message)) def nonexportable(self, object): system.write_message(Severity.Information, "Object not exportable: %s" % object) @property def aborting(self): return False; reporter = ER() proj = projects.open(filename) proj.export_xml(reporter, proj.get_children(False), tempname, recursive = True) proj.close() False False 2
Last updated: 2020-02-08
Ticket #6: Modify Properties / Compiler defines
Scripting
snippets
(Ticket)
# Find Object VICTIM in projecttree victim = projects.primary.find("VICTIM", True)[0] props = victim.build_properties props.external = not props.external props.enable_system_call = not props.enable_system_call props.link_always = not props.link_always props.exclude_from_build = not props.exclude_from_build if ";FOOBAR" in props.compiler_defines: props.compiler_defines = props.compiler_defines.replace(";FOOBAR","") else: props.compiler_defines = props.compiler_defines + ";FOOBAR" Modify Properties / Compiler defines Scripting 0 snippets Ticket tickets Modify Properties / Compiler defines 2020-02-08 02:18:39.206000 Unlicense False 0 ingo Ticket #6: Modify Properties / Compiler defines 0 False /tol/scripting/snippets/6/ None 2020-02-08 01:44:18.785000 None 6 scripting # Find Object VICTIM in projecttree victim = projects.primary.find("VICTIM", True)[0] props = victim.build_properties props.external = not props.external props.enable_system_call = not props.enable_system_call props.link_always = not props.link_always props.exclude_from_build = not props.exclude_from_build if ";FOOBAR" in props.compiler_defines: props.compiler_defines = props.compiler_defines.replace(";FOOBAR","") else: props.compiler_defines = props.compiler_defines + ";FOOBAR" False False 2
Last updated: 2020-02-08
Ticket #7: SVN checkout
Scripting
snippets
(Ticket)
def set_username(req): req.username = username req.password = password req.save = True # Optional svn.auth_username_password += set_username svn.checkout(url, dir, filename) proj = projects.primary proj.save_as(filename) SVN checkout Scripting 0 snippets Ticket tickets SVN checkout 2020-02-08 02:18:39.205000 Unlicense False 0 ingo Ticket #7: SVN checkout 0 False /tol/scripting/snippets/7/ None 2020-02-08 01:46:04.388000 None 7 scripting def set_username(req): req.username = username req.password = password req.save = True # Optional svn.auth_username_password += set_username svn.checkout(url, dir, filename) proj = projects.primary proj.save_as(filename) False False 2
Last updated: 2020-02-08
Ticket #8: SVN commit
Scripting
snippets
(Ticket)
def set_username(req): req.username = username req.password = password req.save = True # Optional svn.auth_username_password += set_username svn.commit(message) SVN commit Scripting 0 snippets Ticket tickets SVN commit 2020-02-08 02:18:39.200000 Unlicense False 0 ingo Ticket #8: SVN commit 0 False /tol/scripting/snippets/8/ None 2020-02-08 01:47:04.102000 None 8 scripting def set_username(req): req.username = username req.password = password req.save = True # Optional svn.auth_username_password += set_username svn.commit(message) False False 2
Last updated: 2020-02-08
Ticket #9: SVN update
Scripting
snippets
(Ticket)
def set_username(req): req.username = username req.password = password req.save = True # Optional svn.auth_username_password += set_username svn.update() SVN update Scripting 0 snippets Ticket tickets SVN update 2020-02-08 02:18:39.202000 Unlicense False 0 ingo Ticket #9: SVN update 0 False /tol/scripting/snippets/9/ None 2020-02-08 01:48:24.555000 None 9 scripting def set_username(req): req.username = username req.password = password req.save = True # Optional svn.auth_username_password += set_username svn.update() False False 2
Last updated: 2020-02-08
Ticket #10: Add Device with Task Configuration
Scripting
snippets
(Ticket)
# add device proj.add('PLC', devId) apps = proj.find('Application', True) if len(apps) > 0: tc = apps[0].create_task_configuration() # add task task = tc.create_task('Task') task.pous.add('PLC_PRG') Add Device with Task Configuration Scripting 0 snippets Ticket tickets Add Device with Task Configuration 2020-02-08 02:18:39.205000 Unlicense False 0 ingo Ticket #10: Add Device with Task Configuration 0 False /tol/scripting/snippets/10/ None 2020-02-08 01:49:48.651000 None 10 scripting # add device proj.add('PLC', devId) apps = proj.find('Application', True) if len(apps) > 0: tc = apps[0].create_task_configuration() # add task task = tc.create_task('Task') task.pous.add('PLC_PRG') False False 1
Last updated: 2020-02-08
Ticket #11: Check compile errors of libraries
Scripting
snippets
(Ticket)
CompileCategory = Guid("{97F48D64-A2A3-4856-B640-75C046E37EA9}") # Clear messages from Build category system.clear_messages(CompileCategory) projects.primary.check_all_pool_objects() # Get message objects which contain all the data severities = { Severity.FatalError : "Fatal error", Severity.Error : "Error", Severity.Warning : "Warning", Severity.Information : "Information", Severity.Text : "Text" } msgs = system.get_message_objects(CompileCategory, Severity.FatalError|Severity.Error) for msg in msgs: sev = severities[msg.severity] print("{} {}{}: {}".format(sev, msg.prefix, msg.number, msg.text) Check compile errors of libraries Scripting 0 snippets Ticket tickets Check compile errors of libraries 2020-02-08 02:18:39.204000 Unlicense False 0 ingo Ticket #11: Check compile errors of libraries 0 False /tol/scripting/snippets/11/ None 2020-02-08 01:50:49.600000 None 11 scripting CompileCategory = Guid("{97F48D64-A2A3-4856-B640-75C046E37EA9}") # Clear messages from Build category system.clear_messages(CompileCategory) projects.primary.check_all_pool_objects() # Get message objects which contain all the data severities = { Severity.FatalError : "Fatal error", Severity.Error : "Error", Severity.Warning : "Warning", Severity.Information : "Information", Severity.Text : "Text" } msgs = system.get_message_objects(CompileCategory, Severity.FatalError|Severity.Error) for msg in msgs: sev = severities[msg.severity] print("{} {}{}: {}".format(sev, msg.prefix, msg.number, msg.text) False False 2
Last updated: 2020-02-08
Ticket #13: Add device to project
Scripting
snippets
(Ticket)
devId = None devices = device_repository.get_all_devices("CODESYS Control Win V3") for device in devices: devId = device.device_id proj = projects.primary # delete existing testdev device existing = proj.find('testdev') if len(existing) > 0: existing[0].remove() # add device proj.add('testdev', devId) apps = proj.find('Application', True) if len(apps) > 0: app = apps[0] tc = app.create_task_configuration() Add device to project Scripting 0 snippets Ticket tickets Add device to project 2020-02-08 16:01:54.247000 Unlicense False 0 ingo Ticket #13: Add device to project 0 False /tol/scripting/snippets/13/ None 2020-02-08 16:01:54.134000 None 13 scripting devId = None devices = device_repository.get_all_devices("CODESYS Control Win V3") for device in devices: devId = device.device_id proj = projects.primary # delete existing testdev device existing = proj.find('testdev') if len(existing) > 0: existing[0].remove() # add device proj.add('testdev', devId) apps = proj.find('Application', True) if len(apps) > 0: app = apps[0] tc = app.create_task_configuration() False False 1
Last updated: 2020-02-08
Ticket #14: Login and monitor variable
Scripting
snippets
(Ticket)
# login onlineapp = online.create_online_application(app) try: onlineapp.login(OnlineChangeOption.Try, True) except: print("Error: compile error") return False # run program onlineapp.start() # wait until project finishes for timeout in range(10): system.delay(1000) xready = onlineapp.read_value("PRG_RUNTEST.xReady") if str(xready) == "TRUE": break # check for error xerror = onlineapp.read_value("PRG_RUNTEST.xError") ~~~Login and monitor variable Scripting 0 snippets Ticket tickets Login and monitor variable 2020-02-08 16:04:51.316000 Unlicense False 0 ingo Ticket #14: Login and monitor variable 0 False /tol/scripting/snippets/14/ None 2020-02-08 16:04:51.212000 None 14 scripting ~~~python # login onlineapp = online.create_online_application(app) try: onlineapp.login(OnlineChangeOption.Try, True) except: print("Error: compile error") return False # run program onlineapp.start() # wait until project finishes for timeout in range(10): system.delay(1000) xready = onlineapp.read_value("PRG_RUNTEST.xReady") if str(xready) == "TRUE": break # check for error xerror = onlineapp.read_value("PRG_RUNTEST.xError") False False 1
Last updated: 2020-02-08