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...
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2013-11-05
Originally created by: M.Schaber
Hi, labview,
labview hat geschrieben:
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 hat geschrieben:
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...
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. ```
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).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"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:
\# opensprojectproj=projects.open("D:\\data\\projects\\Ampel.project")
\# set"Ampel.project"toactiveapplicationapp=proj.active_application     Â
onlineapp=online.create_online_application(app)
\# logintodeviceonlineapp.login(OnlineChangeOption.Try, True)Â Â Â Â Â Â
\# setstatusofapplicationto"run", ifnotin"run"ifnotonlineapp.application_state==ApplicationState.run:
  onlineapp.start()
\# wait1secondsystem.delay(1000)Â Â Â Â Â Â
\# readvalueofiVar1value=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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2013-11-07
Originally created by: M.Schaber
Hi,
labview hat geschrieben:
"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?
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 hat geschrieben:
From CodeSys help file, script example 1:
<--- 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.
M.Schaber hat geschrieben:
Hi,
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.
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
\# scriptexampleReadVariable.py
\# Closeallprojectswhilelen(projects.all)>0:Â Â Â Â Â Â
  projects.all[0].close()
\# opensprojectproj=projects.open("D:\\data\\projects\\Ampel.project")
\# set"Ampel.project"toactiveapplicationapp=proj.active_application     Â
onlineapp=online.create_online_application(app)
\# logintodeviceonlineapp.login(OnlineChangeOption.Try, True)Â Â Â Â Â Â
\# setstatusofapplicationto"run", ifnotin"run"ifnotonlineapp.application_state==ApplicationState.run:
  onlineapp.start()
\# wait1secondsystem.delay(1000)Â Â Â Â Â Â
\# readvalueofiVar1value=onlineapp.read_value("PLC_PRG.iVar1")Â Â Â Â Â Â
\# displayvalueinmessagevieworcommandlineprintvalue      Â
\# logoutfromdeviceandclose"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,
Can I read directly input of the FBD and output from the FBD for each loop iteration, If not possible goto No.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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
labview hat geschrieben:
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 hat geschrieben:
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.
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 hat geschrieben:
Hi, labview.
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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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) ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
learning hat geschrieben:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2015-02-20
Originally created by: M.Schaber
Hi, learning,
learning hat geschrieben:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
Where,
rDCInput = input variable from a FBD
But, I have no idea where to accommodate the RAMPHANDLE via a CodeSys scripting command.
Many Thanks.
Originally created by: M.Schaber
Hi, labview,
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.
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. ```
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).
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:
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.
Originally created by: M.Schaber
Hi,
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
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.
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
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,
Sorry it sounds complicated,
Many Thanks.
Hi, labview.
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.
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.
Example 1 (1.0).tsd.zip [1.33 KiB]
Hi there,
I have a question,
Many Thanks.
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()
l viewtopic.php?f=18&t=5538 l
Originally created by: M.Schaber
Hi, learning,
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?