mraa  1.7.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Functions | Typedefs
uart.h File Reference

API Description

UART is the Universal asynchronous receiver/transmitter interface to libmraa. It allows the exposure of UART pins on supported boards. With functionality to expand at a later date.

#include "mraa.h"
int
main(int argc, char** argv)
{
mraa_uart_context uart;
uart = mraa_uart_init(0);
if (uart == NULL) {
fprintf(stderr, "UART failed to setup\n");
return EXIT_FAILURE;
}
char buffer[] = "Hello Mraa!";
mraa_uart_write(uart, buffer, sizeof(buffer));
return EXIT_SUCCESS;
}

Go to the source code of this file.

Functions

mraa_uart_context mraa_uart_init (int uart)
 
mraa_uart_context mraa_uart_init_raw (const char *path)
 
mraa_result_t mraa_uart_flush (mraa_uart_context dev)
 
mraa_result_t mraa_uart_sendbreak (mraa_uart_context dev, int duration)
 
mraa_result_t mraa_uart_set_baudrate (mraa_uart_context dev, unsigned int baud)
 
mraa_result_t mraa_uart_set_mode (mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits)
 
mraa_result_t mraa_uart_set_flowcontrol (mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts)
 
mraa_result_t mraa_uart_set_timeout (mraa_uart_context dev, int read, int write, int interchar)
 
mraa_result_t mraa_uart_set_non_blocking (mraa_uart_context dev, mraa_boolean_t nonblock)
 
const char * mraa_uart_get_dev_path (mraa_uart_context dev)
 
mraa_result_t mraa_uart_stop (mraa_uart_context dev)
 
int mraa_uart_read (mraa_uart_context dev, char *buf, size_t length)
 
int mraa_uart_write (mraa_uart_context dev, const char *buf, size_t length)
 
mraa_boolean_t mraa_uart_data_available (mraa_uart_context dev, unsigned int millis)
 

Typedefs

typedef struct _uart * mraa_uart_context
 

Function Documentation

mraa_uart_context mraa_uart_init ( int  uart)

Initialise uart_context, uses board mapping

Parameters
uartthe index of the uart set to use
Returns
uart context or NULL

Here is the caller graph for this function:

mraa_uart_context mraa_uart_init_raw ( const char *  path)

Initialise a raw uart_context. No board setup.

Parameters
pathfor example "/dev/ttyS0"
Returns
uart context or NULL

Here is the caller graph for this function:

mraa_result_t mraa_uart_flush ( mraa_uart_context  dev)

Flush the outbound data. Blocks until complete.

Parameters
devThe UART context
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_sendbreak ( mraa_uart_context  dev,
int  duration 
)

Send a break to the device. Blocks until complete.

Parameters
devThe UART context
durationWhen 0, send a break lasting at least 250 milliseconds, and not more than 500 milliseconds. When non zero, the break duration is implementation specific.
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_baudrate ( mraa_uart_context  dev,
unsigned int  baud 
)

Set the baudrate. Takes an int and will attempt to decide what baudrate is to be used on the UART hardware.

Parameters
devThe UART context
baudunsigned int of baudrate i.e. 9600
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_mode ( mraa_uart_context  dev,
int  bytesize,
mraa_uart_parity_t  parity,
int  stopbits 
)

Set the transfer mode For example setting the mode to 8N1 would be "mraa_uart_set_mode(dev, 8,MRAA_UART_PARITY_NONE , 1)"

Parameters
devThe UART context
bytesizedata bits
parityParity bit setting
stopbitsstop bits
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_flowcontrol ( mraa_uart_context  dev,
mraa_boolean_t  xonxoff,
mraa_boolean_t  rtscts 
)

Set the flowcontrol

Parameters
devThe UART context
xonxoffXON/XOFF Software flow control.
rtsctsRTS/CTS out of band hardware flow control
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_timeout ( mraa_uart_context  dev,
int  read,
int  write,
int  interchar 
)

Set the timeout for read and write operations <= 0 will disable that timeout

Parameters
devThe UART context
readread timeout
writewrite timeout
intercharinbetween char timeout
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_uart_set_non_blocking ( mraa_uart_context  dev,
mraa_boolean_t  nonblock 
)

Set the blocking state for write operations

Parameters
devThe UART context
nonblocknew nonblocking state
Returns
Result of operation

Here is the caller graph for this function:

const char* mraa_uart_get_dev_path ( mraa_uart_context  dev)

Get Char pointer with tty device path within Linux For example. Could point to "/dev/ttyS0"

Parameters
devuart context
Returns
char pointer of device path

Here is the caller graph for this function:

mraa_result_t mraa_uart_stop ( mraa_uart_context  dev)

Destroy a mraa_uart_context

Parameters
devuart context
Returns
mraa_result_t

Here is the caller graph for this function:

int mraa_uart_read ( mraa_uart_context  dev,
char *  buf,
size_t  length 
)

Read bytes from the device into a buffer

Parameters
devuart context
bufbuffer pointer
lengthmaximum size of buffer
Returns
the number of bytes read, or -1 if an error occurred

Here is the caller graph for this function:

int mraa_uart_write ( mraa_uart_context  dev,
const char *  buf,
size_t  length 
)

Write bytes in buffer to a device

Parameters
devuart context
bufbuffer pointer
lengthmaximum size of buffer
Returns
the number of bytes written, or -1 if an error occurred

Here is the caller graph for this function:

mraa_boolean_t mraa_uart_data_available ( mraa_uart_context  dev,
unsigned int  millis 
)

Check to see if data is available on the device for reading

Parameters
devuart context
millisnumber of milliseconds to wait, or 0 to return immediately
Returns
1 if there is data available to read, 0 otherwise

Here is the caller graph for this function:

Include dependency graph for uart.h: