62 lines
2.3 KiB
Markdown
62 lines
2.3 KiB
Markdown
# Configure Python Scripting in CODESYS IDE
|
|
|
|
This guide helps you enable and validate Python scripting in the CODESYS Development System.
|
|
|
|
## 1) Prerequisites
|
|
|
|
- CODESYS Development System installed
|
|
- A local Python installation (recommended: 64-bit)
|
|
- Permissions to install CODESYS packages/add-ons
|
|
|
|
> Note: Python version compatibility can vary by CODESYS release. Check your CODESYS release notes if the scripting package requests a specific Python version.
|
|
|
|
## 2) Enable scripting support in CODESYS
|
|
|
|
1. Start CODESYS IDE.
|
|
2. Open the CODESYS package/add-on manager.
|
|
3. Verify that scripting support is installed (usually shown as `Scripting`, `Script Engine`, or similar CODESYS scripting component).
|
|
4. If missing, install the scripting package from CODESYS Store/Installer and restart CODESYS.
|
|
|
|
## 3) Verify Python environment in IDE
|
|
|
|
1. Open the scripting window/console in CODESYS (menu name depends on version/profile).
|
|
2. Confirm that the script console starts without errors.
|
|
3. If CODESYS asks for a Python path/interpreter, set your local Python executable.
|
|
4. Save settings and restart IDE once.
|
|
|
|
## 4) Run a first test script
|
|
|
|
Use this minimal script in the CODESYS script console/editor:
|
|
|
|
```python
|
|
import sys
|
|
print("Python OK")
|
|
print(sys.version)
|
|
```
|
|
|
|
Expected result: no import/runtime errors and printed Python version output.
|
|
|
|
## 5) Connect script to an existing project
|
|
|
|
1. Open your CODESYS project.
|
|
2. From scripting console/editor, access the active project object (CODESYS scripting API).
|
|
3. Start with read-only actions first:
|
|
- list devices
|
|
- list POUs
|
|
- print project metadata
|
|
4. Then move to controlled write actions (for example, auto-creating folders/objects).
|
|
|
|
## 6) Common setup issues
|
|
|
|
- **Scripting menu missing**: scripting package not installed or wrong CODESYS profile.
|
|
- **Interpreter errors**: incompatible Python version or wrong executable path.
|
|
- **Permission errors**: run IDE with appropriate permissions for package/plugin install.
|
|
- **API object errors**: script written for another CODESYS version/API revision.
|
|
|
|
## 7) Recommended workflow
|
|
|
|
- Keep scripts in version control near your CODESYS project.
|
|
- Start with non-destructive scripts (reporting/checks) before auto-edit scripts.
|
|
- Add log output for every script action.
|
|
- Test scripts on a copy of the project before applying to production projects.
|