ModbusTcpClient¶
Description¶
The ModbusTcpClient object implements a Modbus TCP client which communicates with Modbus slaves (servers) via TCP network connections.
› Inherits: | ModbusClient |
---|
Properties¶
lowDelay¶
This property holds whether to optimize the underlying TCP/IP socket for low latency by setting the TCP_NODELAY
option and disabling Nagle’s algorithm.
This property was introduced in InCore 2.5.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | lowDelayChanged() |
› Attributes: | Writable |
networkAddress¶
This property holds the host address of the Modbus TCP server which to connect to.
› Type: | String |
---|---|
› Default: | 127.0.0.1 |
› Signal: | networkAddressChanged() |
› Attributes: | Writable |
networkPort¶
This property holds the network port of the Modbus TCP server which to connect to.
› Type: | SignedInteger |
---|---|
› Default: | 502 |
› Signal: | networkPortChanged() |
› Attributes: | Writable |
Example¶
import InCore.Foundation 2.5
import InCore.Modbus 2.5
Application {
name: "Modbus TCP client example"
ModbusTcpClient {
// set address to connect to
networkAddress: "192.168.10.19"
// change retry and timeout configuration
numberOfRetries: 1
timeout: 500
ModbusSlave {
address: 1
// define Modbus register for temperature
ModbusRegister {
id: temperature
type: ModbusRegister.Input
address: 1
onDataChanged: console.log("Temperature", data)
}
// define special Modbus register device name stored as string
ModbusRegister {
type: ModbusRegister.Holding
address: 0x1000
count: 8
dataType: ModbusRegister.String
onDataChanged: console.log("Device name", data)
}
// read all registers every 50 ms
Polling on registers { interval: 50 }
}
// print information message when connected
onConnected: console.log("Connected to Modbus TCP slave")
// print error message if something goes wrong
onErrorOccurred: console.log(errorString)
}
}