This document explains the Python compatibility requirements for scripts that run inside CODESYS.
CODESYS uses IronPython for its scripting environment. This means any script that runs directly inside CODESYS must maintain compatibility with this environment.
The CODESYS API implementation uses the following approach:
- PERSISTENT_SESSION.py: This script runs directly inside CODESYS and must maintain compatibility with the CODESYS IronPython environment.
- Other Components: All other components (HTTP server, Windows service, client) require Python 3.x.
When modifying the PERSISTENT_SESSION.py script, be aware of these syntax requirements:
-
Exception Handling:
- Use the syntax:
except Exception, e:
- Use the syntax:
-
Print Statements:
- Use the syntax:
print "Hello"
- Use the syntax:
-
String Handling:
- Be aware that IronPython handles strings differently than modern Python
-
Division Operator:
- Integer division:
5 / 2results in2
- Integer division:
When making changes to the PERSISTENT_SESSION.py script:
- Always maintain compatibility with the CODESYS IronPython environment
- Test the script in the CODESYS environment
- Avoid using modern Python features not supported by CODESYS
- Remember that IronPython might have some limitations compared to CPython
To test changes to PERSISTENT_SESSION.py:
- Make your modifications
- Run the script in CODESYS using the script execution feature
- Verify that your script executes correctly without syntax errors
- Test the functionality through the HTTP API
For more information on CODESYS scripting, refer to the CODESYS documentation on scripting and automation.