ModbusTcpServer¶
Description¶
The ModbusTcpServer object implements a Modbus server which communicates with Modbus masters (clients) via TCP network connections.
This object was introduced in InCore 2.0.
› Inherits: | ModbusServer |
---|
Properties¶
networkAddress¶
This property holds the local network address which to listen on for incoming connections. When set to 0.0.0.0
the server will listen on all addresses/interfaces.
› Type: | String |
---|---|
› Default: | 0.0.0.0 |
› Signal: | networkAddressChanged() |
› Attributes: | Writable |
networkPort¶
This property holds the network port which to listen on for incoming connections.
› Type: | SignedInteger |
---|---|
› Default: | 502 |
› Signal: | networkPortChanged() |
› Attributes: | Writable |
Example¶
import InCore.Foundation 2.5
import InCore.Modbus 2.5
Application {
name: "Modbus TCP server/client example"
Counter {
id: counter
running: counterEnabledReg.data
startValue: 123
}
ModbusTcpServer {
id: server
address: 1
networkPort: 1234
networkAddress: "localhost"
// expose 3 values at addresses 2…4 through one register definition
ModbusRegister {
type: ModbusRegister.Input
address: 2
count: 3
data: [ 123, 456, 789 ]
}
ModbusRegister {
id: counterEnabledReg
type: ModbusRegister.Holding
address: 0
data: false
onDataChanged: console.log("Counter enabled:", data)
}
ModbusRegister {
id: counterReg
type: ModbusRegister.Input
address: 123
data: counter.value
}
ModbusRegister {
id: messageReg
type: ModbusRegister.Input
address: 0x1000
count: 6
dataType: ModbusRegister.String
data: "Hello world!"
}
onConnected: console.log("Server accepting connections")
onErrorOccurred: console.log("Server error:", errorString)
}
ModbusTcpClient {
id: client
networkAddress: server.networkAddress
networkPort: server.networkPort
numberOfRetries: 1
timeout: 500
ModbusSlave {
address: server.address
ModbusRegister {
type: counterEnabledReg.type
address: counterEnabledReg.address
data: client.state === ModbusTcpClient.ConnectedState
}
ModbusRegister {
type: counterReg.type
address: counterReg.address
onDataChanged: console.log( "Counter value:", data)
}
ModbusRegister {
type: messageReg.type
address: messageReg.address
count: messageReg.count
dataType: messageReg.dataType
onDataChanged: console.log("Message register content:", data)
}
Polling on registers { interval: 100 }
}
onConnected: console.log("Connected to Modbus TCP slave")
onErrorOccurred: console.log("Client error:", errorString)
}
}