TeleBoss 850 2.06.280_STD User Manual
Page 185
Returns
If successful, returns Lua string containing register values as an array. If not successful, returns nil plus a string
containing an error message.
Note:
The serial port device must already be set to the required baud rate and data format.
Example
-- read a 32-bit unsigned integer (assumes high-word first, high-byte first)
v, error = a_lib.MODBUSReadRegisters(handle, address, register, 2)
if v ~= nil then
value = (string.byte(v, 1) * 0x1000000) + (string.byte(v, 2) * 0x10000) +
(string.byte(v, 3) * 0x100) + string.byte(v, 4)
end
-- read a 16-bit signed integer (assumes high-word first, high-byte first)
v, error = a_lib.MODBUSReadRegisters(handle, address, register, 1)
if v ~= nil then
-- get unsigned value
value = (string.byte(v, 1) * 0x100) + string.byte(v, 2)
-- adjust if negative
if (value >= 0x8000) then
value = -(0x8000 - (value - 0x8000))
end
end
-- read a string that is stored in 8 16-bit registers
v = a_lib.MODBUSReadRegisters(handle, address, register, 8)
-- print the string
print(v)
Blahblahblah
-- print the string length (this corresponds to registers * 2, regardless of
ASCIIZ length)
print(#v)
16
a_lib.MODBUSWriteRegisterSingle
Description
Write a value to a single 16-bit register on a MODBUS device.
Syntax
a_lib.MODBUSWriteRegisterSingle(handle, address, register, value)
handle: The handle obtained when the serial port device was opened
address: Address of the Modbus device (1-63)
register: The register on the Modbus device to write to
value: Lua string containing value as byte array
Returns
Returns 1 if successful, otherwise returns nil plus a string containing an error message.
Note:
The serial port device must already be set to the required baud rate and data format.
Summary of Contents for Teleboss 850
Page 6: ......