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 Tue Aug 20, 2019 6:42 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Help..
PostPosted: Fri Nov 01, 2013 12:08 pm 
Offline

Joined: Thu Sep 12, 2013 9:54 am
Posts: 12
Hello,

I have two questions,


1st,
If it is possible to run CodeSys Script Language in Python 2.7,3.3 and IronPython IDLE/Console? If yes, how to get started?

For example what is a correct function, (correct me if I am wrong), need to import?

2nd,
I wish to write a value into a FBD instance via RAMPHANDLE(is a Output) via Python script continuously,I thought the command should be...

Code:
onlineapp.write_value("PLC_PRG.rDCInput")

Where,
rDCInput = input variable from a FBD

But, I have no idea where to accommodate the RAMPHANDLE via a CodeSys scripting command.



Many Thanks.


Top
   
 Post subject: Re: Help..
PostPosted: Tue Nov 05, 2013 10:48 am 
Offline
Frequent User
Frequent User
User avatar

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

labview wrote:
If it is possible to run CodeSys Script Language in Python 2.7,3.3 and IronPython IDLE/Console? If yes, how to get started?
For example what is a correct function, (correct me if I am wrong), need to import?

For the CODESYS Script Language, the IronPython interpreter is embedded within the CODESYS process and the "Automation Platform" framework. The CODESYS specific functions are directly provided by the host, and there is no separate module you can import from an external python interpreter.

It is certainly doable to start CODESYS from IronPython - you would need to initialize the Automation Platform and CODESYS from within the script, and then use the ScriptEngine to execute code. If your company bought the "Automation Platform" license, can download the brandabelling sample from the Developer Network - the C# code there illustrates how to get CODESYS running.

For a normal CPython script (whether 2.7 or 3.3), you would first need to start up a .NET Framework via the .NET Hosting API (probably using cTypes or COM), then start the Automation Platform and CODESYS within the .NET Framework, and then use the ScriptEngine to get a Script Scope. As an additional hurdle, the IronPython and CPython script scopes are very different beasts, you would need to use COM or Python for .NET to interact with the IronPython and .NET objects.

Whether all that is worth the hassle is another question.

Maybe you can get a similar experience using another approach: You could try to use Python Remoting (or some other RPC implementation of your choice). In CODESYS, you start a remote server, and then you connect there via the "normal" python script. I did not test this myself, but it may work for you.

labview wrote:
2nd,
I wish to write a value into a FBD instance via RAMPHANDLE(is a Output) via Python script continuously,I thought the command should be...

Code:
onlineapp.write_value("PLC_PRG.rDCInput")

Where,
rDCInput = input variable from a FBD

But, I have no idea where to accommodate the RAMPHANDLE via a CodeSys scripting command.

I'm not exactly sure what you want to accomplish there.
Code:
onlineapp.write_value()
writes the value once, and you need a second parameter with the actual value. You can of course read the RAMPHANDLE variable via monitoring, and write the value back in a loop, but you should be aware that each read/write cycle has the overhead of monitoring cycle time (usually 200ms) and network latency, so this may not really work for you, depending on your task cycle time and fieldbus reliability.

If your test needs reliable timing, you should instrument your application or FB via IEC code which handles the test logic, and then execute it (maybe using the IEC Unit Test functionality of the test manager).

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

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


Top
   
 Post subject: Re: Help..
PostPosted: Wed Nov 06, 2013 9:06 am 
Offline

Joined: Thu Sep 12, 2013 9:54 am
Posts: 12
Hello Schaber,

Thanks for your information,

"you should instrument your application or FB via IEC code which handles the test logic, and then execute it (maybe using the IEC Unit Test functionality of the test manager)."
- I don't really understand what you mean here but I assume that it is possible to integrate instrumentation( including looping function for example passing latest value into the RAMPHANDLE) into the IEC unit test functionality of the test manager?


Next question,

For example,

From CodeSys help file, script example 1:
Code:
# opens project
proj = projects.open("D:\\data\\projects\\Ampel.project")

# set "Ampel.project" to active application
app = proj.active_application           
onlineapp = online.create_online_application(app)

# login to device
onlineapp.login(OnlineChangeOption.Try, True)           

# set status of application to "run", if not in "run"
if not onlineapp.application_state == ApplicationState.run:
    onlineapp.start()

# wait 1 second
system.delay(1000)           

# read value of iVar1
value = onlineapp.read_value("PLC_PRG.iVar1")           


