# ================================================================
# modbus_tcp.py
# module file for libmodbus
#                                                CONTEC.Co., Ltd.
# ================================================================
import ctypes
import ctypes.wintypes
import modbus

modbus_dll = ctypes.cdll.LoadLibrary('modbus.dll')

modbus_t = modbus.struct__modbus

# ----------------------------------------
# Prototype definition
# ----------------------------------------
# ----------------------------------------
# ModbusTCP function
# ----------------------------------------
# C Prototype: MODBUS_API modbus_t* modbus_new_tcp(const char *ip_address, int port)
modbus_new_tcp = modbus_dll.modbus_new_tcp
modbus_new_tcp.argtypes = [ctypes.c_char_p, ctypes.c_int]
modbus_new_tcp.restype = ctypes.POINTER(modbus_t)

# ----------------------------------------
# Parameters
# ----------------------------------------
# ----------------------------------------
# ModbusTCP Port Number
# ----------------------------------------
MODBUS_TCP_DEFAULT_PORT = 502
# ----------------------------------------
# ModbusTCP Slave Id
# ----------------------------------------
MODBUS_TCP_SLAVE = 255
# ----------------------------------------
# TCP MODBUS ADU
# ----------------------------------------
# Modbus_Application_Protocol_V1_1b.pdf Chapter 4 Section 1 Page 5
# 253 bytes + MBAP (7 bytes) = 260 bytes
MODBUS_TCP_MAX_ADU_LENGTH = 260
