Function
Specifies the IP address and port of the slave device to communicate with, and initializes it as Modbus/TCP.
Format
ctx = modbus_new_tcp( ip , port )
Parameters
ip [ C : char * ] [ Python : ctypes.c_char_p]
Specify the IP address of the Modbus slave to communicate with.
port [ C : int ] [ Python : ctypes.POINTER(ctypes.c_int)]
Specify the port to use.
To use the default(502), specify 'MODBUS_TCP_DEFAULT_PORT'.
Return values
ctx [ C : modbus_t * ] [ Python : ctypes.POINTER(modbus_t) ]
If the function succeeds, the pointer address of the modbus_t structure is returned.
If the function fails, NULL is returned. The following error is stored in errno.
Definition |
Description |
EINVAL |
IP address is invalid. |
ENOMEM |
Memory is insufficient. |
Remarks
Specifies the IP and port of the slave device to be connected, and initialize it as Modbus/TCP.
Example
The following is an example of communicating with a Modbus slave.
IP address : 192.168.1.102
Port to use : 502
C |
modbus_t *ctx; ctx = modbus_new_tcp("192.168.1.102", 502); |
Python |
ctx = ctypes.POINTER(modbus_t) ctx = modbus_tcp.modbus_new_tcp("192.168.1.102", 502) |