| ioPAC RTU Controllers C/C++ Sample Code Programming Guide

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Functions
ModbusTCPSlave
Library » ModbusSlave

## Data Structures
struct | Modbus_TCP_Master_Connection_Info

## 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

## 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] | 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.

Returns
  MODBUS_SLAVE_ERR_CODE

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Unregister | ( | UINT32 | sHandle | ) |

Parameters

  [in] | sHandle | A 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] | sHandle | A 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] | sHandle | A 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] | sHandle | A handle, like a file descriptor, stands for the listening port.
  [in] | map_type | Please refer to ModbusSlaveMapType .
  [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.

Returns
  MODBUS_SLAVE_ERR_CODE

Note
  RW Callback's return code: ModbusSlaveReturnCode .

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Tcp_Slave_Delete_Entry | ( | UINT32 | sHandle,
|  | UINT8 | map_type,
|  | UINT16 | address
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the listening port.
  [in] | map_type | Please refer to ModbusSlaveMapType .
  [in] | address | Modbus 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] | sHandle | A handle, like a file descriptor, stands for the listening port.
  [out] | count | The 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] | sHandle | A 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] | sHandle | A handle, like a file descriptor, stands for the listening port.
  [out] | connection_info | Connection Information of Modbus TCP Masters which are connecting.

Returns
  MODBUS_SLAVE_ERR_CODE