Giter VIP home page Giter VIP logo

libuart's Introduction

libuart

Easy to use library for accessing the UART (RS232) interface.

Functions:

uart_t *uart_open(const char *dev, int baud, const char *opt)

Open a UART port connection.

Arguments:

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

Return:

On success, an uart_t object will be returned. On error, a NULL pointer will be returned.

void uart_close(uart_t *uart)

Close the connection.

Arguments:

Arg Description
uart The uart_t object

int uart_send(uart_t *uart, char *send_buf, int len)

Transmit data via UART.

Arguments:

Arg Description
uart The uart_t object
send_buf The pointer to the data to transmit
len The length of the data in bytes

Return:

On success, the number of transmited bytes will be returned. On error, -1 will be returned.

int uart_recv(uart_t *uart, char *recv_buf, int len)

Receive data from the UART port.

Arguments:

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

Return:

On success, the number of received bytes will be returned. On error, -1 will be returned.

void uart_baud_set(uart_t *uart, int baud)

Set the baud rate from the UART port.

Arguments:

Arg Description
uart The uart_t object
baud The baud rate (Use the enums in the header file, other values where not accepted)

int uart_baud_get(uart_t *uart)

Get the current baud rate from the UART port.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the baud rate will be returned. On error, -1 will be returned.

int uart_fd_get(uart_t *uart)

Get the file descriptor from the UART port. (Linux/UNIX only)

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the file descriptor will be returned. On error, -1 will be returned.

int uart_handle_get(uart_t *uart)

Get the handle from the UART port. (Windows only)

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the handle will be returned. On error, -1 will be returned.

char *uart_dev_get(uart_t *uart)

Get the device of the from the UART port.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the device name will be returned. After usage the string must be freed. On error, a NULL pointer will be returned.

void uart_databits_set(uart_t *uart, int data_bits)

Set the data bits from the UART port.

Arguments:

Arg Description
uart The uart_t object
data_bits The number of data bits (valid values are 5, 6, 7 ot 8)

int uart_databits_get(uart_t *uart)

Get the data bits from the uart port.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the number of data bits will be returned. On error, -1 will be returned.

void uart_parity_set(uart_t *uart, int parity)

Set the parity from the UART port.

Arguments:

Arg Description
uart The uart_t object
parity The parity (valid values are UART_PARITY_NO, UART_PARITY_ODD or UART_PARITY_EVEN)

int uart_parity_get(uart_t *uart)

Get the parity from the UART port.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the parity will be returned. On error, -1 will be returned.

void uart_stopbits_set(uart_t *uart, int stop_bits)

Set the stop bits from the UART port.

Arguments:

Arg Description
uart The uart_t object
stop_bits The number of stop bits (valid values are 1 or 2)

int uart_stopbits_get(uart_t *uart)

Get the stop bits from the UART port.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the number of stop bits will be returned. On error, -1 will be returned.

void uart_flow_set(uart_t *uart, int flow_ctrl)

Set the flow control from the UART port.

Arguments:

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)

int uart_flow_get(uart_t *uart)

Get the flow control from the UART port.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the flow control will be returned. On error, -1 will be returned.

void uart_pin_set(uart_t *uart, int pin, int state)

Set the state of a specific pin from the UART port.

Arguments:

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)
Pins:
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

int uart_pin_get(uart_t *uart, int pin)

Get the state of a specific pin from the UART port.

Arguments:

Arg Description
uart The uart_t object
pin The control pin of the UART

Return:

On success, the state of the pin will be returned. On error, -1 will be returned.

int uart_bytes_get(uart_t *uart);

Get the current available bytes in the receive buffer.

Arguments:

Arg Description
uart The uart_t object

Return:

On success, the number of bytes in the receive buffer will be returned. On error, -1 will be returned.

libuart's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.