CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Thu Oct 17, 2019 11:47 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri May 22, 2015 9:30 am 
Offline

Joined: Tue May 19, 2015 6:27 am
Posts: 14
Hi,
I browsed through the forum but I couldn't find a sollution for this.
I would like to run a Phyton script (or bash script) based on a condition within PLC programm (ie. If GPIO pin 27 is high, I want to run a Phyton script).

I found some suggestions using Sysprocess.library and SysTypes.library, and use "Sys Process Execute Command", but I can not find these two libraries at all (viewtopic.php?f=21&t=5714)

Hope someone can help.
Best regards,
Gregor


Top
   
PostPosted: Sat May 23, 2015 5:51 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3492
Hi,
1. for adding syslibs you need to switch to professional (this is obsolete for 3.5SP7 ).
2. then you need to add sysprocess library and Systypes Interfaces2 library (just type part of the name into the search field see screenshot)
3. check my example (add the command to /etc/CODESYSControl.cfg)
BR
Edwin


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


Top
   
PostPosted: Sat May 23, 2015 7:53 am 
Offline

Joined: Tue May 19, 2015 6:27 am
Posts: 14
Hi Edwin,
thank you for your answer.

I managed to install libraries: "SysProcess 3.5.5.0" and "SysTypes2 Interfaces".

I am a bit confused, what and how I should write into CODESYScontrol.cfg

I have a working script (only an example) which I can run with this command:
Code:
sudo python \home\GPIO27_ON.py


What should I write into .cfg file for this command to be used from within PLC program?

I prepared this in .cfg:
Code:
[SysProcess]
Command.0=shutdown
Command.1=GPIO27_ON.py


I moved file to \usr\bin\ folder. I made it executable.

In Programm I define xGumb as virtual button.
This is my code:
Code:
xRisingTrigger(CLK:=xGumb);
IF xRisingTrigger.Q  THEN
   _('GPIO27_ON.py',ADR(Result));
END_IF


I get Result value 25 when I trigger xGumb. Script is not executed.

Gregor


Top
   
PostPosted: Sat May 23, 2015 8:18 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3492
Hi,
could not really se the problem at the moment
could you please upload the CODESYSControl.cfg .. (check if there is a dublicate entry of the SysProcess section)

Error 25 means:
define ERR_NO_ACCESS_RIGHTS 0x0019 /* No access rights for this operation */


BR
Edwin


Top
   
PostPosted: Sat May 23, 2015 8:38 am 
Offline

Joined: Tue May 19, 2015 6:27 am
Posts: 14
Hi Edwin,
attached is CODESYSControl.cfg (I had to rename it to .txt because forum doesn't allow .cfg files to be uploaded).
There is no duplicate.

Could this be a problem with ROOT privilege to run python scripts?

BR,
Gregor


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


Top
   
PostPosted: Sat May 23, 2015 8:44 am 
Offline

Joined: Tue May 19, 2015 6:27 am
Posts: 14
Running script...
Attachment:
trying to run script.jpg

BR,
Gregor


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


Top
   
PostPosted: Sat May 23, 2015 8:48 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3492
Hi,

Change the config file to:

[SysProcess]
Command.0=shutdown
Command.1=python

(after doing this a restart of the runtime is needed)

and then call in CODESYS
    Sys..Process...ExecuteC..('python GPIO27_ON.py',ADR(Result));

BR
Edwin


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


Top
   
PostPosted: Sat May 23, 2015 2:44 pm 
Offline

Joined: Tue May 19, 2015 6:27 am
Posts: 14
Hi Edwin,
I finnaly got it working!
I had to give the full path to run scripts!

Code:
IF xRisingTrigger.Q  THEN 
   _('python /usr/bin/GPIO27_ON.py',ADR(Result));
END_IF


Thank you!
BR, Gregor


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 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