Logic Machine Forum
Script execution priority - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Script execution priority (/showthread.php?tid=387)



Script execution priority - Mirco - 13.09.2016

Hi everybody!  Big Grin

I have a big problem, with the execution of my project and I hope you will have some advise.
I have to read/write datas from/to 4 different PLCs in the same Modbus RTU network. There are 14 different script (6 resident, 6 event and 2 scheduler) that exchange data via modbus RTU.
To avoid that one or more script start before the finish of the script that is in execution, I use this code:


Code:
repeat
 tmp = storage.get("Modbus")
 if (tmp == nil or tmp == 0) then
   storage.set("Modbus", 1)
   continue = true
   alert("--SCRIPT--Dati CT -> START")    --This line is used for debuggig purpose
 else
   continue = false
   os.sleep(0.2)
 end
until (continue)

--My script code that start communication with one modbus slave PLC

Sometimes it happened that 2 or more script started at the same time and they were both executed. This couse timeout and wrong slave errors because scripts set the communication with different slaves.

I hope you will understand my problem, I'm not very good in english Tongue

Mirco


RE: Script execution priority - admin - 13.09.2016

You can use built-in modbus mapper and create a profile for each PLC. This way you won't have any sync issues. You can also use modbus mapper as a proxy, I'll provide an example later on.


RE: Script execution priority - Mirco - 13.09.2016

(13.09.2016, 07:17)admin Wrote: You can use built-in modbus mapper and create a profile for each PLC. This way you won't have any sync issues. You can also use modbus mapper as a proxy, I'll provide an example later on.

I can't, because I have to manipulate datas before writenig it into an object (for example: my PLC use 2 byte integer registers, and I have to convert it in 2 byte float for the visualization) or I have to don't read some registers if a condition is checked.


RE: Script execution priority - admin - 14.09.2016

You can use proxy which will be available in RC2 firmware. First, you have to enable RTU in modbus mapper, then you can use it in scripts like this:

Code:
mbproxy = require('mbproxy')
mb = mbproxy.new()
mb:setslave(2)
r1, r2, r3 = mb:readregisters(0, 3)

log(r1, r2, r3)

In your code you will just have to replace luamodbus require/open/connect with proxy functions and you won't have any issues with simultaneous port access from several scripts Smile


RE: Script execution priority - Mirco - 16.09.2016

(14.09.2016, 08:40)admin Wrote: You can use proxy which will be available in RC2 firmware. First, you have to enable RTU in modbus mapper, then you can use it in scripts like this:

Code:
mbproxy = require('mbproxy')
mb = mbproxy.new()
mb:setslave(2)
r1, r2, r3 = mb:readregisters(0, 3)

log(r1, r2, r3)

In your code you will just have to replace luamodbus require/open/connect with proxy functions and you won't have any issues with simultaneous port access from several scripts Smile

Thanks for your help!  Smile I tried it yesterday, but unfortunatelly the Schneider HomeLYnk and SpaceLYnk.. (Next time I will buy your LogicMachine)
Do you have a library that can I import, or something else that can I do?
Thanks again for your help!


RE: Script execution priority - admin - 16.09.2016

Please contact us via e-mail


RE: Script execution priority - Mirco - 02.12.2016

Does this code work if I use Modbus TCP instead of Modbus RTU?


RE: Script execution priority - admin - 02.12.2016

No, there's no point as TCP can be used simultaneously unlike RS485.


RE: Script execution priority - esteve.budia - 15.05.2018

Is this solution validated yet in Wiser / SL 2.1.1 ?
thx