Hey Guys,
I am very new to Codesys i find it very useful for PLC applications.
I have designed the GUI for an appplication in Codesys how do I relate the GUI to a python script.
For example: I have a button or a bunch of buttons designed through codesys. These buttons when clicked should call python functions. This application will be run on a Raspberry pie as the PLC.
I really could not find any material online to do such a thing. COuld someone help me and point me in the right direction maybe show me an example or post a link maybe for reference.
Thank you in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I do not know if there is a specific library for this, but you can run linux command line from CodeSys, meaning you can call your python script too.
First, you need to edit a codesys file in the RPI to allow codesys to run command lines :
sudo nano /etc/CODESYSControl.cfg
in the file "CODESYSControl.cfg", add this :
[SysProcess]command=AllowAll
Then, in CodeSys, you need the have the SysProcess library in your project. You can then call your python script as follows :
Note that the CodeSys cycle will stop until the command has return. If your script takes time, you can either add '&' at the end of your command so the function returns immediately and the script runs in background (but you won't have your return string), or put your call on a separate core (codesys can use 4 core on the RPI, meaning 4 simultaneous code running)
Last edit: snguyen 2022-02-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey Guys,
I am very new to Codesys i find it very useful for PLC applications.
I have designed the GUI for an appplication in Codesys how do I relate the GUI to a python script.
For example: I have a button or a bunch of buttons designed through codesys. These buttons when clicked should call python functions. This application will be run on a Raspberry pie as the PLC.
I really could not find any material online to do such a thing. COuld someone help me and point me in the right direction maybe show me an example or post a link maybe for reference.
Thank you in advance.
Could someone share their knowledge in this topic please, Thank you
Hi, I do not know if there is a specific library for this, but you can run linux command line from CodeSys, meaning you can call your python script too.
First, you need to edit a codesys file in the RPI to allow codesys to run command lines :
sudo nano /etc/CODESYSControl.cfg
in the file "CODESYSControl.cfg", add this :
Then, in CodeSys, you need the have the SysProcess library in your project. You can then call your python script as follows :
Note that the CodeSys cycle will stop until the command has return. If your script takes time, you can either add '&' at the end of your command so the function returns immediately and the script runs in background (but you won't have your return string), or put your call on a separate core (codesys can use 4 core on the RPI, meaning 4 simultaneous code running)
Last edit: snguyen 2022-02-09