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

- Main Page
- Modules
- Data Structures
- Files

Functions
ModbusRTUSlave
Library » ModbusSlave

## Functions
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Init ()
| This API must be called at first. More...
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Uninit ()
| This API must be called at the end. More...
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Register (UINT8 slot, SERIAL_PORT port, INT32 slaveID, UINT16 map_size, TTY_PARAM *param, UINT32 *handle)
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Unregister (UINT32 handle)
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Start (UINT32 handle)
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Stop (UINT32 handle)
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Add_Entry (UINT32 handle, UINT8 map_type, UINT16 address, void *pUserData, pfnModbusRead, pfnModbusWrite)
MODBUS_SLAVE_ERR_CODE | MX_RTU_Modbus_Rtu_Slave_Delete_Entry (UINT32 handle, UINT8 map_type, UINT16 address)

## Detailed Description

Sample Code:
modbus_rtu_slave.c

## Function Documentation

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Init | ( |  | ) |

This API must be called at first.

Returns
  MODBUS_SLAVE_ERR_CODE

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Uninit | ( |  | ) |

This API must be called at the end.

Returns
  MODBUS_SLAVE_ERR_CODE

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Register | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | INT32 | slaveID,
|  | UINT16 | map_size,
|  | TTY_PARAM * | param,
|  | UINT32 * | handle
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in COM Ports, slot 1 ~ 12: Expansion COM Ports.
  [in] | port | port 0 ~ 3.
  [in] | slaveID | RTU serial port UnitID(ie. Device ID).
  [in] | map_size | The amount of entries for each Map Type, Maximum Map Size is MODBUS_MAX_MAP_SIZE .
  [in] | param | Serial settings, e.g., baud rate, parity, flow control, etc.
  [out] | handle | A handle, like a file descriptor, stands for the rtu port.

Returns
  MODBUS_SLAVE_ERR_CODE

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Unregister | ( | UINT32 | handle | ) |

Parameters

  [in] | handle | A handle, like a file descriptor, stands for the rtu port.
  [in] | slot | slot 0: Built-in COM Ports, slot 1 ~ 12: Expansion COM Ports.
  [in] | port | port 0 ~ 3.

Returns
  MODBUS_SLAVE_ERR_CODE

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Start | ( | UINT32 | handle | ) |

Parameters

  [in] | handle | A handle, like a file descriptor, stands for the rtu port.

Returns
  MODBUS_SLAVE_ERR_CODE

Note
  This function must be called to start listening the rtu port after calling MX_RTU_Modbus_Rtu_Slave_Register .

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Stop | ( | UINT32 | handle | ) |

Parameters

  [in] | handle | A handle, like a file descriptor, stands for the rtu port.

Returns
  MODBUS_SLAVE_ERR_CODE

Note
  This function must be called to stop listening the rtu port before calling MX_RTU_Modbus_Rtu_Slave_Unregister .

MODBUS_SLAVE_ERR_CODE MX_RTU_Modbus_Rtu_Slave_Add_Entry | ( | UINT32 | handle,
|  | UINT8 | map_type,
|  | UINT16 | address,
|  | void * | pUserData,
|  | pfnModbusRead | ,
|  | pfnModbusWrite |
| ) |  |

Parameters

  [in] | handle | A handle, like a file descriptor, stands for the rtu 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_Rtu_Slave_Delete_Entry | ( | UINT32 | handle,
|  | UINT8 | map_type,
|  | UINT16 | address
| ) |  |

Parameters

  [in] | handle | A handle, like a file descriptor, stands for the rtu 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