Read and Write Services

To write to a communications resource, call the _VCOMM_WriteComm service. This service writes the specified data to the transmit queue and returns immediately. Always check both the return value of this service and the number of bytes written. If there is insufficient space in the transmit queue, the number of bytes written is less than the number requested - yet the return value is TRUE. In this case, call the _VCOMM_ClearCommError service to detect and reset any communications errors that may have occurred.

For communications devices that do not use transmit queues, such as LPT ports, _VCOMM_WriteComm actually writes the data to the device before returning. If a write time-out occurs, the number of bytes written is less than the number requested and the return value is FALSE.

To send high-priority characters, such as event characters, you can use the _VCOMM_TransmitCommChar service. This service sends a single character ahead of any data in the transmit queue. Until the hardware is ready to send the character, most port drivers store it in a special one-character buffer. If a character specified in a previous call to this service is still waiting to be sent, the service returns FALSE.

To read from a communications resource, call the _VCOMM_ReadComm service. This service reads the specified amount of data from the receive queue and returns immediately. Always check both the return value of this service and the number of bytes read. If the receive queue does not contain enough data, the number of bytes read is less than the number requested - yet the return value is TRUE. If the number of bytes read is zero, call _VCOMM_ClearCommError to detect and reset any communications errors that may have occurred.

For output-only devices, such as LPT ports, _VCOMM_ReadComm returns TRUE with zero bytes read. For other communications devices that do not uses receive queues, _VCOMM_ReadComm actually reads the data from the device before returning. If a read time-out occurs, the number of bytes read is less than the number requested and the return value is FALSE.

You can check the status of the transmit and receive queues by calling the _VCOMM_GetCommQueueStatus service; this service fills in a _COMSTAT structure. You can discard the contents of the transmit or receive queue by calling the _VCOMM_PurgeComm service.

See Also

_COMSTAT, _VCOMM_ClearCommError, _VCOMM_GetCommQueueStatus, _VCOMM_PurgeComm, _VCOMM_ReadComm, _VCOMM_TransmitCommChar, _VCOMM_WriteComm