|
|
|
|
ModbusConnectTCP (Function) In french: ModbusConnecteTCP Connects a client to a Modbus server via transmission control protocol (TCP). New in version 2024
Session is modbusSession
Session = ModbusConnectTCP("192.168.1.18",3275)
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
ELSE
ModbusWriteRegister(Session, 0x42,0xCAFE)
END
ModbusDisconnect(Session)
Syntax
<Session> = ModbusConnectTCP(<Address> [, <Port> [, <Slave ID> [, <Connection timeout>]]])
<Session>: modbusSession variable modbusSession variable used to communicate with the Modbus server. <Address>: Character string Modbus server address. This address can correspond to: - an IPv4 or IPv6 address,
- a domain name (e.g., "modbusserver.com").
<Port>: Optional integer Port number to be used for the TCP connection. By default, this parameter is set to 502, the standard port for Modbus TCP. <Slave ID>: Optional integer Number between 0 and 255 that indicates which slave to connect to if it is behind a gateway (e.g., a Modbus TCP to Modbus RTU gateway). By default, this parameter is set to 255 (broadcast address). <Connection timeout>: Optional integer Timeout for connecting to the Modbus server, expressed in milliseconds. This parameter can be: - an integer corresponding to the number of milliseconds,
- a Duration variable,
- the duration in a readable format (e.g., 20s or 10 ms).
Remarks - After calling ModbusConnectTCP, it is recommended to check the ErrorOccurred variable to make sure there are no errors.
- ModbusConnectTCP blocks the application until a connection is established or the connection timeout is exceeded.
- The slave identifier is in the modbusSession variable. If an operation is to be performed on several different slaves, you can change the slave identifier in the modbusSession variable to avoid reopening the session.
Business / UI classification: Business Logic
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|