CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Sep 20, 2018 5:31 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Mar 29, 2018 1:09 am 
Offline

Joined: Thu Feb 08, 2018 5:01 pm
Posts: 17
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.


Top
   
PostPosted: Fri Mar 30, 2018 7:06 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2837
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


Top
   
PostPosted: Thu Apr 05, 2018 8:24 pm 
Offline

Joined: Thu Feb 08, 2018 5:01 pm
Posts: 17
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.


Top
   
PostPosted: Sat Apr 07, 2018 7:12 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2837
Hi,
so on which plc do you execute this?

BR
Edwin


Top
   
PostPosted: Wed Apr 11, 2018 10:20 pm 
Offline

Joined: Thu Feb 08, 2018 5:01 pm
Posts: 17
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.


Top
   
PostPosted: Sun Apr 15, 2018 11:53 am 
Offline

Joined: Wed Oct 25, 2017 10:03 am
Posts: 5
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.


Top
   
PostPosted: Sun Apr 15, 2018 5:46 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2837
Hi,
did you check this?
viewtopic.php?f=23&t=6247&p=19932#p19941
BR
Edwin


Top
   
PostPosted: Sat Apr 21, 2018 6:49 pm 
Offline

Joined: Thu Feb 08, 2018 5:01 pm
Posts: 17
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.


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Mon Apr 23, 2018 5:55 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2837
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


Top
   
PostPosted: Tue Jun 12, 2018 3:58 pm 
Offline

Joined: Wed Jan 27, 2016 10:51 pm
Posts: 40
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?


Top
   
PostPosted: Tue Jun 12, 2018 4:59 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2837
Hi,
you need to update the Pi runtime Version to have it in
/var/opt/codesys...

BR
Edwin


Top
   
PostPosted: Thu Aug 02, 2018 9:23 am 
Offline

Joined: Wed Aug 01, 2018 9:33 am
Posts: 3
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


You do not have the required permissions to view the files attached to this post.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited