COMM-DRV/Lib: OpenComPort() – Read one byte from serial port


This function opens a standard COM port. Under Windows it opens standard Windows COM ports as seen in the Device Manager.


port = OpenComPort(ComPort,InbufLen,OutbufLen);

On Entry-

int ComPort;

Comport to open. (1 for COM1, 2 for COM2, 3 for COM3, and so on)

long InbufLen;

Length of input buffer.

long OutbufLen;

Length of output buffer.

On Exit-

int port;

If port is a positive number then this is the port number/handle that will be used by all functions referencing the output port.

If port is negative then the return is the negation of the error code as defined in Appendix C.

See Also-



#include <comm.h>

int Port;
int Stat;

if ((Port=OpenComPort(1,1024,1024)) < 0)
print(“Error # %d opening serial port\n”,-Port);

//Take corrective action

//Set line characteristics
Stat = SetPortCharacteristics(Port,BAUD9600,PAR_NONE,LENGTH_8,STOPBIT_1,PROT_NONNON);