defs/si_sys/serial.h File Reference

A serial port object. More...

#include <si_sys/defs.h>
#include <termios.h>

Go to the source code of this file.

Classes

struct  sc_serialPort
 A serial port object. More...

Enumerations

enum  se_baudRate {
  se_baudRate_9600 = 9600, se_baudRate_19200 = 19200, se_baudRate_38400 = 38400, se_baudRate_57600 = 57600,
  se_baudRate_115200 = 115200, se_baudRate_230400 = 230400
}
 An enumeration of allowed baud rate values.

Functions

sc_status sc_serialPort_construct (sc_serialPort *sp, const char *dev, se_baudRate baud)
sc_status sc_serialPort_destruct (sc_serialPort *sp)
sc_status sc_serialPort_read (sc_serialPort *sp, s_uint8 *buff, s_int32 len, s_int32 *bytesRead)
sc_status sc_serialPort_readAll (sc_serialPort *sp, s_uint8 *buff, s_int32 len)
sc_status sc_serialPort_write (sc_serialPort *sp, const s_uint8 *buff, s_int32 len, s_int32 *bytesWritten)
sc_status sc_serialPort_flush (sc_serialPort *sp)


Detailed Description

A serial port object.

This serial port object hides some complexity in opening and configuring serial ports.


Function Documentation

sc_status sc_serialPort_construct ( sc_serialPort sp,
const char *  dev,
se_baudRate  baud 
)

Constructs the serial port object sp using the special file name 'dev' and sets it up at the given baud rate.

The port is always set to binary mode.

sc_status sc_serialPort_destruct ( sc_serialPort sp  ) 

Destructs the serial port sp, closing the device and restoring its original parameters.

sc_status sc_serialPort_flush ( sc_serialPort sp  ) 

Flushes the send and recv buffers associated with the port sp.

sc_status sc_serialPort_read ( sc_serialPort sp,
s_uint8 *  buff,
s_int32  len,
s_int32 *  bytesRead 
)

Reads as many bytes as are available on the port (up to len) into buff. The actual number read is returned in bytesRead.

Parameters:
[in,out] sp The serial port object to read from.
[in] buff The buffer to store read bytes.
[in] len The size of buffer. No more bytes than this will be read.
[out] bytesRead The actual number of bytes read into buff.

sc_status sc_serialPort_readAll ( sc_serialPort sp,
s_uint8 *  buff,
s_int32  len 
)

Reads len bytes on the port into the given buffer, blocking if necessary until all len bytes are read.

Parameters:
[in,out] sp The serial port object to read from.
[in] buff The buffer to store read bytes.
[in] len The number of bytes that will be read.

sc_status sc_serialPort_write ( sc_serialPort sp,
const s_uint8 *  buff,
s_int32  len,
s_int32 *  bytesWritten 
)

Writes as many bytes as possible to the port (up to len) from buff. The actual number written is returned in bytesWritten.

Parameters:
[in,out] sp The serial port object to write to.
[in] buff The data to write.
[in] len The amount of data to write.
[out] bytesWritten The actual number of bytes written from buff.


doxygen