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

- Main Page
- Modules
- Data Structures
- Files

Functions
ModbusTCPMaster
Library » ModbusMaster

## Functions
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Open (UINT8 ipAddress[], UINT16 tcpPort, UINT32 cTimeoutMs, UINT32 *sHandle)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Close (UINT32 sHandle)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Ioctl (UINT32 sHandle, UINT8 unitId, UINT32 rwTimeoutMs)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Read_Coils (UINT32 sHandle, UINT16 startAddr, UINT16 coilCount, UINT8 byteCoils[], UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Write_Coils (UINT32 sHandle, UINT16 startAddr, UINT16 coilCount, UINT8 byteCoils[], UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Write_Coil (UINT32 sHandle, UINT16 addr, UINT8 coil, UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Read_Discrete_Inputs (UINT32 sHandle, UINT16 startAddr, UINT16 coilCount, UINT8 byteCoils[], UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Read_Input_Regs (UINT32 sHandle, UINT16 startAddr, UINT16 regCount, UINT16 regs[], UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Read_Holding_Regs (UINT32 sHandle, UINT16 startAddr, UINT16 regCount, UINT16 regs[], UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Write_Holding_Regs (UINT32 sHandle, UINT16 startAddr, UINT16 regCount, UINT16 regs[], UINT8 *exceptionCode)
MODBUS_MASTER_ERR_CODE | MX_RTU_Modbus_Tcp_Master_Write_Holding_Reg (UINT32 sHandle, UINT16 addr, UINT16 regValue, UINT8 *exceptionCode)

## Detailed Description

Sample Code:
modbus_tcp_master.c

## Function Documentation

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Open | ( | UINT8 | ipAddress[],
|  | UINT16 | tcpPort,
|  | UINT32 | cTimeoutMs,
|  | UINT32 * | sHandle
| ) |  |

Parameters

  [in] | ipAddress | IP of Modbus TCP Slave.
  [in] | tcpPort | Port of Modbus TCP Slave.
  [in] | cTimeoutMs | Modbus TCP connecting timeout in milliseconds.
  [out] | sHandle | A handle, like a file descriptor, stands for the connection.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Close | ( | UINT32 | sHandle | ) |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Ioctl | ( | UINT32 | sHandle,
|  | UINT8 | unitId,
|  | UINT32 | rwTimeoutMs
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [in] | unitId | Unit ID from 0x0 to 0xffff, Unit ID is not 0 when the Modbus TCP Slave is a gateway.
  [in] | rwTimeoutMs | Modbus TCP RW timeout in milliseconds.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Read_Coils | ( | UINT32 | sHandle,
|  | UINT16 | startAddr,
|  | UINT16 | coilCount,
|  | UINT8 | byteCoils[],
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [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 TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Write_Coils | ( | UINT32 | sHandle,
|  | UINT16 | startAddr,
|  | UINT16 | coilCount,
|  | UINT8 | byteCoils[],
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [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 TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Write_Coil | ( | UINT32 | sHandle,
|  | UINT16 | addr,
|  | UINT8 | coil,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [in] | addr | Modbus Address from 0x0 to 0xffff.
  [in] | coil | Written Data to Modbus TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Read_Discrete_Inputs | ( | UINT32 | sHandle,
|  | UINT16 | startAddr,
|  | UINT16 | coilCount,
|  | UINT8 | byteCoils[],
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [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 TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Read_Input_Regs | ( | UINT32 | sHandle,
|  | UINT16 | startAddr,
|  | UINT16 | regCount,
|  | UINT16 | regs[],
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [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 TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Read_Holding_Regs | ( | UINT32 | sHandle,
|  | UINT16 | startAddr,
|  | UINT16 | regCount,
|  | UINT16 | regs[],
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [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 TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Write_Holding_Regs | ( | UINT32 | sHandle,
|  | UINT16 | startAddr,
|  | UINT16 | regCount,
|  | UINT16 | regs[],
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [in] | startAddr | Modbus Address from 0x0 to 0xffff.
  [in] | regCount | The amount of holding registers will be written from Start Address.
  [in] | regs | Written Data to Modbus TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE

MODBUS_MASTER_ERR_CODE MX_RTU_Modbus_Tcp_Master_Write_Holding_Reg | ( | UINT32 | sHandle,
|  | UINT16 | addr,
|  | UINT16 | regValue,
|  | UINT8 * | exceptionCode
| ) |  |

Parameters

  [in] | sHandle | A handle, like a file descriptor, stands for the connection.
  [in] | addr | Modbus Address from 0x0 to 0xffff.
  [in] | regValue | Written Data to Modbus TCP Slave.

Returns
  MODBUS_MASTER_ERR_CODE