Easy to use library for accessing the UART (RS232) interface.
Open a UART port connection.
Arg | Description |
---|---|
dev | The device name of the UART port |
baud | The baud rate of the UART port (Use the enums in the header file, other values are not accepted) |
opt | The configuration string of the UART port |
The configuration string must be 4 chars long. The first char represents the number of data bits (valid values are 5, 6, 7 or 8), the second char represents the parity (valid values are N for No parity, O for Odd parity or E for Even parity), the third char represents the number of stop bits (valid values are 1 or 2) and the fourth char represents the flow control (valid values are N for No flow control, S for Software flow control or H for Hardware flow control).
Example configuration string:
8N1N
Char | Description |
---|---|
8 | 8 data bits |
N | No parity |
1 | 1 stop bit |
N | No flow control |
On success, an uart_t object will be returned. On error, a NULL pointer will be returned.
Close the connection.
Arg | Description |
---|---|
uart | The uart_t object |
Transmit data via UART.
Arg | Description |
---|---|
uart | The uart_t object |
send_buf | The pointer to the data to transmit |
len | The length of the data in bytes |
On success, the number of transmited bytes will be returned. On error, -1 will be returned.
Receive data from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
recv_buf | The pointer where the received data is stored |
len | The length of the data in bytes |
On success, the number of received bytes will be returned. On error, -1 will be returned.
Set the baud rate from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
baud | The baud rate (Use the enums in the header file, other values where not accepted) |
Get the current baud rate from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the baud rate will be returned. On error, -1 will be returned.
Get the file descriptor from the UART port. (Linux/UNIX only)
Arg | Description |
---|---|
uart | The uart_t object |
On success, the file descriptor will be returned. On error, -1 will be returned.
Get the handle from the UART port. (Windows only)
Arg | Description |
---|---|
uart | The uart_t object |
On success, the handle will be returned. On error, -1 will be returned.
Get the device of the from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the device name will be returned. After usage the string must be freed. On error, a NULL pointer will be returned.
Set the data bits from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
data_bits | The number of data bits (valid values are 5, 6, 7 ot 8) |
Get the data bits from the uart port.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the number of data bits will be returned. On error, -1 will be returned.
Set the parity from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
parity | The parity (valid values are UART_PARITY_NO, UART_PARITY_ODD or UART_PARITY_EVEN) |
Get the parity from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the parity will be returned. On error, -1 will be returned.
Set the stop bits from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
stop_bits | The number of stop bits (valid values are 1 or 2) |
Get the stop bits from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the number of stop bits will be returned. On error, -1 will be returned.
Set the flow control from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
flow_ctrl | The flow control (valid values are UART_FLOW_NO, UART_FLOW_SOFTWARE or UART_FLOW_HARDWARE) |
Get the flow control from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the flow control will be returned. On error, -1 will be returned.
Set the state of a specific pin from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
pin | The control pin of the UART |
state | The state of the pin to set (valid values are 0 or 1) |
Pin | Description |
---|---|
UART_PIN_RTS | Request to Send |
UART_PIN_CTS | Clear to Send |
UART_PIN_DSR | Data Set Ready |
UART_PIN_DCD | Data Carrier Detect |
UART_PIN_DTR | Data Terminal Ready |
UART_PIN_RI | Ring Indicator |
Get the state of a specific pin from the UART port.
Arg | Description |
---|---|
uart | The uart_t object |
pin | The control pin of the UART |
On success, the state of the pin will be returned. On error, -1 will be returned.
Get the current available bytes in the receive buffer.
Arg | Description |
---|---|
uart | The uart_t object |
On success, the number of bytes in the receive buffer will be returned. On error, -1 will be returned.