Main Page | Data Structures | File List | Data Fields | Globals

isisserial.c File Reference

ISIS client serial port handling utilties. More...

#include "isisclient.h"

Functions

int OpenSerialPort (char *ttydev)
 Open a serial port.

int SetSerialPort (int ttyFD, int speed, int databits, int stopbits, int parity)
 Set the serial port attributes.

void CloseSerialPort (int ttyFD)
 Close an open serial port.

int WriteSerialPort (int ttyFD, char *msgstr)
 Write a message string to a serial port.

int ReadSerialPort (int ttyFD, char *msgstr)
 Read data from a serial port.

void FlushSerialPort (int ttyFD, int ntimes)
 Read data from a serial port.


Detailed Description

ISIS client serial port handling utilties.

This is a set of simple functions for using serial (tty) ports in an ISIS client application. They encapsulate a number of useful basic functions for opening, closing, setting attributes, reading, writing, and flushing junk from serial ports, relieving writers of ISIS client applications from the pain of getting all the arcane fcntl and termios calls right.

Author:
R. Pogge, OSU Astronomy Dept (pogge@astronomy.ohio-state.edu)
Date:
2003 September 15

Function Documentation

int OpenSerialPort char *  ttydev  ) 
 

Open a serial port.

Parameters:
ttydev Name of the port (e.g., /dev/ttya)
Returns:
File descriptor of the open serial port or -1 if failed
Opens the named serial port for unblocking read/write (the only mode we support), and returns the file descriptor of the open port. All error messages are reported internally. This function only opens the port; port attributes (speed, parity, etc.) need to be set subsequently using the SetSerialPort() call

int SetSerialPort int  ttyFD,
int  speed,
int  databits,
int  stopbits,
int  parity
 

Set the serial port attributes.

Parameters:
ttyFD File descriptor of the open port (see OpenSerialPort())
speed Port speed in baud, one of (1200,2400,4800,9600,19200,38400)
databits Number of data bits (5, 6, 7, or 8)
stopbits Number of stop bits (1 or 2)
parity Port parity, 0 = noparity, 1 = enable parity
Returns:
0 if successful, -1 if an error.
Sets the attributes of the open serial port: speed, data bits (character size mask), stop bits (1 or 2), and partiy (no parity, or parity generation on output/checking on input). The normal mode for most tty ports we use in the data-taking system are set to
9600 baud, 8 data bits, 1 stop bit, no parity
corresponding to speed=9600, databits=8, stopbits=2, parity=0.

The port must have already been opened using OpenSerialPort().

See also:
OpenSerialPort()

void CloseSerialPort int  ttyFD  ) 
 

Close an open serial port.

Parameters:
ttyFD file descriptor of an open serial port (see OpenSerialPort())
Closes an open serial port. Used as a simple wrapper for the close() function to provide a logical functional opposite to OpenSerialPort().

int WriteSerialPort int  ttyFD,
char *  msgstr
 

Write a message string to a serial port.

Parameters:
ttyFD file descriptor of an open serial port (see OpenSerialPort())
msgstr message string to write
Returns:
Number of bytes written if successful, 0 or -1 if unsuccessful.
Writes the message string provided to the serial port given by ttyFD. This port must have been previously opened and setup using the OpenSerialPort() and SetSeriaPort() functions.

See also:
ReadSerialPort()

int ReadSerialPort int  ttyFD,
char *  msgstr
 

Read data from a serial port.

Parameters:
ttyFD file descriptor of an open serial port (see OpenSerialPort())
msgstr message string to carry the input string
Returns:
Number of bytes read if successful, 0 or -1 if unsuccessful.
Reads characters from the serial port ttyFD and loads them into msgstr. This port must have been previously opened and setup using the OpenSerialPort() and SetSeriaPort() functions. This function is most often used in the context of a select() loop to watch for activity on one or more open serial ports, though it may be used generally as required.

See also:
WriteSerialPort()

void FlushSerialPort int  ttyFD,
int  ntimes
 

Read data from a serial port.

Parameters:
ttyFD file descriptor of an open serial port (see OpenSerialPort())
ntimes number of times to read the port for flushing
Reads the serial port ntimes to attempt to flush any extraneous port junk. This port must have been previously opened and setup using the OpenSerialPort() and SetSeriaPort() functions. Assumes that the buffer size is at least the default BUFSIZ defined in stdio.h Whether or not this is a good idea remains to be seen.


Generated on Thu Jul 22 20:28:29 2004 for ISIS Client API by doxygen 1.3.7