CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Nov 23, 2017 8:15 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 17 posts ]  Go to page 1 2 Next
Author Message
PostPosted: Thu Jul 19, 2012 11:37 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Hi all,

Could someone tell me is there any way to run a script that Codesys will interprete, not manually from Tools->Scripting, but from e.g. command line?

I did manage to start Codesys application, login and run it through the command line by executing it with parameter:

C:\Program Files\3S CoDeSys V3.4 SP3\CoDeSys\Common>start /wait CoDeSys.exe --profile="CoDeSys V3.4 SP3" --runscript="C:\runscript.py"


Now runscript.py is looking like this:
-------------------------------------
from __future__ import print_function

import os
scriptdir = os.path.dirname("C:\TestStand\Systemtest\Libs\CoDeSys\Open_SysTS_FBC-EC.py") # Directory of our script.
datadir = os.path.join(scriptdir, "Projekt") # Enter the subdirectory.
projectpath = os.path.join(datadir, "test_no2.project") # And add the project name.

proj = projects.open(projectpath)

app = proj.active_application

onlineapp = online.create_online_application(app)

onlineapp.login(OnlineChangeOption.Try, True)

if not onlineapp.application_state == ApplicationState.run:
onlineapp.start()

system.delay(1000)
-----------------------------------------
So the application is starting and working, but what if I want to e.g. stop the program running? I could manually execute another script from Codesys, but I want to do that by calling some batch file for example, that will stop Codesys.
Please help me.


Top
   
PostPosted: Thu Jul 19, 2012 12:54 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, Daniel_REC,
[/quote]
daniel_REC wrote:
Could someone tell me is there any way to run a script that Codesys will interprete, not manually from Tools->Scripting, but from e.g. command line?

I did manage to start Codesys application, login and run it through the command line by executing it with parameter:

C:\Program Files\3S CoDeSys V3.4 SP3\CoDeSys\Common>start /wait CoDeSys.exe --profile="CoDeSys V3.4 SP3" --runscript="C:\runscript.py"


So you already know how to start a script via command line. There are additional options like "--noUI" which are described in the Online Help, see the chapter about the "Script Language" in "Concepts and Basic Components".

Also note that you don't need the "start /wait" when starting CoDeSys from within a batch file.

daniel_REC wrote:
Now runscript.py is looking like this:
-------------------------------------
Code:
from __future__ import print_function

import os
scriptdir = os.path.dirname("C:\TestStand\Systemtest\Libs\CoDeSys\Open_SysTS_FBC-EC.py") # Directory of our script.
datadir = os.path.join(scriptdir, "Projekt") # Enter the subdirectory.
projectpath = os.path.join(datadir, "test_no2.project") # And add the project name.

proj = projects.open(projectpath)

app = proj.active_application

onlineapp = online.create_online_application(app)

onlineapp.login(OnlineChangeOption.Try, True)

if not onlineapp.application_state == ApplicationState.run:
    onlineapp.start()

system.delay(1000)

-----------------------------------------
So the application is starting and working, but what if I want to e.g. stop the program running? I could manually execute another script from Codesys, but I want to do that by calling some batch file for example, that will stop Codesys.
Please help me.


The application on the PLC will continue running when CoDeSys (the IDE) exists after executing the script.

So you just create a different python script which just stops the application instead of starting it.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Jul 19, 2012 1:17 pm 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Thank You M.Schaber for quick answer, but You did write exactly the same solution that is in my post, and I did ask about HOW to start the next python script while Codesys is allready running? I can't do that with:
C:\Program Files\3S CoDeSys V3.4 SP3\CoDeSys\Common>start /wait CoDeSys.exe --profile="CoDeSys V3.4 SP3" --runscript="C:\run_second_script.py"
because it will open another Codesys application. Maybe I try to explain it like this:
Codesys is running, script from parameter was executed -> after a while I want to stop Codesys by executing another script file -> Question: How to do it from command line?


Top
   
PostPosted: Thu Jul 19, 2012 1:23 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, daniel_REC,

daniel_REC wrote:
Thank You M.Schaber for quick answer, but You did write exactly the same solution that is in my post, and I did ask about HOW to start the next python script while Codesys is allready running?

I can't do that with:
C:\Program Files\3S CoDeSys V3.4 SP3\CoDeSys\Common>start /wait CoDeSys.exe --profile="CoDeSys V3.4 SP3" --runscript="C:\run_second_script.py"
because it will open another Codesys application. Maybe I try to explain it like this:
Codesys is running, script from parameter was executed -> after a while I want to stop Codesys by executing another script file -> Question: How to do it from command line?


