Modbus, reading registers with strings - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10) +--- Thread: Modbus, reading registers with strings (/showthread.php?tid=1245) |
Modbus, reading registers with strings - schippi - 20.02.2018 Hello, I'm using a json profile to read modbus registers from a 4g router. Reading normal values work perfect but I didn't find a solution how to read out 16 registers and convert it to string format. A possible solution in LUA is also welcome. Definition: Thank you in advance, Uwe RE: Modbus, reading registers with strings - Erwin van der Zwart - 20.02.2018 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() mbetslave(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 RE: Modbus, reading registers with strings - schippi - 21.02.2018 Hello Erwin, many thanks! I tried your code, but unfortunately I got no result anywhere. "log(result)" serves nothing! It looks like the code stops at the (in homelynk unknown ?) function called "lmcore.inttostr()" ??? Code: require('luamodbus') I read out the registers 71 to 87 which should contain the router name: "RUT955" and logged the variables (r1 to r16) directly and this is the current log Code: RouterModbus 21.02.2018 20:07:10 I attached the routers short modbus manual. B.R, Uwe RE: Modbus, reading registers with strings - Erwin van der Zwart - 21.02.2018 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') Erwin RE: Modbus, reading registers with strings - admin - 22.02.2018 More universal solution: Code: require('luamodbus') RE: Modbus, reading registers with strings - schippi - 22.02.2018 Hello Erwin, the result is: RouterModbus2 22.02.2018 11:46:00 * string: RUT955H7V02043 Your solution works perfect and i prefer the second one, caused on it's flexibility! I'll give you a very big "THANK YOU" for your enthusiastic service Have a nice day and b. r., Uwe PS.: I know, that the success of this product depends essentially on such colleagues as you. |