home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HomeWare 14
/
HOMEWARE14.bin
/
os2
/
cenv2_19.arj
/
COMM.LIB
< prev
next >
Wrap
Text File
|
1994-03-08
|
3KB
|
81 lines
// Comm.lib - Serial communications library
// ver.1
//
//**** CommOpen(): Open Comm port
// SYNTAX: int CommOpen(string CommPortName,int Error)
// WHERE: CommPortName: port name, such as "COM1" or "COM2"
// Error: Set errorcode if returning 0
// RETURN: Handle for this comm port. NULL if could not open
// NOTES: You should be sure to close com port when finished
//
//
//**** CommClose(): Close Comm port
// SYNTAX: void CommClose(int CommHandle)
// WHERE: CommHandle: value returned from previous call to CommOpen
//
//
//**** CommWrite(): Write to comm port
// SYNTAX: int CommWrite(int CommHandle,byte[] BufferArea,int BufferLength,int BytesWritten)
// WHERE: CommHandle: value returned from previous call to CommOpen
// BufferArea: data bytes to write
// BufferLength: How many bytes to write
// BytesWritten: Set to how many bytes were written
// RETURN: 0 for success, else error code
//
//
//**** CommRead(): Read from comm port
// SYNTAX int CommRead(int CommHandle,byte[] BufferArea,int MaxBufferLength,int BytesRead)
// WHERE: CommHandle: value returned from previous call to CommOpen
// BufferArea: data bytes to read to (created if necessary)
// MaxBufferLength: Maximum bytes to read
// BytesRead: Set to how many bytes were read
// RETURN: 0 for success, else error code
//
//
#include <FileIO.lib>
#include <DevIOctl.lib>
/*****************************************************************
********* END OF DESCRIPTION FOR COMM.LIB *********
*****************************************************************/
#define COMM_IOCTL_CATEGORY 1
CommOpen(CommPortName,Error)
{
Error = DosOpen(CommPortName,_RetCommFileHandle,_ActionTaken,0,FILE_NORMAL,
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,NULL );
if ( Error )
_RetCommFileHandle = 0;
return _RetCommFileHandle;
}
CommClose(CommHandle)
{
DosClose(CommHandle);
}
CommRead(CommHandle,BufferArea,BufferLength,BytesRead)
{
return DosRead(CommHandle,BufferArea,
min(QueryCharsInReceiveQueue(CommHandle),BufferLength),
BytesRead);
}
CommWrite(FileHandle,BufferArea,BufferLength,BytesWritten)
{
return DosWrite(FileHandle,BufferArea,BufferLength,BytesWritten);
}
QueryCharsInReceiveQueue(CommHandle)
{
#define QUERY_RCV_FUNCTION 0x68
_retSize = 0;
_rc = DosDevIOCTL(CommHandle,COMM_IOCTL_CATEGORY,QUERY_RCV_FUNCTION,
NULL,0,0,_data,4,_retSize);
return ( 0 == _rc && 4 == _retSize ) ? BLObGet(_data,0,UWORD16) : 0 ;
}