mraa  1.7.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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* dev;
try {
dev = new mraa::Uart(0);
} catch (std::exception& e) {
std::cout << e.what() << ", likely invalid platform config" << std::endl;
}
try {
dev = new mraa::Uart("/dev/ttyACM0");
} catch (std::exception& e) {
std::cout << "Error while setting up raw UART, do you have a uart?" << std::endl;
std::terminate();
}
if (dev->setBaudRate(115200) != mraa::SUCCESS) {
std::cout << "Error setting parity on UART" << std::endl;
}
if (dev->setMode(8, mraa::UART_PARITY_NONE, 1) != mraa::SUCCESS) {
std::cout << "Error setting parity on UART" << std::endl;
}
if (dev->setFlowcontrol(false, false) != mraa::SUCCESS) {
std::cout << "Error setting flow control UART" << std::endl;
}
dev->writeStr("Hello monkeys");

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: