Serial Port Access


Enumerations

enum  com_dev_t { COMM_DEV_DEFAULT }
enum  {
  COMM_BAUD_110,
  COMM_BAUD_300,
  COMM_BAUD_600,
  COMM_BAUD_1200,
  COMM_BAUD_2400,
  COMM_BAUD_4800,
  COMM_BAUD_7200,
  COMM_BAUD_9600,
  COMM_BAUD_14400,
  COMM_BAUD_19200,
  COMM_BAUD_38400,
  COMM_BAUD_57600,
  COMM_BAUD_115200
}
enum  {
  COMM_DATABITS_5,
  COMM_DATABITS_6,
  COMM_DATABITS_7,
  COMM_DATABITS_8
}
enum  {
  COMM_STOPBITS_10,
  COMM_STOPBITS_15,
  COMM_STOPBITS_20
}
enum  {
  COMM_PARITY_NONE,
  COMM_PARITY_ODD,
  COMM_PARITY_EVEN,
  COMM_PARITY_MARK,
  COMM_PARITY_SPACE
}
enum  {
  COMM_FC_NONE = 0x00,
  COMM_FC_XONXOFF_INPUT = 0x01,
  COMM_FC_XONXOFF_OUTPUT = 0x02,
  COMM_FC_RTSCTS_INPUT = 0x04,
  COMM_FC_RTSCTS_OUTPUT = 0x08,
  COMM_FC_DSRDTR_INPUT = 0x10,
  COMM_FC_DSRDTR_OUTPUT = 0x20
}
enum  WaitResult {
  COMM_WAIT_TIMEOUT,
  COMM_WAIT_DATAREADY,
  COMM_WAIT_ERROR
}
enum  {
  COMM_ERROR_GENERAL = 0x01,
  COMM_ERROR_OVERRUN = 0x02,
  COMM_ERROR_PARITY = 0x04,
  COMM_ERROR_FRAMING = 0x08,
  COMM_ERROR_TIMEOUT = 0x10,
  COMM_STATE_CHANGED = 0x80
}

Functions

com_t com_open (com_dev_t device, long timeout)
bool com_close (com_t port)
int com_read (com_t port, long timeout)
bool com_write (com_t port, int value, long timeout)
int com_wait_for_data (com_t port, long timeout)
bool com_set_config (com_t port, struct COMMConfig *config)
bool com_get_config (com_t port, struct COMMConfig *config)
int com_get_state (com_t port)
bool com_flush (com_t port)
bool com_set_DTR (com_t port, bool state)
bool com_set_RTS (com_t port, bool state)
bool com_get_DTR (com_t port)
bool com_get_RTS (com_t port)


Compounds

     struct   COMMConfigCOM port configuration parameters COM port configuration parameters


Detailed Description

Functions for working with com port. Please see the respective Accessing Serial Port tutorial.


Enumeration Type Documentation

anonymous enum
 

Baud Rates.

Enumeration values:
COMM_BAUD_110   100 baud.
COMM_BAUD_300   300 baud.
COMM_BAUD_600   600 baud.
COMM_BAUD_1200   1200 baud.
COMM_BAUD_2400   2400 baud.
COMM_BAUD_4800   4800 baud.
COMM_BAUD_7200   7200 baud.
COMM_BAUD_9600   9600 baud.
COMM_BAUD_14400   14400 baud.
COMM_BAUD_19200   19200 baud.
COMM_BAUD_38400   38400 baud.
COMM_BAUD_57600   57600 baud (default).
COMM_BAUD_115200   115200 baud.

anonymous enum
 

Number of data bits per byte.

Enumeration values:
COMM_DATABITS_5   5 bits.
COMM_DATABITS_6   6 bits.
COMM_DATABITS_7   7 bits.
COMM_DATABITS_8   8 bits.

anonymous enum
 

Number of stop bits after byte.

Enumeration values:
COMM_STOPBITS_10   1 bit.
COMM_STOPBITS_15   1.5 bits.
COMM_STOPBITS_20   2 bits.

anonymous enum
 

Parity check.

Enumeration values:
COMM_PARITY_NONE   No flow control.
COMM_PARITY_ODD   Odd.
COMM_PARITY_EVEN   Even.
COMM_PARITY_MARK   Mark.
COMM_PARITY_SPACE   Space.

anonymous enum
 

Flow control types.

Enumeration values:
COMM_FC_NONE   No flow control.
COMM_FC_XONXOFF_INPUT   XON/XOFF control of input data.
COMM_FC_XONXOFF_OUTPUT   XON/XOFF control of output data.
COMM_FC_RTSCTS_INPUT   RTS/CTS control of input data.
COMM_FC_RTSCTS_OUTPUT   RTS/CTS control of output data.
COMM_FC_DSRDTR_INPUT   DSR/DTR control of input data.
COMM_FC_DSRDTR_OUTPUT   DSR/DTR control of output data.

anonymous enum
 

Receive errors & special values.

