function modbusWriteSingleCoil()
Jump to navigation
Jump to search
Write value to single coil using modbus protocol. The call is asynchronous: the code execution proceeds immediately and when the response arrives, callback function is called.
nil modbusWriteSingleCoil(table config
)
Parameters
table config{deviceAddress
,callback
,address
,value
,port
,timeout
}
- string
deviceAddress
IP address of device - function{response}
callback
this function is called when response arrives - string
address
number of the coil - boolean
value
the value to be written - optional number
port
numer of port (default 502) - optional number
timeout
maximum seconds to wait for response (default 30)
Callback Parameters
table response{result
,errInfo
,address
}
- number
result
error code of the response (0 is success) - string
errInfo
error description (if result>0) - number
address
number of the input register
Return value
nil
Usage
-- Turn on all outputs on NETIO with IP 10.0.0.105 and port 505 local function modbusWriteCallback(data) log(string.format("addr %d, result %d", data.address, data.result)) end for i = 101,104 do modbusWriteSingleCoil{deviceAddress='10.0.0.105', port=505, timeout=6, address=true, value=4, callback=modbusWriteCallback} end
Requirements
Netio FirmWare 3.3.0+