ioPAC RTU Controllers
C/C++ Sample Code Programming Guide
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Modules | Data Structures | Macros | Enumerations | Functions
ModbusTCPSlave

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
 

Enumerations

enum  MODBUS_SLAVE_ERR_CODE {
  MODBUS_SLAVE_ERR_OK = 0, MODBUS_SLAVE_ERR_ADDRESS, MODBUS_SLAVE_ERR_ADDRESS_COLLISION, MODBUS_SLAVE_ERR_BIND,
  MODBUS_SLAVE_ERR_CREATE_SOCKET, MODBUS_SLAVE_ERR_CREATE_THREAD, MODBUS_SLAVE_ERR_EXCEPTION, MODBUS_SLAVE_ERR_EXCEED_MAP_SIZE,
  MODBUS_SLAVE_ERR_FUNCTION, MODBUS_SLAVE_ERR_ILLEGAL_HANDLE, MODBUS_SLAVE_ERR_IDLE_TIMEOUT, MODBUS_SLAVE_ERR_ILLEGAL_ACTION,
  MODBUS_SLAVE_ERR_LISTEN, MODBUS_SLAVE_ERR_LISTEN_PORT_OVERFLOW, MODBUS_SLAVE_ERR_MAP_TYPE, MODBUS_SLAVE_ERR_MAP_EMPTY,
  MODBUS_SLAVE_ERR_MEMORY_LEAK, MODBUS_SLAVE_ERR_NO_START, MODBUS_SLAVE_ERR_NO_REGISTER, MODBUS_SLAVE_ERR_PORT_LISTENING,
  MODBUS_SLAVE_ERR_REGISTERED_PORT, MODBUS_SLAVE_ERR_SIZE, MODBUS_SLAVE_ERR_SYSTEM_TIMEOUT, MODBUS_SLAVE_ERR_SET_SOCKET_MODE,
  MODBUS_SLAVE_ERR_SET_SOCKET_OPTION, MODBUS_SLAVE_ERR_NO_CONNECTIONS, MODBUS_SLAVE_ERR_SYSTEM_INFO, MODBUS_SLAVE_ERR_AMOUNT
}
 

Functions

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Init ()
 This API must be called at first. More...
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Uninit ()
 This API must be called at the end. More...
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Register (UINT16 port, UINT16 map_size, UINT32 idle_timeout_second, UINT32 *sHandle)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Unregister (UINT32 sHandle)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Start (UINT32 sHandle)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Stop (UINT32 sHandle)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Add_Entry (UINT32 sHandle, UINT8 map_type, UINT16 address, void *pUserData, pfnModbusRead, pfnModbusWrite)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Delete_Entry (UINT32 sHandle, UINT8 map_type, UINT16 address)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Map_Count (UINT32 sHandle, UINT16 *count)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Map_Dump (UINT32 sHandle)
 
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Connection_Info (UINT32 sHandle, struct Modbus_TCP_Master_Connection_Info *connection_info)
 

Detailed Description

Sample Code:
modbus_tcp_slave.c

Macro Definition Documentation

