Difference between revisions of "Function modbusReadInputRegister()"

From wiki.netio-products.com
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:function modbusReadInputRegister()}} Read value from single input register using modbus protocol. The call is asynchronous: the code execution proceeds immediat...")
 
 
Line 24: Line 24:
  
 
=== Usage ===
 
=== Usage ===
  -- Read value about voltage (*10) from NETIO with IP address 10.0.0.105 and port 505
+
  -- Read value of voltage (*10) from NETIO with IP address 10.0.0.105 and port 505
 
  function modbusReadCallback(data)
 
  function modbusReadCallback(data)
 
   if data.result == 0 then
 
   if data.result == 0 then

Latest revision as of 13:57, 20 June 2019

Read value from single input register using modbus protocol. The call is asynchronous: the code execution proceeds immediately and when the response arrives, callback function is called.

nil modbusReadInputRegister(table config)

Parameters

table config{deviceAddress, callback, address,port, timeout}
  • string deviceAddress IP address of device
  • function{response} callback this function is called when response arrives
  • string address number of the input register
  • 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, value}
  • number result error code of the response (0 is success)
  • string errInfo error description (if result>0)
  • number address number of the input register
  • string value value of the input register

Return value

nil

Usage

-- Read value of voltage (*10) from NETIO with IP address 10.0.0.105 and 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

modbusReadInputRegister{deviceAddress='10.0.0.105', port=505, timeout=6, address=1, callback=modbusReadCallback}

Requirements

Netio FirmWare 3.3.0+