Difference between revisions of "Function modbusReadCoil()"
Jump to navigation
Jump to search
(Created page with "{{DISPLAYTITLE:function modbusReadCoil()}} Read value from single coil using modbus protocol. The call is asynchronous: the code execution proceeds immediately and when the re...") |
|||
| Line 25: | Line 25: | ||
=== Usage === | === Usage === | ||
-- Read value of all outputs from NETIO with IP 10.0.0.105 on port 505 | -- Read value of all outputs from NETIO with IP 10.0.0.105 on port 505 | ||
| − | + | function modbusReadCallback(data) | |
if data.result == 0 then | if data.result == 0 then | ||
log(string.format("modbus addr %d, got %s", data.address, tostring(data.value))) | log(string.format("modbus addr %d, got %s", data.address, tostring(data.value))) | ||
Latest revision as of 13:45, 20 June 2019
Read value from single coil using modbus protocol. The call is asynchronous: the code execution proceeds immediately and when the response arrives, callback function is called.
nil modbusReadCoil(table config)
Parameters
table config{deviceAddress, callback, address,port, timeout}
- string
deviceAddressIP address of device - function{response}
callbackthis function is called when response arrives - string
addressnumber of the coil - optional number
portnumer of port (default 502) - optional number
timeoutmaximum seconds to wait for response (default 30)
Callback Parameters
table response{result, errInfo, address, value}
- number
resulterror code of the response (0 is success) - string
errInfoerror description (if result>0) - number
addressnumber of the coil - boolean
valuevalue of the coil
Return value
nil
Usage
-- Read value of all outputs from NETIO with IP 10.0.0.105 on port 505
function modbusReadCallback(data)
if data.result == 0 then
log(string.format("modbus addr %d, got %s", data.address, tostring(data.value)))
else
log(string.format("modbus coil addr %d failed with error %d: %s", data.address, data.result, data.errorInfo))
end
end
for i = 101,104 do
modbusReadCoil{deviceAddress='10.0.0.105', port=505, timeout=6, address=i, callback=modbusReadCallback}
end
Requirements
Netio FirmWare 3.3.0+