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
#2
Hi Uwe,

Can you try this? I'm not sure how the chars are written in the register so it could not work like this (maybe it's HEX based)

require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485', 19200, 'E', 8, 1, 'H')
mb:connect()
mbConfusedetslave(1)
r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16 = mb:readregisters(7,16)
result = lmcore.inttostr(r1) .. lmcore.inttostr(r2) .. lmcore.inttostr(r3) .. lmcore.inttostr(r4) .. lmcore.inttostr(r5) .. lmcore.inttostr(r6) .. lmcore.inttostr(r7) .. lmcore.inttostr(r8) .. lmcore.inttostr(r9) .. lmcore.inttostr(r10) .. lmcore.inttostr(r11) .. lmcore.inttostr(r12) .. lmcore.inttostr(r13) .. lmcore.inttostr(r14) .. lmcore.inttostr(r15) .. lmcore.inttostr(r16)
log(result)
mb:close()

BR,

Erwin
Reply


Messages In This Thread
RE: Modbus, reading registers with strings - by Erwin van der Zwart - 20.02.2018, 22:23

Forum Jump: