Due to time constraints, the documentation for the script commands was currently delivered in a somewhat temporary form. In the CoDeSys installation directory, in the subdirectory CoDeSys\Online Help
is a file called ScriptEngine.chm
. In this file, all CoDeSys-specific python interfaces for the script engine are documented. This file is generated directly from the C# source, and thus its content is complete, but its form is not integrated into the online help, and it's structure is more related to our internal implementation than to the simpler structure visible for script authors.
The namespace _3S.CoDeSys.ScriptEngine.BasicFunctionality contains the objects we provide for the scripts (unfold the lowest entry in the content tree). The other namespaces only contain some enum values which are imported from other areas of CoDeSys.
The following entry points are provided for the scripts:
- system: Basic functionality for the intetration into CoDeSys. This object provides all the functions which are documented under "ISystem Interface", e. G. exitting CoDeSys, access to the message window, or query via ui_present whether CoDeSys is running in the --noUI mode.
- projects: Basic functionality for the project administration. This object provides all the functions documented under "IScriptProjects Interface", e. G. loading of projects and project archives. Additionally, it is the entry point into the specific projects.
- online: Basic functionality for the online access on the PLC. With the method "create_online_application" one can fetch the online object for a specific application object. Those are documented under "IScriptOnlineApplication", and one can use them to log into a PLC, start an application, and read values of variables.
The Functions of projects are documented at "IScriptProject Interface" and "IScriptProjectDeviceExtension Interface". Projects are the root of the project trees which contains the devices and POUs.Objekts:
The objects are documented at "IScriptObject Interface". Additionally, all projects provide two marker properties: "is_libman" and "is_device". For library managers, the first one returns "True", a sign that the objects provide all the "IScriptLibManObject" commands, too. In analogy to that, device objects return True from is_device, to show that they support the methods of "IScriptDeviceObject".
An example of how to use those marker properties is in the Examples and Receipes
thread in receipe 2: The printtree method uses is_device to check whether the object is a device before accessing the device id.
I hope this faciliates your entry into the world of scripting.
I think, the best strategy is to read the examples here in the forum, cross-compare them with the documentation, and in case of any doubts, ask here in the forum.Footnotes:
 If you're interested in the details: CoDeSys is a modular product built from about 200 plugins, which can be extended and exchanged by our OEM customers in line with our "Automation Platform". For this reason, our scripting implementation is also modularized internally. A main plugin called "ScriptEngine" provides the infrastructure (Scripting interpreter, commands, command line options). Five more plugins, so-called ScriptDrivers, provide the actual commands for the scripts, separated into the areas "System", "Project", "Online", "LibraryManager" and "Device". Such script drivers can provide objects and types (classes, interfaces, enums), and even extend objects of other script drivers with their own functionality. This modular architecture ensures that our ScriptDriver does not exploit any internal shortcuts, thus our OEMs can integrate their plugins into the ScriptEngine seamlessly.
 Calling this functionality "commands" is a little bit simplified, the interface for the scripts is object oriented (as python is an object oriented language). This might seem a little bit komplex compared to the old V2 Batch Mode, but is considerably more powerful and flexible.
Check out the CODESYS store: http://store.codesys.com/CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions