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

Modules

 SerialMode
 
 SerialBaudRate
 
 SerialDataBits
 
 SerialParity
 
 SerialStopBit
 
 SerialFlowControl
 

Macros

#define MX_RTU_SerialRead   MX_RTU_SerialBlockRead
 
#define SERIAL_MAX_OQUEUE_LENGTH   4095
 

Enumerations

enum  SERIAL_PORT {
  PORT1 = 0, PORT2, PORT3, PORT4,
  PORT5, PORT6, PORT7, PORT8,
  PORT_AMOUNT
}
 
enum  SERIAL_ERR_CODE {
  SERIAL_ERR_OK = 0, SERIAL_ERR_FD, SERIAL_ERR_OPEN, SERIAL_ERR_CLOSE,
  SERIAL_ERR_PARAMETER, SERIAL_ERR_SLOT, SERIAL_ERR_PORT, SERIAL_ERR_READ,
  SERIAL_ERR_WRITE, SERIAL_ERR_IOCTL, SERIAL_ERR_MODE, SERIAL_ERR_ttyUSB,
  SERIAL_ERR_NOT_SUPPORT_PRODUCT, SERIAL_ERR_SYSTEM_INFO, SERIAL_ERR_HOT_PLUG, SERIAL_ERR_FLUSH,
  SERIAL_ERR_AMOUNT
}
 

Functions

SERIAL_ERR_CODE MX_RTU_SerialOpen (UINT8 slot, SERIAL_PORT port)
 
SERIAL_ERR_CODE MX_RTU_SerialWrite (UINT8 slot, SERIAL_PORT port, UINT32 len, UINT8 *str, UINT32 *write_bytes)
 
SERIAL_ERR_CODE MX_RTU_SerialNonBlockRead (UINT8 slot, SERIAL_PORT port, UINT32 len, UINT8 *buf, UINT32 *read_bytes)
 
SERIAL_ERR_CODE MX_RTU_SerialBlockRead (UINT8 slot, SERIAL_PORT port, UINT32 len, UINT8 *buf, UINT32 *read_bytes)
 
SERIAL_ERR_CODE MX_RTU_SerialClose (UINT8 slot, SERIAL_PORT port)
 
SERIAL_ERR_CODE MX_RTU_SerialFlowControl (UINT8 slot, SERIAL_PORT port, UINT8 control)
 
SERIAL_ERR_CODE MX_RTU_SerialSetSpeed (UINT8 slot, SERIAL_PORT port, UINT32 speed)
 
SERIAL_ERR_CODE MX_RTU_SerialSetMode (UINT8 slot, SERIAL_PORT port, UINT8 mode)
 
SERIAL_ERR_CODE MX_RTU_SerialGetMode (UINT8 slot, SERIAL_PORT port, UINT8 *mode)
 
SERIAL_ERR_CODE MX_RTU_SerialSetParam (UINT8 slot, SERIAL_PORT port, UINT8 parity, UINT8 databits, UINT8 stopbit)
 
SERIAL_ERR_CODE MX_RTU_SerialDataInInputQueue (UINT8 slot, SERIAL_PORT port, UINT32 *bytes)
 
SERIAL_ERR_CODE MX_RTU_SerialDataInOutputQueue (UINT8 slot, SERIAL_PORT port, UINT32 *bytes)
 
SERIAL_ERR_CODE MX_RTU_SerialInputQueueFlush (UINT8 slot, SERIAL_PORT port)
 
SERIAL_ERR_CODE MX_RTU_SerialOutputQueueFlush (UINT8 slot, SERIAL_PORT port)
 
SERIAL_ERR_CODE MX_RTU_FindFD (UINT8 slot, SERIAL_PORT port, INT32 *fd)
 

Detailed Description

Sample Code:
serial_echo.c

Macro Definition Documentation

#define MX_RTU_SerialRead   MX_RTU_SerialBlockRead
#define SERIAL_MAX_OQUEUE_LENGTH   4095

Enumeration Type Documentation

Enumerator
PORT1 

0

PORT2 

1

PORT3 

2

PORT4 

3

PORT5 

4

PORT6 

5

PORT7 

6

PORT8 

7

PORT_AMOUNT 

8

Enumerator
SERIAL_ERR_OK 

0

SERIAL_ERR_FD 

1

SERIAL_ERR_OPEN 

2

SERIAL_ERR_CLOSE 

3

SERIAL_ERR_PARAMETER 

4

SERIAL_ERR_SLOT 

5

SERIAL_ERR_PORT 

6

SERIAL_ERR_READ 

7

SERIAL_ERR_WRITE 

8

SERIAL_ERR_IOCTL 

9

SERIAL_ERR_MODE 

10

SERIAL_ERR_ttyUSB 

11

SERIAL_ERR_NOT_SUPPORT_PRODUCT 

12

SERIAL_ERR_SYSTEM_INFO 

13

SERIAL_ERR_HOT_PLUG 

14

SERIAL_ERR_FLUSH 

15

SERIAL_ERR_AMOUNT 

16

Function Documentation

SERIAL_ERR_CODE MX_RTU_SerialOpen ( UINT8  slot,
SERIAL_PORT  port 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialWrite ( UINT8  slot,
SERIAL_PORT  port,
UINT32  len,
UINT8 str,
UINT32 write_bytes 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]lenlength of sent data.
[in]strsent data.
[out]write_byteswritten bytes by serial.
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialNonBlockRead ( UINT8  slot,
SERIAL_PORT  port,
UINT32  len,
UINT8 buf,
UINT32 read_bytes 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]lenlength of received buffer.
[out]bufreceived buffer.
[out]read_bytesreceived bytes by serial.
Returns
SERIAL_ERR_CODE
Note
A non-blocking read will (or at least should) always return immediately, but it might not return any data, if none is available at the moment.
SERIAL_ERR_CODE MX_RTU_SerialBlockRead ( UINT8  slot,
SERIAL_PORT  port,
UINT32  len,
UINT8 buf,
UINT32 read_bytes 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]lenlength of received buffer.
[out]bufreceived buffer.
[out]read_bytesreceived bytes by serial.
Returns
SERIAL_ERR_CODE
Note
A blocking read will wait until there is data available (or a timeout, if any, expires), and then returns from the function call.
SERIAL_ERR_CODE MX_RTU_SerialClose ( UINT8  slot,
SERIAL_PORT  port 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialFlowControl ( UINT8  slot,
SERIAL_PORT  port,
UINT8  control 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]controlSerialFlowControl
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialSetSpeed ( UINT8  slot,
SERIAL_PORT  port,
UINT32  speed 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]speedSerialBaudRate
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialSetMode ( UINT8  slot,
SERIAL_PORT  port,
UINT8  mode 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]modeSerialMode
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialGetMode ( UINT8  slot,
SERIAL_PORT  port,
UINT8 mode 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[out]modeSerialMode
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialSetParam ( UINT8  slot,
SERIAL_PORT  port,
UINT8  parity,
UINT8  databits,
UINT8  stopbit 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[in]paritySerialParity
[in]databitsSerialDataBits
[in]stopbitSerialStopBit
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialDataInInputQueue ( UINT8  slot,
SERIAL_PORT  port,
UINT32 bytes 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[out]bytesbytes of received data in input queue.
Returns
SERIAL_ERR_CODE
SERIAL_ERR_CODE MX_RTU_SerialDataInOutputQueue ( UINT8  slot,
SERIAL_PORT  port,
UINT32 bytes 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[out]bytesbytes of sent data in output queue.
Returns
SERIAL_ERR_CODE
Note
Please checking (SERIAL_MAX_OQUEUE_LENGTH - bytes) > written bytes or not before calling MX_RTU_SerialWrite.
SERIAL_ERR_CODE MX_RTU_SerialInputQueueFlush ( UINT8  slot,
SERIAL_PORT  port 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
Returns
SERIAL_ERR_CODE
Note
Flushes data received but not read.
SERIAL_ERR_CODE MX_RTU_SerialOutputQueueFlush ( UINT8  slot,
SERIAL_PORT  port 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
Returns
SERIAL_ERR_CODE
Note
Flushes data written but not transmitted.
SERIAL_ERR_CODE MX_RTU_FindFD ( UINT8  slot,
SERIAL_PORT  port,
INT32 fd 
)
Parameters
[in]slotslot 0: Built-in COM Ports, slot 1 ~ 9: Expansion COM Ports.
[in]portport 0 ~ 3.
[out]fdfile descriptor of slot and port.
Returns
SERIAL_ERR_CODE