25.09.2017, 06:18
Erwin, full documenation is not finished, but here are the most important functions:
Code:
mb:setslave(slaveid)
Sets slave id to read/write data from/to
mb:readcoils(start, count) [01]
mb:readdiscreteinputs(start, count) [02]
mb:readregisters(start, count) [03]
mb:readinputregisters(start, count) [04]
Reads one or many registers/coils from the start address
Returns all values on success and nil, error description on error
mb:writebits(start, v1, [v2, [v3, ...]]) [05]
mb:writemultiplebits(start, v1, [v2, [v3, ...]]) [15]
mb:writeregisters(start, v1, [v2, [v3, ...]]) [06]
mb:writemultipleregisters(start, v1, [v2, [v3, ...]]) [16]
Writes values to registers/coils from the start address
Single write will be used when only one value is supplied, multiple write otherwise
Returns all of values written on success and nil, error description on error
Use writeregisters/writemultipleregisters to force writing using multiple
coil/register write function even when writing to a single coil or register
mb:readregistervalue(address, datatype, [swap]) [03]
mb:readinputregistervalue(address, datatype, [swap]) [04]
Reads encoded register(s) value based on the specified datatype:
"int16" - signed 2-byte (1 register) integer
"uint16" - usigned 2-byte (1 register) integer
"float16" - 2-byte floating point (KNX format, used in some HVAC units)
"int32" - signed 4-byte (2 registers) integer
"uint32" - unsigned 4-byte (2 registers) integer
"float32" - 4-byte (2 registers) floating point (IEEE 754)
"int64" - signed 8-byte (4 registers) integer
"uint64" - unsigned 8-byte (4 registers) integer
"float64" - 8-byte (4 registers) floating point (IEEE 754)
Optionally, it`s possible to swap register/byte order
Default value is word (2-byte) swap
Possible string values: n (no swap), w (word swap), b (byte swap), bw (byte and word swap)
Returns value on success and nil, error description on error
mb:writeregistervalue(address, value, datatype, [swap]) [06/16]
Writes encoded value to register(s) based on the specified datatype:
"int16" - signed 2-byte (1 register) integer
"uint16" - usigned 2-byte (1 register) integer
"int16m" - signed 2-byte (1 register) integer, force multiple write
"uint16m" - usigned 2-byte (1 register) integer, force multiple write
"float16" - 2-byte floating point (KNX format, used in some HVAC units)
"int32" - signed 4-byte (2 registers) integer
"uint32" - unsigned 4-byte (2 registers) integer
"float32" - 4-byte (2 registers) floating point (IEEE 754)
"int64" - signed 8-byte (4 registers) integer
"uint64" - unsigned 8-byte (4 registers) integer
"float64" - 8-byte (4 registers) floating point (IEEE 754)
Optionally, it`s possible to swap register/byte order
Default value is word (2-byte) swap
Possible string values: n (no swap), w (word swap), b (byte swap), bw (byte and word swap)
Returns number of values written on success and nil, error description on error
mb:reportslaveid()
Reads slave internal data
Returns values on success and nil, error description on error