class Serial

Generic serial device access. More...

Definition#include <serial.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Members


Detailed Description

A portable APE class for access to generic serial devices. The win32 version has not yet been written, but the Posix version uses termios services.

Serial (const char *fname, long speed, int format, int flow)

Open a named serial device under a specified set of attributes. Attributes include the serial device speed (baud rate), the data format (SERIAL_FORMAT_7E1, SERIAL_FORMAT_7O1, SERIAL_FORMAT_7N1, SERIAL_FORMAT_7S2, SERIAL_FORMAT_8E1, SERIAL_FORMAT_8O1, SERIAL_FORMAT_8N1, and SERIAL_FORMAT_8S2), as well as the kind of flow control (SERIAL_FLOW_NONE, SERIAL_FLOW_HARD, SERIAL_FLOW_SOFT and SERIAL_FLOW_BOTH) to use. Additional data formats would be easy enough to add if so desired.

Parameters:
fnamepath name of logical serial device. @speed absolute speed in bits per second. @format serial data format to use. @flow serial device flow control method to use.

~Serial ()
[virtual]

Release the serial device and restore it to it's previous attributes.

void setFlowControl (int flow)

Change the flow control mode in effect for the serial device. This allows post constructor changes.

Parameters:
flowserial device flow control method to use.

void setSpeed (long speed)

Change the serial port baud rate (speed in bps) for the serial device.

Parameters:
speedabsolute speed in bits per second.

void setFormat (int format)

Change the serial port data format in use for the serial device.

Parameters:
formatserial data format to use.

int Inkey (timeout_t timer = 0)

Wait up to a specified timeout for a single character to appear at the serial device, and return that character.

Parameters:
timertimeout specified in milliseconds.

Returns: character read or -1 if timed out.

int Read (void *buf, size_t len, timeout_t timer = 0)

Read a specified number of bytes from the serial device but wait no longer than a specified timeout for data to become available. The Posix termios only supports timeout resolution within 1/10th of a second, hence, specifying a timeout with an accuracy less than 100 milliseconds is useless.

Parameters:
bufpointer to store data from the device.
lennumber of bytes to read.
timertimeout specified in milliseconds.

Returns: number of bytes actually read.

int Readline (char *buf, size_t max, timeout_t timer = 0)

Read a specified number of bytes from the serial device but wait no longer than a specified timeout, and also stop if the newline character has been read.

Parameters:
bufpointer to store data from the device.
lennumber of bytes to read.
timertimeout specified in milliseconds.

Returns: number of bytes actually read.

inline void setNewline (char nl)

Specify the newline character code to use with ReadLine.

Parameters:
nlnewline character code (default 13).

inline int Write (void *buf, size_t len)
[virtual]

Write a block of data to the serial device.

Parameters:
bufpointer to data to write.
lennumber of bytes to write.

Returns: number of bytes written on success, -1 on error.

inline int Write (char *buf)
[virtual]

Write a null terminated C string directly to the serial device.

Parameters:
bufpointer to null terminated string to write.

Returns: number of bytes written on success, -1 on error.