#define MAKE_WORD (   a,
 
)    (((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

Enumeration Type Documentation

Enumerator
MODBUS_SLAVE_ERR_OK 

0

MODBUS_SLAVE_ERR_ADDRESS 

1

MODBUS_SLAVE_ERR_ADDRESS_COLLISION 

2

MODBUS_SLAVE_ERR_BIND 

3

MODBUS_SLAVE_ERR_CREATE_SOCKET 

4

MODBUS_SLAVE_ERR_CREATE_THREAD 

5

MODBUS_SLAVE_ERR_EXCEPTION 

6

MODBUS_SLAVE_ERR_EXCEED_MAP_SIZE 

7

MODBUS_SLAVE_ERR_FUNCTION 

8

MODBUS_SLAVE_ERR_ILLEGAL_HANDLE 

9

MODBUS_SLAVE_ERR_IDLE_TIMEOUT 

10

MODBUS_SLAVE_ERR_ILLEGAL_ACTION 

11

MODBUS_SLAVE_ERR_LISTEN 

12

MODBUS_SLAVE_ERR_LISTEN_PORT_OVERFLOW 

13

MODBUS_SLAVE_ERR_MAP_TYPE 

14

MODBUS_SLAVE_ERR_MAP_EMPTY 

15

MODBUS_SLAVE_ERR_MEMORY_LEAK 

16

MODBUS_SLAVE_ERR_NO_START 

17

MODBUS_SLAVE_ERR_NO_REGISTER 

18

MODBUS_SLAVE_ERR_PORT_LISTENING 

19

MODBUS_SLAVE_ERR_REGISTERED_PORT 

20

MODBUS_SLAVE_ERR_SIZE 

21

MODBUS_SLAVE_ERR_SYSTEM_TIMEOUT 

22

MODBUS_SLAVE_ERR_SET_SOCKET_MODE 

23

MODBUS_SLAVE_ERR_SET_SOCKET_OPTION 

24

MODBUS_SLAVE_ERR_NO_CONNECTIONS 

25

MODBUS_SLAVE_ERR_SYSTEM_INFO 

26

MODBUS_SLAVE_ERR_AMOUNT 

27

Function Documentation

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Init ( )

This API must be called at first.

Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Uninit ( )

This API must be called at the end.

Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Register ( UINT16  port,
UINT16  map_size,
UINT32  idle_timeout_second,
UINT32 sHandle 
)
Parameters
[in]portTCP/IP listening port.
[in]map_sizeThe amount of entries for each Map Type, Maximum Map Size is MODBUS_MAX_MAP_SIZE .
[in]idle_timeout_secondModbus TCP Slave will stop the connection if a master idled over N seconds, Minimum Idle Timeout is MODBUS_MIN_IDLE_TIMEOUT_SECOND .
[out]sHandleA handle, like a file descriptor, stands for the listening port.
Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Unregister ( UINT32  sHandle)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Start ( UINT32  sHandle)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
Returns
MODBUS_SLAVE_ERR_CODE
Note
This function must be called to start listening the port after calling MX_RTU_Modbus_Tcp_Slave_Register .
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Stop ( UINT32  sHandle)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
Returns
MODBUS_SLAVE_ERR_CODE
Note
This function must be called to stop listening the port before calling MX_RTU_Modbus_Tcp_Slave_Unregister .
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Add_Entry ( UINT32  sHandle,
UINT8  map_type,
UINT16  address,
void *  pUserData,
pfnModbusRead  ,
pfnModbusWrite   
)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
[in]map_typePlease refer to ModbusTCPSlaveMapType .
[in]addressModbus Address from 0x0 to 0xffff.
[in]pUserDataUser Date for RW Callback.
[in]pfnModbusReadRead Callback of the modbus address.
[in]pfnModbusWriteWrite Callback of the modbus address.
Returns
MODBUS_SLAVE_ERR_CODE
Note
RW Callback's return code: ModbusTCPSlaveReturnCode .
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Delete_Entry ( UINT32  sHandle,
UINT8  map_type,
UINT16  address 
)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
[in]map_typePlease refer to ModbusTCPSlaveMapType .
[in]addressModbus Address from 0x0 to 0xffff, this address must be added already.
Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Map_Count ( UINT32  sHandle,
UINT16 count 
)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
[out]countThe amount of entries are added.
Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Map_Dump ( UINT32  sHandle)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
Returns
MODBUS_SLAVE_ERR_CODE
MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Connection_Info ( UINT32  sHandle,
struct Modbus_TCP_Master_Connection_Info connection_info 
)
Parameters
[in]sHandleA handle, like a file descriptor, stands for the listening port.
[out]connection_infoConnection Information of Modbus TCP Masters which are connecting.
Returns
MODBUS_SLAVE_ERR_CODE