Main Page   Namespace List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

lfc::posixPAL::serial Namespace Reference

posix serial communications PAL. More...


Compounds

struct  lfc::posixPAL::serial::PortSettings
 contain port settings to save/restore. More...


Typedefs

typedef int Handle
 serial port handle type. More...


Enumerations

enum  ErrorCodes { errOk, errGeneric, errNotSupported }

Functions

int init ()
 init PAL. More...

int cleanup ()
 cleanup PAL. More...

int open (Handle &handle, const char *name)
 open serial port. More...

int close (Handle handle)
 close a serial port. More...

int write (Handle handle, const void *buff, long count, long &writtenCount)
 write data to a serial device. More...

int read (Handle handle, void *buff, long count, long &readCount)
 read data from a serial device. More...

int flush (Handle handle)
 flush output buffer. More...

int setup (Handle handle, const char *portSettings)
 set port settings (baud rate, parity, ...). More...

int availableCount (Handle handle, long &count)
 get the number of bytes available in the input buffer. More...

int setHardwareFlowControl (Handle handle, bool bEnable)
 enable/disable hardware flow control. More...

int setSoftwareFlowControl (Handle handle, bool bEnable, char Xon, char Xoff)
 enable/disable software flow control. More...

int setReadTimeouts (Handle handle, long timeout)
 set read timeouts. More...

int setBlockingRead (Handle handle, bool bBlocking)
 enable/disable blocking read. More...

int purgeBuffer (Handle handle, int flags)
 purge i/o buffers. More...

int sendBreak (Handle handle)
 send a break (for 500ms). More...

int getModemStatus (Handle handle, int &status)
 get modem status bits (DSR, DTR, RTS, CTS, DCD, RNG). More...

int setDTR (Handle handle, bool bEnable)
 enable/disable DTR. More...

int setRTS (Handle handle, bool bEnable)
 enable/disable RTS. More...

int saveSettings (Handle handle, PortSettings &settings)
 save current port settings. More...

int restoreSettings (Handle handle, const PortSettings &settings)
 restore current port settings. More...

const char * message (int index)
 return the message coresponding to a return code. More...


Variables

const int MAX_ERROR_CODE = 2
const char * messagesTable [MAX_ERROR_CODE+1]
const Handle NULL_HANDLE = -1
 a handle value designating an invalid handle. More...

const int purgeInput = 0x0001
 purge buffer flags. More...

const int purgeOutput = 0x0002
 purge buffer flags. More...

const int mstatusDSR = 0x0001
 modem status flags. More...

const int mstatusDTR = 0x0002
 modem status flags. More...

const int mstatusRTS = 0x0004
 modem status flags. More...

const int mstatusCTS = 0x0008
 modem status flags. More...

const int mstatusDCD = 0x0010
 modem status flags. More...

const int mstatusRNG = 0x0020
 modem status flags. More...


Detailed Description

posix serial communications PAL.

Todo:
more datalied error codes

need testing


Typedef Documentation

typedef int lfc::posixPAL::serial::Handle
 

serial port handle type.


Enumeration Type Documentation

enum lfc::posixPAL::serial::ErrorCodes
 

Enumeration values:
errOk 
errGeneric 
errNotSupported 


Function Documentation

int init   [inline]
 

init PAL.

Returns:
error code (0 means no error)

int cleanup   [inline]
 

cleanup PAL.

Returns:
error code (0 means no error)

int open Handle   handle,
const char *    name
[inline]
 

open serial port.

Parameters:
handle  will contain the handle if the operation succed, no modification otherwhise
name  comm device name (ex. "com1" under win32, "/dev/ttyS0" under Linux)
Returns:
error code (0 means no error)

int close Handle    handle [inline]
 

close a serial port.

Parameters:
handle  a valid serial port handle
Returns:
error code (0 means no error)

int write Handle    handle,
const void *    buff,
long    count,
long &    writtenCount
[inline]
 

write data to a serial device.

Parameters:
handle  a valid handle
buff  pointer to the data to be written
count  number of bytes to write
written  return the actual number of bytes written
Returns:
error code (0 means no error)

int read Handle    handle,
void *    buff,
long    count,
long &    readCount
[inline]
 

read data from a serial device.

Parameters:
handle  a valid handle
buff  pointer to the buffer that will receive the data
count  number of bytes to read
written  return the actual number of bytes read
Returns:
error code (0 means no error)

int flush Handle    handle [inline]
 

flush output buffer.

Parameters:
handle  a valid handle
Returns:
error code (0 means no error)

int setup Handle    handle,
const char *    portSettings
[inline]
 

set port settings (baud rate, parity, ...).

Parameters:
handle  a valid handle
portSettings  describe port settings in the following format: <baud>,

