Difference between revisions of "Function modbusWriteSingleRegister()"
Jump to navigation
Jump to search
(Created page with "{{DISPLAYTITLE:function modbusWriteSingleRegister()}} Write value from to single register using modbus protocol. The call is asynchronous: the code execution proceeds immediat...") |
|||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:function modbusWriteSingleRegister()}} | {{DISPLAYTITLE:function modbusWriteSingleRegister()}} | ||
| − | Write value | + | Write value to single register using modbus protocol. The call is asynchronous: the code execution proceeds immediately and when the response arrives, callback function is called. |
<i>nil</i> <b>modbusWriteSingleRegister</b>(<i>table</i> <code>config</code>) | <i>nil</i> <b>modbusWriteSingleRegister</b>(<i>table</i> <code>config</code>) | ||
| Line 15: | Line 15: | ||
=== Callback Parameters === | === Callback Parameters === | ||
| − | <i>table</i> response{<code>result</code>, <code>errInfo</code>, <code>address | + | <i>table</i> response{<code>result</code>, <code>errInfo</code>, <code>address</code>} |
* <i>number</i> <code>result</code> error code of the response (0 is success) | * <i>number</i> <code>result</code> error code of the response (0 is success) | ||
* <i>string</i> <code>errInfo</code> error description (if result>0) | * <i>string</i> <code>errInfo</code> error description (if result>0) | ||
Latest revision as of 14:08, 20 June 2019
Write value to single register using modbus protocol. The call is asynchronous: the code execution proceeds immediately and when the response arrives, callback function is called.
nil modbusWriteSingleRegister(table config)
Parameters
table config{deviceAddress, callback, address, value, port, timeout}
- string
deviceAddressIP address of device - function{response}
callbackthis function is called when response arrives - string
addressnumber of the register - number
valuethe value to be written - optional number
portnumer of port (default 502) - optional number
timeoutmaximum seconds to wait for response (default 30)
Callback Parameters
table response{result, errInfo, address}
- number
resulterror code of the response (0 is success) - string
errInfoerror description (if result>0) - number
addressnumber of the input register
Return value
nil
Usage
-- Switch state of 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
modbusWriteSingleRegister{deviceAddress='10.0.0.105', port=505, timeout=6, address=i, value=4, callback=modbusWriteCallback}
end
Requirements
Netio FirmWare 3.3.0+