I'm not really sure what you mean. With "Codesys", do you mean the runtime or the IDE?

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Jul 19, 2012 2:10 pm 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Hm... now i don't know what You mean:)
I want to do a really simple thing in theory (so I think). I have created project in Codesys application and i can run it using windows command line (cmd) by writing path to Codesys.exe and parameter after this (in parameter is path to script that starts project, login and run it). After the whole project is started the script file is finished working. And from this part I need help:
I have another script that looks like this:
----------------------------------------------------------------
from __future__ import print_function

proj = projects.primary
app = proj.active_application
onlineapp = online.create_online_application(app)
onlineapp.logout()
-----------------------------------------------------------------
If I will execute this script by selecting in Codesys "Tools->Scripting->Execute Script File..." then it is working, the project is logout. But I want to do it in another way - I want to execute this script from windows command line. My question is, what should I write in cmd to make it work?


Top
   
PostPosted: Thu Jul 19, 2012 2:35 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, Daniel,

daniel_REC wrote:
Hm... now i don't know what You mean:)


The CoDeSys IDE is the integrated development environment, the tool you use to write IEC-61131 applications, and which also executes the IronPython scripts.

The CoDeSys runtime is where your IEC applications are actually running. It may be a CoDeSys Control Win running on the same PC as your IDE (The little Image icon in your notification area), or running remote on some other machine (e. G. an Industrial PC or PLC).

When you go "Online", you connect your IDE with your Runtime, and "download" the compiled application from the IDE to the Runtime, so it can be executed there.

daniel_REC wrote:
I want to do a really simple thing in theory (so I think). I have created project in Codesys application and i can run it using windows command line (cmd) by writing path to Codesys.exe and parameter after this (in parameter is path to script that starts project, login and run it). After the whole project is started the script file is finished working. And from this part I need help:
I have another script that looks like this:
----------------------------------------------------------------
from __future__ import print_function

proj = projects.primary
app = proj.active_application
onlineapp = online.create_online_application(app)
onlineapp.logout()
-----------------------------------------------------------------
If I will execute this script by selecting in Codesys "Tools->Scripting->Execute Script File..." then it is working, the project is logout. But I want to do it in another way - I want to execute this script from windows command line. My question is, what should I write in cmd to make it work?


Now, if your question is about starting and stopping IEC applications, then you do not need to keep the CoDeSys IDE UI open after your script has finished executing. You can insert a
Code:
system.exit()
statement at the end of the python script to close the CoDeSys IDE after the Script is finished, or add "--noUI" to the command line which prevents the IDE UI from even showing at all, and automatically exits the IDE when the Script is finished.

On the other hand, if your question is about shutting an already running IDE via command line, or tell an already running IDE to execute another script via command line: Both cases are not yet covered by scripting itsself, but you may use external tools like AutoIt.


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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Fri Jul 20, 2012 6:31 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Hello,

So I'm talking about Codesys IDE application. Unfortunately I can't close it by system.exit() because it is still needed. I'm using it with TestStand and there are some test cases that requires to stop the runtime and logout to do some changes in modules parameters, and after that login again and start runtime. Now I'm doing it manually, but I was thinking that I can do it by executing script, and I can, but still the script I have to execute manually, so it is not automated system yet. For executing new script I could use Autoit like You did mention, but it is not so proffesional:)


Top
   
PostPosted: Fri Jul 20, 2012 10:41 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
daniel_REC wrote:
Hello,

So I'm talking about Codesys IDE application. Unfortunately I can't close it by system.exit() because it is still needed. I'm using it with TestStand and there are some test cases that requires to stop the runtime and logout to do some changes in modules parameters, and after that login again and start runtime. Now I'm doing it manually, but I was thinking that I can do it by executing script, and I can, but still the script I have to execute manually, so it is not automated system yet. For executing new script I could use Autoit like You did mention, but it is not so proffesional:)


Hmm. I don't know about TestStand, but maybe you can close the IDE after the first script, and just re-start it to do the second login, stop the runtime, logout, update, login and restart. If you use the same project, and you save it before closing, it should be able to reload the compile info, and login without any interruption to the IEC application.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Fri Jul 20, 2012 1:18 pm 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Thank You, now it's working:)
But in the future - CoDeSys developers maybe should implement some way to do this without closing IDE because starting it even without UI take some time, and when it's closed we can't check what is the actual variables status.
The whole start/stop IDE for me was needed to import and replace some modules with different parameters, because I can't change it automaticaly. E.g. I have an analog input module and using DP-Parameters it can be switched between voltage and current measurement. Unfortunately this switch I can do only manually by stopping runtime, logging out, changing desired parameter by mouse click and then login and run. This is also another tip for developers to implement some way to change the module parameter with some programming code.


Top
   
