home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
CENVIW.ZIP
/
COMM.LIB
< prev
next >
Wrap
Text File
|
1993-11-14
|
21KB
|
464 lines
// Comm.lib - Windows routines for accessing (open, read, write, etc...)
// the COMM ports (serial ports, printer ports). You may want
// to #include this file in your Cmm source, or just copy out
// the parts that you want.
//
//---- OpenComm(): Open COMM device and get handle to it -------------------
// SYNTAX: int OpenComm(string CommName[,int ReadQueueSize,int WriteQueueSize])
// WHERE: CommName: String name for the device, such as "COM1", "COM2", "LPT1", etc...
// ReadQueueSize, WriteQueueSize: Optional buffer sizes to prepare area
// for data to reside while it is being received or sent. These
// values are ignored by Windows for LPT ports. If these
// are not supplied then they default to the following
#define DEFAULT_COMM_QUEUE_SIZE 500
// RETURN: Returns a handle to the now-open communications device for subsequent
// calls to ReadComm(), WriteComm(), etc. If error, then returns a
// negatvie value, which may be one of the following:
#define IE_BADID (-1) // Invalid or unsupported ID
#define IE_BAUDRATE (-12) // Unsupported baud rate
#define IE_BYTESIZE (-11) // Invalid byte size
#define IE_DEFAULT (-5) // Error in default parameters
#define IE_HARDWARE (-10) // Hardware Not Present
#define IE_MEMORY (-4) // Unable to allocate queues
#define IE_NOPEN (-3) // Device not open
#define IE_OPEN (-2) // Device already open
// NOTES: Call CloseComm before terminating your program. You may want to set
// up an atexit() function to ensure this.
//
//---- CloseComm(): Close COMM device opened with OpenComm ------------------
// SYNTAX: int CloseComm(int CommHandle)
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// RETURN: Returns 0 for success, else a negative error. This call is expected
// to success and so most programmers don't test the return code.
// NOTES: All characters in the output queue are sent before the device is closed.
//
//---- ReadComm(): Read characters from open COMM device ---------------------
// SYNTAX: int ReadComm(int CommHandle,byte[] DestBuffer,int bufferLen[,int CommError])
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// DestBuffer: Data will be read into this buffer, will be created as a
// buffer if it is not already
// bufferLen: Maximum number of bytes to read into buffer
// CommError: If there is a communications error during read, then this will
// be set to the error, else 0 for no error. See CommError
// values below.
// RETURN: Returns number of bytes read, which is 0 up to bufferLen
// NOTES: GetCommError() will always be called, whether or not the optional
// CommError is supplied in this function, to clear port errors. If
// return value is bufferLen, then there may be more characters
// available.
//
//---- GetCommError(): Get COMM port error, and clear error -----------------
// SYNTAX: int GetCommError(CommHandle,[struct CommStatus])
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// CommStatus: an optional structure that will be set with the
// following elements
// bool fCtsHold Transmit is on CTS hold
// bool fDsrHold Transmit is on DSR hold
// bool fRlsdHold Transmit is on RLSD hold
// bool fXoffHold Received handshake
// bool fXoffSent Issued handshake
// bool fEof End of file character found
// bool fTxim Character being transmitted
// int cbInQue count of characters in Rx Queue
// int cbOutQue count of characters in Tx Queue
// RETURN: Return 0 for no error, else an error that may be an OR combination
// of the following:
#define CE_RXOVER 0x0001 // Receive Queue overflow
#define CE_OVERRUN 0x0002 // Receive Overrun Error
#define CE_RXPARITY 0x0004 // Receive Parity Error
#define CE_FRAME 0x0008 // Receive Framing error
#define CE_BREAK 0x0010 // Break Detected
#define CE_CTSTO 0x0020 // CTS Timeout
#define CE_DSRTO 0x0040 // DSR Timeout
#define CE_RLSDTO 0x0080 // RLSD Timeout
#define CE_TXFULL 0x0100 // TX Queue is full
#define CE_PTO 0x0200 // LPTx Timeout
#define CE_IOE 0x0400 // LPTx I/O Error
#define CE_DNS 0x0800 // LPTx Device not selected
#define CE_OOP 0x1000 // LPTx Out-Of-Paper
#define CE_MODE 0x8000 // Requested mode unsupported
// NOTES: Many of the previous function call this function with no CommStatus
// just to clear any potential errors
//
//---- WriteComm: Write characters to open COMM device --------------------
// SYNTAX: int WriteComm(int CommHandle,byte[] SrcBuffer,int bufferLen[,int CommError])
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// SrcBuffer: Data will be written from this buffer
// bufferLen: Number of bytes to written from this buffer
// CommError: If there is a communications error during write, then this will
// be set to the error, else 0 for no error. See CommError
// values below.
// RETURN: Returns number of bytes written, which is 0 up to bufferLen. If less
// than bufferLen then there was certainly an error.
// NOTES: GetCommError() will always be called, whether or not the optional
// CommError is supplied in this function, to clear port errors. If there
// is not enough room in the output queue then some characters will be
// lost, and so if you're not sure there's enough room you may want to
// call GetCommError() to see how much room is available.
//
//
//---- UngetCommChar: Place one character back into the receive queue -------
// SYNTAX: int UngetCommChar(int CommHandle,byte Character)
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// Character: Single character to place back in read queue
// RETURN: Zero if successful, else negative error code
// NOTES: You can only place one character back in the queue. That character
// must be read out of the queue before placing another
//
//
//---- TransmitCommChar: Place character at head of tranmsit queue ---------
// SYNTAX: int TransmitCommChar(int CommHandle,byte Character)
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// Character: Single character for immediate transmission
// RETURN: Zero if successful, else negative error code. Error if previous
// TransmitCommChar() has not been transmitted yet.
//
//
//---- FlushComm: Flush all characters out of receive or transmit queue -----
// SYNTAX: int FlushComm(int CommHandle,int WhichQueue)
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// WhichQueue: 0 to flush transmit queue, else 1 to flush receive queue
// RETURN: Zero if successful, else negative error code for invalid
// CommHandle or invalid WhichQueue.
//
//
//---- SetCommBreak: Suspend transmission and fo to break state -------------
// SYNTAX: int SetCommBreak(int CommHandle)
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// RETURN: Return 0 for success, else negative if CommHandle is invalid
// NOTES: Suspends transmission and places the line in the break state until
// ClearCommBreak() is called.
//
//
//---- ClearCommBreak: Restore transmission and set to non-break state ------
// SYNTAX: int ClearCommBreak(int CommHandle)
// WHERE: CommHandle: value returned from previous successful call to OpenComm()
// RETURN: Return 0 for success, else negative if CommHandle is invalid
//
//
//---- EscapeCommFunction: Perform an extended fun