mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Public Member Functions | List of all members
Uart Class Reference

Detailed Description

This file defines the UART interface for libmraa

Uart uart = new Uart(0);
if (uart.setBaudRate(115200) != Result.SUCCESS) {
System.err.println("Error setting baud rate");
System.exit(1);
}
if (uart.setMode(8, UartParity.UART_PARITY_NONE, 1) != Result.SUCCESS) {
System.err.println("Error setting mode");
System.exit(1);
}
if (uart.setFlowcontrol(false, false) != Result.SUCCESS) {
System.err.println("Error setting flow control");
System.exit(1);
}
uart.writeStr("Hello monkeys");

Public Member Functions

synchronized void delete ()
 
 Uart (int uart)
 
 Uart (String path)
 
String getDevicePath ()
 
String readStr (int length)
 
int writeStr (String data)
 
boolean dataAvailable (long millis)
 
boolean dataAvailable ()
 
Result flush ()
 
Result sendBreak (int duration)
 
Result setBaudRate (long baud)
 
Result setMode (int bytesize, UartParity parity, int stopbits)
 
Result setFlowcontrol (boolean xonxoff, boolean rtscts)
 
Result setTimeout (int read, int write, int interchar)
 
Result setNonBlocking (boolean nonblock)
 

Constructor & Destructor Documentation

Uart ( int  uart)

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
Uart ( String  path)

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

Member Function Documentation

boolean dataAvailable ( long  millis)

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:

Here is the caller graph for this function:

Result flush ( )

Flush the outbound data. Blocks until complete.

Returns
Result of operation
String getDevicePath ( )

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

Returns
char pointer of device path
String readStr ( int  length)

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
Result sendBreak ( int  duration)

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
Result setBaudRate ( long  baud)

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
Result setFlowcontrol ( boolean  xonxoff,
boolean  rtscts 
)

Set the flowcontrol

Parameters
xonxoffXON/XOFF Software flow control.
rtsctsRTS/CTS out of band hardware flow control
Returns
Result of operation
Result setMode ( int  bytesize,
UartParity  parity,
int  stopbits 
)

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
Result setNonBlocking ( boolean  nonblock)

Set the blocking state for write operations

Parameters
nonblocknew nonblocking state
Returns
Result of operation
Result setTimeout ( int  read,
int  write,
int  interchar 
)

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
int writeStr ( String  data)

Write bytes in String object to a device

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

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