Open karlp opened 4 years ago
How about adding a separate metatable to handle decoding the data from the registers? Similar to how it works in pyModbus?
Something along the line of;
local mb = require("libmodbus")
-- Perform a request to get some register values
local decoder = mb.new_decoder(register_values)
print(decoder.get_float32_abcd()) -- 1234.456
print(decoder.get_uint32()) -- 1000
The idea is to have the decoder keep track of the current offset in the register_values table.
To handle encoding, the reverse would apply.
local mb = require("libmodbus")
local encoder = mb.new_encoder()
encoder.add_float32_abcd(1234.456)
encoder.add_uint16(1000)
encoder.add_int32(2000)
print(encoder.registers()) -- or encoder.build()
Currently, the helpers to get/set 32/64 bit values from 16bit registers expect to get each register as a parameter.
when pulling out multiple numbers, it might be nice to support indexing a register table instead? Could automatically attempt to do the right thing based on the type of the first argument?