Enumeration values:
COMM_ERROR_GENERAL   General error.
COMM_ERROR_OVERRUN   Overrun error.
COMM_ERROR_PARITY   Parity error.
COMM_ERROR_FRAMING   Framing error.
COMM_ERROR_TIMEOUT   Timeout expired.
COMM_STATE_CHANGED   State pins changed (CTS, DSR or RI). New bit values are specified in data field.

enum WaitResult
 

com_wait_for_data() function results.

Enumeration values:
COMM_WAIT_TIMEOUT   Timeout expired.
COMM_WAIT_DATAREADY   Data ready.
COMM_WAIT_ERROR   General error (e.g. port is absent).

enum com_dev_t
 

Available serial ports.

Enumeration values:
COMM_DEV_DEFAULT   Default serial port.


Function Documentation

bool com_close ( com_t port )
 

Closes an opened serial port.

Parameters:
port   the handle of a port to close.
Returns:
TRUE on success; FALSE otherwise
  #include <cybiko.h>
   ...
   com_t port;
   int data;
   ...
   // open the default serial port, wait a second for availability
   port = com_open( COMM_DEV_DEFAULT, 1000 );
   ...
   // read a byte, wait forever
   data = com_read( port, 0 );
   ...
   // close the port
   com_close( port );
   ...
See also:
com_open

bool com_flush ( com_t port )
 

Flushes serial port I/O buffers.

Parameters:
port   the handle of a serial port.
Returns:
TRUE on success; FALSE otherwise

bool com_get_DTR ( com_t port )
 

Gets the serial port's current DTR state.

Parameters:
port   the handle of a serial port.
Returns:
current DTR state

bool com_get_RTS ( com_t port )
 

Gets serial port's current RTS state.

Parameters:
port   the handle of a serial port.
Returns:
current RTS state

bool com_get_config ( com_t port,
struct COMMConfig * config )
 

Retrieves current configuration of a serial port.

Parameters:
port   the handle of a serial port.
config   COMMConfig structure that is to receive configuration data
Returns:
TRUE on success; FALSE otherwise

int com_get_state ( com_t port )
 

Retrieves current state of a serial port.

Parameters:
port   the handle of a serial port.
Returns:
either of these constants: COMM_ERROR_* or COMM_STATE_CHANGED.

com_t com_open ( com_dev_t device,
long timeout )
 

Opens a serial port for read / write access.

Parameters:
device   a port to open
timeout   the time to allow for the port to open, in milliseconds.
Returns:
the handle to an opened port, or 0 if the port is already opened.
  #include <cybiko.h>
   ...
   com_t port;
   int data;
   ...
   // open the default serial port, wait a second for availability
   port = com_open( COMM_DEV_DEFAULT, 1000 );
   ...
   // read a byte, wait forever
   data = com_read( port, 0 );
   ...
   // close the port
   com_close( port );
   ...
See also:
com_close

int com_read ( com_t port,
long timeout )
 

Reads a byte from a serial port.

Parameters:
port   the handle of a port to read from
timeout   the time to allow for the byte to be read, in milliseconds.
Returns:
on success, the function returns non-negative value of the specified byte; on error, some negative value is returned. Though it can be only -1 for now, this may change in the future
  #include <cybiko.h>
   ...
   com_t port;
   int data;
   ...
   // open the default serial port, wait a second for availability
   port = com_open( COMM_DEV_DEFAULT, 1000 );
   ...
   // read a byte, wait forever
   data = com_read( port, 0 );
   ...
   // close the port
   com_close( port );
   ...
See also:
com_write

bool com_set_DTR ( com_t port,
bool state )
 

Sets serial port's DTR state.

Parameters:
port   the handle of a serial port.
state   desired DTR state
Returns:
TRUE on success; FALSE otherwise

bool com_set_RTS ( com_t port,
bool state )
 

Sets serial port's RTS state.

Parameters:
port   the handle of a serial port.
state   the desired RTS state.
Returns:
TRUE on success; FALSE otherwise.

bool com_set_config ( com_t port,
struct COMMConfig * config )
 

Sets the serial port's configuration.

Parameters:
port   the handle of a serial port.
config   COMMConfig structure containing the configuration data.
Returns:
TRUE on success; FALSE otherwise.

int com_wait_for_data ( com_t port,
long timeout )
 

Waits for data from a serial port.

Parameters:
port   the handle of the serial port in which to look in
timeout   the time to allow for the byte to read, in milliseconds.
Returns:
one of the WaitResult constants.

bool com_write ( com_t port,
int value,
long timeout )
 

Writes a byte to a serial port.

Parameters:
port   the handle of the port to which the byte should be written.
value   the value of the byte to be written; low-order byte is used.
Returns:
TRUE on success; FALSE otherwise.
  #include <cybiko.h>
   ...
   static void my_com_print( com_t port, const char* str )
   {
     int i;
     for( i = 0; str[ i ]; i++ )
     {
       com_write( port, str[ i ], 0 );
     }
   }
   ...
See also:
com_read