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, reading registers with strings
#4
Hi Uwe,

Thanks for the values, now i could figure out that each register holds 2 chars.

Try this (:

PS: Result is RUT955H7V020

Code:
require('luamodbus')
mb = luamodbus.tcp()

mb:open('192.168.2.1', 502)
mb:connect()

r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16 = mb:readregisters(71,16)

function twobytetochars(value)
 charsvalue = lmcore.hextostr(lmcore.inttohex(value,2))
 return charsvalue
end

if r1 then r1 = twobytetochars(r1) else r1 = "" end
if r2 then r2 = twobytetochars(r2) else r2 = "" end
if r3 then r3 = twobytetochars(r3) else r3 = "" end
if r4 then r4 = twobytetochars(r4) else r4 = "" end
if r5 then r5 = twobytetochars(r5) else r5 = "" end
if r6 then r6 = twobytetochars(r6) else r6 = "" end
if r7 then r7 = twobytetochars(r7) else r7 = "" end
if r8 then r8 = twobytetochars(r8) else r8 = "" end
if r9 then r9 = twobytetochars(r9) else r9 = "" end
if r10 then r10 = twobytetochars(r10) else r10 = "" end
if r11 then r11 = twobytetochars(r11) else r11 = "" end
if r12 then r12 = twobytetochars(r12) else r12 = "" end
if r13 then r13 = twobytetochars(r13) else r13 = "" end
if r14 then r14 = twobytetochars(r14) else r14 = "" end
if r15 then r15 = twobytetochars(r15) else r15 = "" end
if r16 then r16 = twobytetochars(r16) else r16 = "" end

result = r1 .. r2 .. r3 .. r4 .. r5 .. r6 .. r7 .. r8 .. r9 .. r10 .. r11 .. r12 .. r13 .. r14 .. r15 .. r16
log(result)

mb:close()
BR,

Erwin
Reply


Messages In This Thread
RE: Modbus, reading registers with strings - by Erwin van der Zwart - 21.02.2018, 21:56

Forum Jump: