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.

Modbus RTU485-2
#1
Good afternoon

I have a Modbus calorie meter connected to the RS485-2 port of my LM5pL and I would like to know how I have to do it to read 32bit values in Modbus RTU using scripts, thank you very much.

THX.

Hello again, I try to communicate using this code, I can read something but I don't know if it's correct, thank you
Code:
require('luamodbus')
mb = luamodbus.rtu()

mb:open('/dev/RS485-2', 2400, 'E', 8, 1, 'H')
mb:connect()

mb:setslave(44)

        res101 = mb:readregisters(1)
if res101 == nil then
 grp.update('32/2/1', 0)
else
    grp.update('32/2/1', res101*0,01)
    end
        os.sleep(1)
        
        res102 = mb:readregisters(2)
if res102 == nil then
 grp.update('32/2/2', 0)
else
 grp.update('32/2/2', res102*0,01)
 end
   os.sleep(1)

   res103 = mb:readregistervalue(3, "uint32")
grp.update('32/2/3', res103)
os.sleep(1)

   res105 = mb:readregistervalue(5, "uint32")
grp.update('32/2/5', res105)
os.sleep(1)

   res107 = mb:readregistervalue(7, "uint32")
grp.update('32/2/7', res107)
os.sleep(1)

   res109 = mb:readregistervalue(9, "uint32")
grp.update('32/2/9', res109)
os.sleep(1)

   res113 = mb:readregisters(13)
grp.update('32/2/13', res113)
os.sleep(1)

   res114 = mb:readregistervalue(14, "uint32")
grp.update('32/2/14', res114)
os.sleep(1)

   res116 = mb:readregistervalue(16, "uint32")
grp.update('32/2/16', res116)
os.sleep(1)

   res118 = mb:readregistervalue(18, "uint32")
grp.update('32/2/18', res118)
os.sleep(1)

   res120 = mb:readregisters(20)
grp.update('32/2/20', res120)
os.sleep(1)

mb:close()

mb:open('/dev/RS485-2', 2400, 'E', 8, 1, 'H')
mb:connect()

mb:setslave(45)

        res201 = mb:readregisters(1)
if res201 == nil then
 grp.update('32/3/1', 0)
else
    grp.update('32/3/1', res201*0,01)
    end
        os.sleep(1)    

        res202 = mb:readregisters(2)
if res202 == nil then
 grp.update('32/3/2', 0)
else
 grp.update('32/3/2', res202*0,01)
 end
   os.sleep(1)

   res203 = mb:readregistervalue(3, "uint32")
grp.update('32/3/3', res203)
os.sleep(1)

   res205 = mb:readregistervalue(5, "uint32")
grp.update('32/3/5', res205)
os.sleep(1)

   res207 = mb:readregistervalue(7, "uint32")
grp.update('32/3/7', res207)
os.sleep(1)

   res209 = mb:readregistervalue(9, "uint32")
grp.update('32/3/9', res209)
os.sleep(1)

   res213 = mb:readregisters(13)
grp.update('32/3/13', res213)
os.sleep(1)

   res214 = mb:readregistervalue(14, "uint32")
grp.update('32/3/14', res214)
os.sleep(1)

   res216 = mb:readregistervalue(16, "uint32")
grp.update('32/3/16', res216)
os.sleep(1)

   res218 = mb:readregistervalue(18, "uint32")
grp.update('32/3/18', res218)
os.sleep(1)

   res220 = mb:readregisters(20)
grp.update('32/3/20', res220)
os.sleep(1)

mb:close()

Attached Files Thumbnail(s)
   
Reply
#2
You should really use a profile here Smile

You have an issue with multiplier, there should be a dot separator instead of comma:
Code:
grp.update('32/2/1', res101*0.01)

There's an optional third argument for readregistervalue - word/byte swap. Default value is w. More info here: http://openrb.com/docs/modbus.htm
Code:
res103 = mb:readregistervalue(3, "uint32", "n")
Reply
#3
(25.07.2018, 06:59)admin Wrote: You should really use a profile here Smile

You have an issue with multiplier, there should be a dot separator instead of comma:
Code:
grp.update('32/2/1', res101*0.01)

There's an optional third argument for readregistervalue - word/byte swap. Default value is w. More info here: http://openrb.com/docs/modbus.htm
Code:
res103 = mb:readregistervalue(3, "uint32", "n")

In this case we need to use scripting instead of profile because we're already using profile for RS485-1 modbus communication with a different baud rate. 

Appart from these issues, is the script ok?
Is it correct to use os.sleep into the script?

Thanks,
Reply
#4
(25.07.2018, 08:52)David Wrote:
(25.07.2018, 06:59)admin Wrote: You should really use a profile here Smile

You have an issue with multiplier, there should be a dot separator instead of comma:
Code:
grp.update('32/2/1', res101*0.01)

There's an optional third argument for readregistervalue - word/byte swap. Default value is w. More info here: http://openrb.com/docs/modbus.htm
Code:
res103 = mb:readregistervalue(3, "uint32", "n")

In this case we need to use scripting instead of profile because we're already using profile for RS485-1 modbus communication with a different baud rate. 

Appart from these issues, is the script ok?
Is it correct to use os.sleep into the script?

Thanks,

update modbus package to genohm-scada-modbus_20171103_mxs.ipk - it can work with 3 rs lines with different settings
for imx6 use this genohm-scada-modbus_20171103_imx6.ipk
Reply
#5
Hello,

Thank you very much for your responses. I have an LM5Lp so I have used the imx6 file (I understand that it is the processor that carries the lite power) once this is done I have rebooted the Logic Machine but everything remains the same, if I go to the Modbus option I only see one of the two ports of which the equipment has, any solution? Thank you very much.
Reply
#6
(25.07.2018, 10:13)josep Wrote: Hello,

Thank you very much for your responses. I have an LM5Lp so I have used the imx6 file (I understand that it is the processor that carries the lite power) once this is done I have rebooted the Logic Machine but everything remains the same, if I go to the Modbus option I only see one of the two ports of which the equipment has, any solution? Thank you very much.

go to system configuration - system - packages and check ghenom-scada-modbus version. it should be 20171103. if it's not press "green plus" button and install package. 

if it is 20171103, try to clear browser cache.

just checked on my lm5 (see attach)

Attached Files Thumbnail(s)
   
Reply
#7
Hi,

thank you AEK, I clear a browser cache and now it works fine. Now I have a problem with some Modbus adresses, I make a Profile for a heat meter but It not read a LONG format, I define it with uint32 and I use the first of the two adresses number. For example to define Acumulated Head I used this:

{ "name": "Accumulated heat", "bus_datatype": "uint32", "type": "inputregister", "datatype": "uint32", "address": 3, "writable": false, "units": " kWh"  },

but still not working, the temperature values, the status value and the Modbus Adress works fine.

Any idea? thx!

Attached Files Thumbnail(s)
   
Reply
#8
Have you tried reading values via RTU read test? Temperature values are 2 bytes (1 register / int16).
Reply
#9
you can't read any value, or get incorrect value? is there any errors in error log tab? maybe you need read swap option. as Admin said - try to use RTU read test button, it will help you to define correct params
Reply
#10
Hi,

I read some values correctly and the others not work, it value is 0 all the time, this values has defined as LONG and use two modubs adresses. The other problem is that sometimes Modbus have a Timeout problem and it apears in Error Log.

Thank you
Reply
#11
In profile it should be register (fn #3) not inputregister (fn #4). For LONG values use int32 or uint32 data type in RTU read test.
Reply


Forum Jump: