ReadComm

Syntax

int ReadComm(nCid,lpBuf,nSize)

This function reads the number of characters specified by the nSize parameter from the communication device specified by the nCid parameter and copies the characters into the buffer pointed to by the lpBuf parameter.

Parameter Type/Description  

nCid int Specifies the communication device to be read. The OpenComm function returns this value.  
lpBuf LPSTR Points to the buffer that is to receive the characters read.  
nSize int Specifies the number of characters to be read.  

Return Value

The return value specifies the number of characters actually read. It is less than the number specified by nSize only if the number of characters in the receive queue is less than that specified by nSize. If it is equal to nSize, additional characters may be queued for the device. If the return value is zero, no characters are present.

When an error occurs, the return value is set to a value less than zero, with the absolute value being the actual number of characters read. The cause of the error can be determined by using the GetCommError function to retrieve the error code and status. Since errors can occur when no bytes are present, if the return value is zero, the GetCommError function should be used to ensure that no error occurred.

For parallel I/O ports, the return value will always be zero.