and possible for me to reuse back as the above command while the test manager or IEC Unit Test functionality of the test manager is "open"?

Many Thanks.


Top
   
 Post subject: Re: Help..
PostPosted: Thu Nov 07, 2013 8:47 am 
Offline
Frequent User
Frequent User
User avatar

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

labview wrote:
"you should instrument your application or FB via IEC code which handles the test logic, and then execute it (maybe using the IEC Unit Test functionality of the test manager)."
- I don't really understand what you mean here but I assume that it is possible to integrate instrumentation( including looping function for example passing latest value into the RAMPHANDLE) into the IEC unit test functionality of the test manager?


Currently, you need to generate the test logic IEC code containing said loop yourself (as I showed you in Example: How to create an IEC Unit Test FB via Python script, and then include it into the testbed project either manually, or via scripting or test manager functionality (import etc...). This is what I meant by "instrumenting the code".

The IEC Unit Test functionality can then be used to execute said test - of course, you can also do the same manually via the monitoring functions of the test manager or scripting, but the IEC Unit Test functionality is more comfortable, as it takes care for all the handshaking etc.


labview wrote:
From CodeSys help file, script example 1:
Code:
<--- snip --- snap --->


and possible for me to reuse back as the above command while the test manager or IEC Unit Test functionality of the test manager is "open"?


It is possible to run scripts while the test manager is running, using the "Execute Script" action. However, it is not possible to run python scripts while the IEC Unit Test is running. (In Theory, you could run two test scripts in parallel using the "Remote Call" functionality of the test manager, but there is no useful means of synchronization with the IEC Unit Test, so this won't help you to solve your problem.)

But I don't see the point in running an example script which logs in another application while the IEC Unit Test is running - this will only lead to undesirable side effects.

If you could tell us which actual problem you want to solve in detail, we could try to help you.

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

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


Top
   
 Post subject: Re: Help..
PostPosted: Thu Nov 07, 2013 12:27 pm 
Offline

Joined: Thu Sep 12, 2013 9:54 am
Posts: 12
M.Schaber wrote:
Hi,

labview wrote:
"you should instrument your application or FB via IEC code which handles the test logic, and then execute it (maybe using the IEC Unit Test functionality of the test manager)."
- I don't really understand what you mean here but I assume that it is possible to integrate instrumentation( including looping function for example passing latest value into the RAMPHANDLE) into the IEC unit test functionality of the test manager?


Currently, you need to generate the test logic IEC code containing said loop yourself (as I showed you in Example: How to create an IEC Unit Test FB via Python script, and then include it into the testbed project either manually, or via scripting or test manager functionality (import etc...). This is what I meant by "instrumenting the code".

The IEC Unit Test functionality can then be used to execute said test - of course, you can also do the same manually via the monitoring functions of the test manager or scripting, but the IEC Unit Test functionality is more comfortable, as it takes care for all the handshaking etc.

labview wrote:
From CodeSys help file, script example 1:
Code:
<--- snip --- snap --->


and possible for me to reuse back as the above command while the test manager or IEC Unit Test functionality of the test manager is "open"?


It is possible to run scripts while the test manager is running, using the "Execute Script" action. However, it is not possible to run python scripts while the IEC Unit Test is running. (In Theory, you could run two test scripts in parallel using the "Remote Call" functionality of the test manager, but there is no useful means of synchronization with the IEC Unit Test, so this won't help you to solve your problem.)

But I don't see the point in running an example script which logs in another application while the IEC Unit Test is running - this will only lead to undesirable side effects.

If you could tell us which actual problem you want to solve in detail, we could try to help you.



Hi Schaber,

Let's use this script below as example, so that it is easy for me to raise my problems,


1st problem

Code:
# script example ReadVariable.py

# Close all projects
while len(projects.all) > 0:           
    projects.all[0].close()

# opens project
proj = projects.open("D:\\data\\projects\\Ampel.project")

# set "Ampel.project" to active application
app = proj.active_application           
onlineapp = online.create_online_application(app)

# login to device
onlineapp.login(OnlineChangeOption.Try, True)           

# set status of application to "run", if not in "run"
if not onlineapp.application_state == ApplicationState.run:
    onlineapp.start()

# wait 1 second
system.delay(1000)           

# read value of iVar1
value = onlineapp.read_value("PLC_PRG.iVar1")           

# display value in message view or command line
print value             

# log out from device and close "Ampel.project"
onlineapp.logout()           
proj.close()
 



From the above script, it is possible to implement inside Test Manager? if yes, how to do it (what command can be use) especially those with onlineapp command and and how to read FBD output from Codesys such as "PLC_PRG.iVar1" without onlineapp command?


2nd problem,

If implement a FOR LOOP inside Test Manager's Python script,

1. Can I read directly input of the FBD and output from the FBD for each loop iteration, If not possible goto No.2,
2. Can a FBD update Input Parameters values and Output parameters values inside the Test Manager for each loop iteration.

Sorry it sounds complicated,

Many Thanks.


Top
   
 Post subject: Re: Help..
PostPosted: Thu Nov 07, 2013 2:06 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 251
Hi, labview.

labview wrote:
From the above script, it is possible to implement inside Test Manager? if yes, how to do it (what command can be use) especially those with onlineapp command and and how to read FBD output from Codesys such as "PLC_PRG.iVar1" without onlineapp command?

I wrote and attachted a simple test script which implements the same actions as your example in python. Extract the archive and install the test script into your test repository. The first solution uses a test action which executes some python code to read and print the value. The second solution uses test actions to read and store the value.

labview wrote:
If implement a FOR LOOP inside Test Manager's Python script,

1. Can I read directly input of the FBD and output from the FBD for each loop iteration, If not possible goto No.2,
2. Can a FBD update Input Parameters values and Output parameters values inside the Test Manager for each loop iteration.

Yes but reading and writing of variables through the monitoring takes some time. If the timing is essential then you should write your tests in IEC and use the IEC Unit Testing of the Test Manager.


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
   
 Post subject: Re: Help..
PostPosted: Thu Dec 19, 2013 6:55 pm 
Offline

Joined: Thu Sep 12, 2013 9:54 am
Posts: 12
Hi there,

I have a question,

1. How to write a value into a input Function Block(e,g CHxInput) via Test Manager.scripting -> ExecuteScript using Python command?

Many Thanks.



M.Keller wrote:
Hi, labview.

labview wrote:
From the above script, it is possible to implement inside Test Manager? if yes, how to do it (what command can be use) especially those with onlineapp command and and how to read FBD output from Codesys such as "PLC_PRG.iVar1" without onlineapp command?

I wrote and attachted a simple test script which implements the same actions as your example in python. Extract the archive and install the test script into your test repository. The first solution uses a test action which executes some python code to read and print the value. The second solution uses test actions to read and store the value.

labview wrote:
If implement a FOR LOOP inside Test Manager's Python script,

1. Can I read directly input of the FBD and output from the FBD for each loop iteration, If not possible goto No.2,
2. Can a FBD update Input Parameters values and Output parameters values inside the Test Manager for each loop iteration.

Yes but reading and writing of variables through the monitoring takes some time. If the timing is essential then you should write your tests in IEC and use the IEC Unit Testing of the Test Manager.


Top
   
 Post subject: Re: Help..
PostPosted: Wed Feb 18, 2015 8:55 am 
Offline

Joined: Tue Feb 17, 2015 9:15 am
Posts: 3
Hello,

onlineapp.write_value()
is not available anymore. I have looked at the script engine help document, write_online_value(String) and write_online_value Method (IScriptEnumerationValue) are available. But both of them have only one argument.

shouldn't it be write_online_value(String, actual value) ?


Top
   
 Post subject: Re: Help..
PostPosted: Wed Feb 18, 2015 9:31 am 
Offline

Joined: Tue Feb 17, 2015 9:15 am
Posts: 3
learning wrote:
Hello,

onlineapp.write_value()
is not available anymore. I have looked at the script engine help document, write_online_value(String) and write_online_value Method (IScriptEnumerationValue) are available. But both of them have only one argument.

shouldn't it be write_online_value(String, actual value) ?


I have found the solution to write the values: e.g.

onlineApp.set_prepared_value("PLC_PRG.counter", "5")
onlineApp.write_prepared_values()

viewtopic.php?f=18&t=5538


Top
   
 Post subject: Re: Help..
PostPosted: Fri Feb 20, 2015 10:26 am 
Offline
Frequent User
Frequent User
User avatar

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

learning wrote:
Hello,

onlineapp.write_value()
is not available anymore. I have looked at the script engine help document, write_online_value(String) and write_online_value Method (IScriptEnumerationValue) are available. But both of them have only one argument.

shouldn't it be write_online_value(String, actual value) ?


I'm not sure what you're writing about.

Our online application never had a write_value() method.

Maybe you're an OEMs customized CODESYS version which has their own extensions to the script engine?

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

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 10 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