CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Run python script in Codesys
https://forum.codesys.com/viewtopic.php?f=18&t=8734
Page 1 of 1

Author:  eamonn [ Thu Mar 29, 2018 1:09 am ]
Post subject:  Run python script in Codesys

Hi,

I have a python script that sends a sms message to my phone when its run.
I want this code to run when a led in codesys turns on.

I can't figure out how to do this. I know that codesys can run python by using tools, scripting, execute script.

I just want the code to run automatically to alert me of an alarm.

Thanks for the help.

Author:  Edwin Schwellinger [ Fri Mar 30, 2018 7:06 pm ]
Post subject:  Re: Run python script in Codesys

Hi,
this sms you want to send on an alarm or IO triggered by the plc and send by the plc
not in the CODESYS developmentsystem?
Because this python scription here is all in the CODESYS developmentsystem not in the plc.

If you need this for the plc side,
this example here should show how this could work:
(But this works only if the plc side could execute python...)
viewtopic.php?f=23&t=6247&p=19932#p19941

BR
Edwin

Author:  eamonn [ Thu Apr 05, 2018 8:24 pm ]
Post subject:  Re: Run python script in Codesys

Thanks for the help.

I am using the PLC to run the python code. It can run the code on it's own.

I cant seem to get my code to run. I don't have the hardware to test yours but I used your example to make my code.
It seems to run the code but it does not do anything. I have tested my python code on its own and it does work.

Author:  Edwin Schwellinger [ Sat Apr 07, 2018 7:12 am ]
Post subject:  Re: Run python script in Codesys

Hi,
so on which plc do you execute this?

BR
Edwin

Author:  eamonn [ Wed Apr 11, 2018 10:20 pm ]
Post subject:  Re: Run python script in Codesys

I am running it on a raspberry pi 3 model B.
I am trying to have the single file run when a bool value = true.
I can't seem to get it to work through Codesys though.


Edit:

Never mind I got it to work.

Thanks for all the help though.

Author:  rKtiC [ Sun Apr 15, 2018 11:53 am ]
Post subject:  Re: Run python script in Codesys

Could you specify how you made it work? I am trying to run a Python Script on a Raspberry 3 B with the _ and it does not do anything. Running the script via the command line works fine.
I would appreciate any help.

Author:  Edwin Schwellinger [ Sun Apr 15, 2018 5:46 pm ]
Post subject:  Re: Run python script in Codesys

Hi,
did you check this?
viewtopic.php?f=23&t=6247&p=19932#p19941
BR
Edwin

Author:  eamonn [ Sat Apr 21, 2018 6:49 pm ]
Post subject:  Re: Run python script in Codesys

Here is the code that made it work.

This runs my python file sms_warning on the raspberry pi.

Make sure you do this

/etc/CODESYSControl.cfg:
[SysProcess]
Command=AllowAll

This can be done on the pi by using the command: sudo nano /etc/CODESYSControl.cfg

hope this helps.

Author:  Edwin Schwellinger [ Mon Apr 23, 2018 5:55 pm ]
Post subject:  Re: Run python script in Codesys

Hi,
one small remark:
I would recommend to move from /etc/CODESYSControl.cfg to /etc/CODESYSControl_User.cfg:

[SysProcess]
Command=AllowAll


This has the advanatage that on an runtime update ( for example from 3.5SP12 to 3.5SP13) this setting
will be retained.

BR
Edwin

Author:  Peter.skokanek [ Tue Jun 12, 2018 3:58 pm ]
Post subject:  Re: Run python script in Codesys

Hello,
I tried to use your examples to run my python script. But there is no /var/opt/codesys directory. I can find my PlcLogic/Application directory only directly in root directory. Where is a problem. Is it possible to set it somewhere in development system?

Author:  Edwin Schwellinger [ Tue Jun 12, 2018 4:59 pm ]
Post subject:  Re: Run python script in Codesys

Hi,
you need to update the Pi runtime Version to have it in
/var/opt/codesys...

BR
Edwin

Author:  jorgev [ Thu Aug 02, 2018 9:23 am ]
Post subject:  Re: Run python script in Codesys

Hi all,

I would like to use this feature in Codesys (script lang) to transfer variable values between the PLC and a python script.

First, I am trying to execute a simple python script using codesys with a RPI 3 B+ as PLC. I followed the example posted for the unicorn hat as reference. However, I do not have the hardware to test it so I developed a simple code "print()" to verify the code is running.
Below the steps I have followed:
1. Add my script as external file in my CODESYS program.

2. Manually copy to the RPI my python script to the directory /var/opt/codesys/. I have also included
[SysProcess]
Command=AllowAll

in both files
/etc/CODESYSControl.cfg:
/etc/CODESYSControl_User.cfg:


3. Download the Codesys Program to the RPI and run the program from CODESYS.

Although I do not receive any error nor compilation or execution, I can not observe my code running. Is there any step I am missing or I should skip?

Thanks in advance

Author:  agrobot [ Tue Apr 23, 2019 12:00 am ]
Post subject:  Re: Run python script in Codesys

I have the same problem, load the program well without errors, but do nothing, could someone solve this problem?

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/