PostPosted: Fri Jul 20, 2012 1:33 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, Daniel,

daniel_REC wrote:
Thank You, now it's working:)
But in the future - CoDeSys developers maybe should implement some way to do this without closing IDE because starting it even without UI take some time, and when it's closed we can't check what is the actual variables status.
We did already think about something like a "CoDeSys Scripting Server" which can be used to trigger scripts or other actions in an running CoDeSys IDE instance. Technically, this is easy to implement. But there are some "higher-level" problems like the question which IPC mechanism to use (TCP, or windows messages, etc.), and what to do if several CoDeSys instances are running on the same machine or even in the same user session on that machine - which instance is the one to execute the commands?

If you can live with your CoDeSys instance being blocked for user input, you can implement such a server yourself - see the topic Python and Threads in this forum for a guy who is doing something similar. You can use IronPython to listen on some socket and receiving commands which you then execute. However, you'll most likely have to use a mix of .NET and Python standard library APIs (for example to regularly pump the message queue of the main thread), and you'll leave the "officially supported" territory.

Additionally, most runtimes support concurrent connections, so - at least in some cases - it should work to use one CoDeSys instance to monitor the variables, and another one to manipulate the application via scripting.

daniel_REC wrote:
The whole start/stop IDE for me was needed to import and replace some modules with different parameters, because I can't change it automaticaly. E.g. I have an analog input module and using DP-Parameters it can be switched between voltage and current measurement. Unfortunately this switch I can do only manually by stopping runtime, logging out, changing desired parameter by mouse click and then login and run. This is also another tip for developers to implement some way to change the module parameter with some programming code.


We have plans to implement interfaces to configure device parameters via Python scripting, but I cannot give any concrete date yet. As a workaround, some of our customers remove() the object in question and import_native() a modified instance.

But we currently also prepare a public version of our Test Manager (which existed as an internal product for several years now), which supports setting of device parameters. As of current planning, a beta release might be ready by the end of the year, but this is not fixed yet.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Mon Jul 23, 2012 8:50 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Hello,

I,m trying now to speed up starting of Codesys IDE without UI and logout operation. Could you tell me can we modify that line:
onlineapp.login(OnlineChangeOption.Try, True)
to login without online change?

I did try with:
onlineapp.login(OnlineChangeOption.Never, False)
but it's not working, instead of simple login with no changes - building application is started.


Top
   
PostPosted: Fri Aug 17, 2012 11:42 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, Daniel,

daniel_REC wrote:
I,m trying now to speed up starting of Codesys IDE without UI and logout operation. Could you tell me can we modify that line:
onlineapp.login(OnlineChangeOption.Try, True)
to login without online change?

I did try with:
onlineapp.login(OnlineChangeOption.Never, False)
but it's not working, instead of simple login with no changes - building application is started.


OnlineChangeOption.Never usually forces a Download.

Maybe you can try the OnlineChangeOption.Force, it is documented as follows: "Online change shall be forced. If not possible, the action is terminated with no change.".

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Tue Mar 22, 2016 3:47 pm 
Offline

Joined: Mon Mar 21, 2016 10:34 am
Posts: 15
Hi,

I am trying to pass Parameters to my python script using Windows Batch commands. The command Looks like this:
Code:
SET PARAMETER = 100
C:\Program Files\3S CoDeSys V3.5 SP3\CoDeSys\Common>start /wait CoDeSys.exe --profile="CoDeSys V3.5 SP3" --runscript="C:\myscript.py" %PARAMETER%


But I am not able to Access the Parameter in my list of arguments using sys.argv in my script.

Can you probably provide an example on how to pass Parameters to my script.

Best regards,

SK


Top
   
PostPosted: Tue Mar 22, 2016 4:45 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 220
Hi SK.

codesys_sig_forum wrote:
Can you probably provide an example on how to pass Parameters to my script.

Command line:
Code:
CODESYS.exe --profile="CODESYS V3.5 SP8" --runscript="C:\Scripting\script_args.py" --scriptargs="-c --test=3"

Python code:
Code:
import sys
for a in sys.argv:
   print("Arg: " + a)

The content of argv is "C:\Scripting\script_args.py", "-c" and "--test=3".

BR
Martin

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Tue Sep 06, 2016 9:41 am 
Offline

Joined: Wed Aug 03, 2016 3:00 pm
Posts: 8
Hello,
is ther any documentation about all command line options for codesys.exe ?
I can only find a small set in the Online Help (e.g. --noUI and --scriptargs are missing).

Maybe there are more options to get codesys start or open projects faster? Like without loading libraries or without checking for errors in the Project.

Regards
Thomas


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 17 posts ]  Go to page 1 2 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


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