This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Script execution priority
#1
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
Reply
#2
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.
Reply
#3
(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.
Reply
#4
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
Reply
#5
(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!
Reply
#6
Please contact us via e-mail
Reply
#7
Does this code work if I use Modbus TCP instead of Modbus RTU?
Reply
#8
No, there's no point as TCP can be used simultaneously unlike RS485.
Reply
#9
Is this solution validated yet in Wiser / SL 2.1.1 ?
thx
Reply


Forum Jump: