mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Public Member Functions
Uart Class Reference

Detailed Description

This file defines the UART interface for libmraa

// If you have a valid platform configuration use numbers to represent uart
// device. If not use raw mode where std::string is taken as a constructor
// parameter
mraa::Uart* uart;
try {
uart = new mraa::Uart(UART_PORT);
} catch (std::exception& e) {
std::cerr << e.what() << ", likely invalid platform config" << std::endl;
}
try {
uart = new mraa::Uart(dev_path);
} catch (std::exception& e) {
std::cerr << "Error while setting up raw UART, do you have a uart?" << std::endl;
std::terminate();
}
if (uart->setBaudRate(115200) != mraa::SUCCESS) {
std::cerr << "Error setting parity on UART" << std::endl;
}
if (uart->setMode(8, mraa::UART_PARITY_NONE, 1) != mraa::SUCCESS) {
std::cerr << "Error setting parity on UART" << std::endl;
}
if (uart->setFlowcontrol(false, false) != mraa::SUCCESS) {
std::cerr << "Error setting flow control UART" << std::endl;
}
while (flag) {
/* send data through uart */
uart->writeStr("Hello Mraa!");
sleep(1);
}

Public Member Functions

 Uart (int uart)
 
 Uart (std::string path)
 
 Uart (void *uart_context)
 
 ~Uart ()
 
std::string getDevicePath ()
 
int read (char *data, int length)
 
int write (const char *data, int length)
 
std::string readStr (int length)
 
int writeStr (std::string data)
 
bool dataAvailable (unsigned int millis=0)
 
Result flush ()
 
Result sendBreak (int duration)
 
Result setBaudRate (unsigned int baud)
 
Result setMode (int bytesize, UartParity parity, int stopbits)
 
Result setFlowcontrol (bool xonxoff, bool rtscts)
 
Result setTimeout (int read, int write, int interchar)
 
Result setNonBlocking (bool nonblock)
 

Constructor & Destructor Documentation

Uart ( int  uart)
inline

Uart Constructor, takes a pin number which will map directly to the linux uart number, this 'enables' the uart, nothing more

Parameters
uartthe index of the uart set to use

Here is the call graph for this function:

Uart ( std::string  path)
inline

Uart Constructor, takes a string to the path of the serial interface that is needed.

Parameters
paththe index of the uart set to use

Here is the call graph for this function:

Uart ( void *  uart_context)
inline

Uart Constructor, takes a pointer to the UART context and initialises the UART class

Parameters
uart_contextvoid * to a UART context
~Uart ( )
inline

Uart destructor

Here is the call graph for this function:

Member Function Documentation

std::string getDevicePath ( )
inline

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

Returns
char pointer of device path

Here is the call graph for this function:

int read ( char *  data,
int  length 
)
inline

Read bytes from the device into char* buffer

Parameters
databuffer pointer
lengthmaximum size of buffer
Returns
numbers of bytes read

Here is the call graph for this function:

int write ( const char *  data,
int  length 
)
inline

Write bytes in char* buffer to a device

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

Here is the call graph for this function:

std::string readStr ( int  length)
inline

Read bytes from the device into a String object

Parameters
lengthto read
Exceptions
std::bad_allocIf there is no space left for read.
Returns
string of data

Here is the call graph for this function:

int writeStr ( std::string  data)
inline

Write bytes in String object to a device

Parameters
datastring to write
Returns
the number of bytes written, or -1 if an error occurred

Here is the call graph for this function:

bool dataAvailable ( unsigned int  millis = 0)
inline

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

Parameters
millisnumber of milliseconds to wait, or 0 to return immediately
Returns
true if there is data available to read, false otherwise

Here is the call graph for this function:

Result flush ( )
inline

Flush the outbound data. Blocks until complete.

Returns
Result of operation

Here is the call graph for this function:

Result sendBreak ( int  duration)
inline

Send a break to the device. Blocks until complete.

Parameters
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 call graph for this function:

Result setBaudRate ( unsigned int  baud)
inline

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

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

Here is the call graph for this function:

Result setMode ( int  bytesize,
UartParity  parity,
int  stopbits 
)
inline

Set the transfer mode For example setting the mode to 8N1 would be "dev.setMode(8,UART_PARITY_NONE , 1)"

Parameters
bytesizedata bits
parityParity bit setting
stopbitsstop bits
Returns
Result of operation

Here is the call graph for this function:

Result setFlowcontrol ( bool  xonxoff,
bool  rtscts 
)
inline

Set the flowcontrol

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

Here is the call graph for this function:

Result setTimeout ( int  read,
int  write,
int  interchar 
)
inline

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

Parameters
readread timeout
writewrite timeout
intercharinbetween char timeout
Returns
Result of operation

Here is the call graph for this function:

Result setNonBlocking ( bool  nonblock)
inline

Set the blocking state for write operations

Parameters
nonblocknew nonblocking state
Returns
Result of operation

Here is the call graph for this function:


The documentation for this class was generated from the following file: