ReadComm

2.x

  int ReadComm(idComDev, lpvBuf, cbRead)    
  int idComDev; /* identifier of device to read from */
  void FAR* lpvBuf; /* address of buffer for read bytes */
  int cbRead; /* number of bytes to read */

The ReadComm function reads up to a specified number of bytes from the given communications device.

Parameters

idComDev

Specifies the communications device to be read from. The OpenComm function returns this value.

lpvBuf

Points to the buffer for the read bytes.

cbRead

Specifies the number of bytes to be read.

Return Value

The return value is the number of bytes read, if the function is successful. Otherwise, it is less than zero and its absolute value is the number of bytes read.

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

Comments

When an error occurs, the cause of the error can be determined by using the GetCommError function to retrieve the error value 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.

The return value is less than the number specified by the cbRead parameter only if the number of bytes in the receiving queue is less than that specified by cbRead. If the return value is equal to cbRead, additional bytes may be queued for the device. If the return value is zero, no bytes are present.

See Also

GetCommError, OpenComm