ioPAC RTU Controllers
C/C++ Sample Code Programming Guide
|
Modules | |
ModbusTCPSlaveExceptionCode | |
ModbusTCPSlaveReturnCode | |
ModbusTCPSlaveFunctionCode | |
ModbusTCPSlaveMapType | |
Data Structures | |
struct | Modbus_TCP_Master_Connection_Info |
Macros | |
#define | MAKE_WORD(a, b) (((UINT16)a<<8) +(UINT16)b) |
#define | pfnModbusRead int (*pfnModRead)(UINT8 *pData, UINT16 nth, void *pUserData) |
#define | pfnModbusWrite int (*pfnModWrite)(UINT8 *pData, UINT16 nth, void *pUserData) |
#define | MODBUS_LISTEN_PORTS 1 |
#define | MODBUS_MAX_CONNECTION 10 |
#define | MODBUS_MAX_MAP_SIZE 500 |
#define | MODBUS_MIN_IDLE_TIMEOUT_SECOND 10 |
Sample Code:
modbus_tcp_slave.c
#define MODBUS_LISTEN_PORTS 1 |
#define MODBUS_MAX_CONNECTION 10 |
#define MODBUS_MAX_MAP_SIZE 500 |
#define MODBUS_MIN_IDLE_TIMEOUT_SECOND 10 |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Init | ( | ) |
This API must be called at first.
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Uninit | ( | ) |
This API must be called at the end.
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Register | ( | UINT16 | port, |
UINT16 | map_size, | ||
UINT32 | idle_timeout_second, | ||
UINT32 * | sHandle | ||
) |
[in] | port | TCP/IP listening port. |
[in] | map_size | The amount of entries for each Map Type, Maximum Map Size is MODBUS_MAX_MAP_SIZE . |
[in] | idle_timeout_second | Modbus TCP Slave will stop the connection if a master idled over N seconds, Minimum Idle Timeout is MODBUS_MIN_IDLE_TIMEOUT_SECOND . |
[out] | sHandle | A handle, like a file descriptor, stands for the listening port. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Unregister | ( | UINT32 | sHandle | ) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Start | ( | UINT32 | sHandle | ) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Stop | ( | UINT32 | sHandle | ) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Add_Entry | ( | UINT32 | sHandle, |
UINT8 | map_type, | ||
UINT16 | address, | ||
void * | pUserData, | ||
pfnModbusRead | , | ||
pfnModbusWrite | |||
) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
[in] | map_type | Please refer to ModbusTCPSlaveMapType . |
[in] | address | Modbus Address from 0x0 to 0xffff. |
[in] | pUserData | User Date for RW Callback. |
[in] | pfnModbusRead | Read Callback of the modbus address. |
[in] | pfnModbusWrite | Write Callback of the modbus address. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Delete_Entry | ( | UINT32 | sHandle, |
UINT8 | map_type, | ||
UINT16 | address | ||
) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
[in] | map_type | Please refer to ModbusTCPSlaveMapType . |
[in] | address | Modbus Address from 0x0 to 0xffff, this address must be added already. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Map_Count | ( | UINT32 | sHandle, |
UINT16 * | count | ||
) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
[out] | count | The amount of entries are added. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Map_Dump | ( | UINT32 | sHandle | ) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Connection_Info | ( | UINT32 | sHandle, |
struct Modbus_TCP_Master_Connection_Info * | connection_info | ||
) |
[in] | sHandle | A handle, like a file descriptor, stands for the listening port. |
[out] | connection_info | Connection Information of Modbus TCP Masters which are connecting. |