<S> where

  • baud is serial transmition speed
  • B is byte size (5..8)
  • P is parity (n-none, o-odd, e-even, s-space)
  • S is stop bits (1 or 2)
    Note:
    settings string is not case sensitive and it can't containt whitespaces
    Returns:
    error code (0 means no error)

int availableCount Handle    handle,
long &    count
[inline]
 

get the number of bytes available in the input buffer.

Parameters:
handle  a valid handle
count  return the count of available bytes in the input buffer
Returns:
error code (0 means no error)

int setHardwareFlowControl Handle    handle,
bool    bEnable
[inline]
 

enable/disable hardware flow control.

Parameters:
handle  a valid handle
bEnable  if true enable hardware flow control, else disable
Returns:
error code (0 means no error)

int setSoftwareFlowControl Handle    handle,
bool    bEnable,
char    Xon,
char    Xoff
[inline]
 

enable/disable software flow control.

Parameters:
handle  a valid handle
bEnable  if true enable software flow control, else disable
Xon  XON character
Xoff  XOFF character
Returns:
error code (0 means no error)

int setReadTimeouts Handle    handle,
long    timeout
[inline]
 

set read timeouts.

Parameters:
handle  a valid handle
timeout  time (in ms) to wait until a char is received
Returns:
error code (0 means no error)

int setBlockingRead Handle    handle,
bool    bBlocking
[inline]
 

enable/disable blocking read.

Parameters:
handle  a valid handle
bBlocking  if true read blocks until all requested data is read, else read will return immediately with available bytes (possibly none)
Returns:
error code (0 means no error)
Note:
this function might affect read timeouts

int purgeBuffer Handle    handle,
int    flags
[inline]
 

purge i/o buffers.

Parameters:
handle  a valid handle
flags  a combination of the following:
  • purgeInput - clear input buffer
  • purgeOutput - clear output buffer
Returns:
error code (0 means no error)

int sendBreak Handle    handle [inline]
 

send a break (for 500ms).

Parameters:
handle  a valid handle
Returns:
error code (0 means no error)

int getModemStatus Handle    handle,
int &    status
[inline]
 

get modem status bits (DSR, DTR, RTS, CTS, DCD, RNG).

Parameters:
handle  a valid handle
status  will receive modem status flags
  • mstatusCTS - clear to send
  • mstatusDSR - data set ready
  • mstatusRNG - ring
  • mstatusDCD - data carrier detect
Returns:
error code (0 means no error)
Warning:
doesn't get RTS, DTR

int setDTR Handle    handle,
bool    bEnable
[inline]
 

enable/disable DTR.

Parameters:
handle  a valid handle
bEnable  enable or disable DTR
Returns:
error code (0 means no error)
Note:
hardware flow control must be disabled to use this

int setRTS Handle    handle,
bool    bEnable
[inline]
 

enable/disable RTS.

Parameters:
handle  a valid handle
bEnable  enable or disable RTS
Returns:
error code (0 means no error)
Note:
hardware flow control must be disabled to use this

int saveSettings Handle    handle,
PortSettings   settings
[inline]
 

save current port settings.

Parameters:
handle  a valid handle
settings  will store current port settings
Returns:
error code (0 means no error)

int restoreSettings Handle    handle,
const PortSettings   settings
[inline]
 

restore current port settings.

Parameters:
handle  a valid handle
settings  contain previously saved settings
Returns:
error code (0 means no error)

const char* message int    index [inline]
 

return the message coresponding to a return code.

Parameters:
index  message index (return code from other pal functions)


Variable Documentation

const int lfc::posixPAL::serial::MAX_ERROR_CODE = 2
 

const char * lfc::posixPAL::serial::messagesTable
 

Initial value:

{
    "posixPAL::serial -- No error (ok)",
    "posixPAL::serial -- Generic error",
    "posixPAL::serial -- Not supported",
}

const Handle lfc::posixPAL::serial::NULL_HANDLE = -1
 

a handle value designating an invalid handle.

const int lfc::posixPAL::serial::purgeInput = 0x0001
 

purge buffer flags.

const int lfc::posixPAL::serial::purgeOutput = 0x0002
 

purge buffer flags.

const int lfc::posixPAL::serial::mstatusDSR = 0x0001
 

modem status flags.

const int lfc::posixPAL::serial::mstatusDTR = 0x0002
 

modem status flags.

const int lfc::posixPAL::serial::mstatusRTS = 0x0004
 

modem status flags.

const int lfc::posixPAL::serial::mstatusCTS = 0x0008
 

modem status flags.

const int lfc::posixPAL::serial::mstatusDCD = 0x0010
 

modem status flags.

const int lfc::posixPAL::serial::mstatusRNG = 0x0020
 

modem status flags.


Generated on Sat Jan 26 00:35:09 2002 for LFC2 PAL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001