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

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Functions
ModbusRTUMaster
Library » ModbusMaster

## Data Structures
struct | TTY_PARAM

## Functions
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Open (UINT8 slot, SERIAL_PORT port, TTY_PARAM *param)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Close (UINT8 slot, SERIAL_PORT port)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Read_Coils (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 startAddr, UINT16 coilCount, UINT8 byteCoils[], UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Write_Coils (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 startAddr, UINT16 coilCount, UINT8 byteCoils[], UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Write_Coil (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 addr, UINT8 coil, UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Read_Discrete_Inputs (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 startAddr, UINT16 coilCount, UINT8 byteCoils[], UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Read_Input_Regs (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 startAddr, UINT16 regCount, UINT16 regs[], UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Read_Holding_Regs (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 startAddr, UINT16 regCount, UINT16 regs[], UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Write_Holding_Regs (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 startAddr, UINT16 regCount, UINT16 regs[], UINT32 timeoutMs, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Rtu_Master_Write_Holding_Reg (UINT8 slot, SERIAL_PORT port, UINT8 unitId, UINT16 addr, UINT16 reg, UINT32 timeoutMs, UINT8 *exceptionCode)

## Detailed Description

Sample Code:
modbus_rtu_master.c

## Function Documentation

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Open | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | TTY_PARAM * | param
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | param | Serial settings, e.g., baud rate, parity, flow control, etc.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Close | ( | UINT8 | slot,
|  | SERIAL_PORT | port
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Read_Coils | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | startAddr,
|  | UINT16 | coilCount,
|  | UINT8 | byteCoils[],
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | coilCount | The amount of coils to be read from Start Address.
  [out] | byteCoils | Read Data from Modbus RTU Slave.
  [in] | timeoutMs | Coils read timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Write_Coils | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | startAddr,
|  | UINT16 | coilCount,
|  | UINT8 | byteCoils[],
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | coilCount | The amount of coils to be written from Start Address.
  [in] | byteCoils | Written Data to Modbus RTU Slave.
  [in] | timeoutMs | Coils write timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Write_Coil | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | addr,
|  | UINT8 | coil,
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | addr | Modbus Address from 0x0 to 0xffff.
  [in] | coil | Written Data to Modbus RTU Slave.
  [in] | timeoutMs | A Coil write timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Read_Discrete_Inputs | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | startAddr,
|  | UINT16 | coilCount,
|  | UINT8 | byteCoils[],
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | coilCount | The amount of discrete inputs to be read from Start Address.
  [out] | byteCoils | Read Data from Modbus RTU Slave.
  [in] | timeoutMs | Discrete inputs read timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Read_Input_Regs | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | startAddr,
|  | UINT16 | regCount,
|  | UINT16 | regs[],
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Port 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | regCount | The amount of input registers to be read from Start Address.
  [out] | regs | Read Data from Modbus RTU Slave.
  [in] | timeoutMs | Input registers read timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Read_Holding_Regs | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | startAddr,
|  | UINT16 | regCount,
|  | UINT16 | regs[],
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | regCount | The amount of holding registers to be read from Start Address.
  [out] | regs | Read Data from Modbus RTU Slave.
  [in] | timeoutMs | Holding registers read timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Write_Holding_Regs | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | startAddr,
|  | UINT16 | regCount,
|  | UINT16 | regs[],
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | regCount | The amount of holding registers to be written from Start Address.
  [in] | regs | Written Data to Modbus RTU Slave.
  [in] | timeoutMs | Holding registers write timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Rtu_Master_Write_Holding_Reg | ( | UINT8 | slot,
|  | SERIAL_PORT | port,
|  | UINT8 | unitId,
|  | UINT16 | addr,
|  | UINT16 | reg,
|  | UINT32 | timeoutMs,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | slot | Slot 0: Built-in COM Ports, Slots 1 ~ 12: Expansion COM Ports.
  [in] | port | Ports 0 ~ 3.
  [in] | unitId | Unit ID from 0x0 to 0xffff.
  [in] | addr | Modbus Address from 0x0 to 0xffff.
  [in] | reg | Written Data to Modbus RTU Slave.
  [in] | timeoutMs | A Holding Register write timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE