MRAA

MRAA is a low level skeleton library for communication on GNU/Linux platforms. See examples here.

Uart Class

Module: mraa

This file defines the UART interface for libmraa

Methods

Uart

(
  • uart
)
Number

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

Parameters:

  • uart Number

    the index of the uart set to use

Returns:

Number:

Uart

(
  • path
)
Number

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

Parameters:

  • path String

    the index of the uart set to use

Returns:

Number:

getDevicePath

() String

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

Returns:

String:

char pointer of device path

read

(
  • length
)
Buffer

Read length bytes from the device

Parameters:

  • length Number

    Size of read in bytes to make

Returns:

Buffer:

Data read

write

(
  • length
)
Enum mraa_result_t

Write length bytes to the device

Parameters:

  • length Number

    Size of buffer to send

Returns:

Enum mraa_result_t:

Result of operation

readStr

(
  • length
)
String

Read bytes from the device into a String object

Parameters:

  • length Number

    to read

Returns:

String:

string of data

writeStr

(
  • data
)
Number

Write bytes in String object to a device

Parameters:

  • data String

    string to write

Returns:

Number:

the number of bytes written, or -1 if an error occurred

dataAvailable

(
  • millis
)
Boolean

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

Parameters:

  • millis Number

    number of milliseconds to wait, or 0 to return immediately

Returns:

Boolean:

true if there is data available to read, false otherwise

flush

() Enum Result

Flush the outbound data. Blocks until complete.

Returns:

Enum Result:

Result of operation

sendBreak

(
  • duration
)
Enum Result

Send a break to the device. Blocks until complete.

Parameters:

  • duration Number

    When 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:

Enum Result:

Result of operation

setBaudRate

(
  • baud
)
Enum Result

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

Parameters:

  • baud Number

    unsigned int of baudrate i.e. 9600

Returns:

Enum Result:

Result of operation

setMode

(
  • bytesize
  • parity
  • stopbits
)
Enum Result

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

Parameters:

  • bytesize Number

    data bits

  • parity Enum UartParity

    Parity bit setting

  • stopbits Number

    stop bits

Returns:

Enum Result:

Result of operation

setFlowcontrol

(
  • xonxoff
  • rtscts
)
Enum Result

Set the flowcontrol

Parameters:

  • xonxoff Boolean

    XON/XOFF Software flow control.

  • rtscts Boolean

    RTS/CTS out of band hardware flow control

Returns:

Enum Result:

Result of operation

setTimeout

(
  • read
  • write
  • interchar
)
Enum Result

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

Parameters:

  • read Number

    read timeout

  • write Number

    write timeout

  • interchar Number

    inbetween char timeout

Returns:

Enum Result:

Result of operation

setNonBlocking

(
  • nonblock
)
Enum Result

Set the blocking state for write operations

Parameters:

  • nonblock Boolean

    new nonblocking state

Returns:

Enum Result:

Result of operation