# ComRdTerm

int ComRdTerm (int COMPort, char buffer[], int count, int terminationByte);

## Purpose

Reads from the input queue until terminationByte occurs in buffer, count is met, or a timeout occurs. Returns integer value that indicates the number of bytes read from the queue.

ComRdTerm times out whenever the input queue remains empty during an entire timeout period. This occurs when no data has been received during one timeout period. On a timeout, ComRdTerm returns the number of bytes read and sets rs232err to -99. You can set the timeout period by calling SetComTime.

If the read terminates on the termination byte, ComRdTerm neither writes the byte to the buffer nor includes it in count.

If the termination character is a carriage return (CR or decimal 13) or a linefeed (LF or decimal 10), the function handles it as follows:

- If terminationByte = CR, and if the character immediately following CR is LF, ComRdTerm discards the LF in addition to the CR.
- If terminationByte = LF, and if the character immediately following LF is CR, ComRdTerm discards the CR in addition to the LF.

ComRdTerm includes in the return count only the bytes placed in buffer. If ComRdTerm discards CR or LF because it follows an LF or CR, the function does not count it toward satisfying count.

ComRdTerm returns an error if you have not opened the port or you pass an invalid parameter value.

| Note When executing a less than 8 bits transfer, LabWindows/CVI does not guarantee the value of the invalid high bits. For a 7 bits transfer, the value of the 8th bit is undefined. 7 bit value "0x60" can be passed back as "0x60" or "0xE0"(0x60|0x80). This depends on the device driver. Most drivers set the value to 0.

## Parameters

Input
Name | Type | Description
COMPort | integer | A number that indicates the COM port on which to operate. This number is paired with deviceName, which represents the COM port, during the OpenComConfig function call. Default Value: 1—COM1 Valid Range: 1—1,000
count | integer | The number of bytes to read from the selected port.
terminationByte | integer | The byte value used to terminate the read. If the termination character is a carriage return (CR or decimal 13) or a linefeed (LF or decimal 10), the function handles it as follows: If terminationByte = CR, and if the character immediately following CR is LF, ComRdTerm discards the LF in addition to the CR. If terminationByte = LF, and if the character immediately following LF is CR, ComRdTerm discards the CR in addition to the LF. ComRdTerm includes in the return count only the bytes placed in buffer. If ComRdTerm discards CR or LF because it follows an LF or CR, the function does not count it toward satisfying count. ComRdTerm returns an error if you have not opened the port or you pass an invalid parameter value.
Output
Name | Type | Description
buffer | string | The variable in which to store the data that was read from the selected port.

## Return Value

Name | Type | Description
nbytes | integer | Number of bytes read from the input queue. If an error occurs, the return value is a negative error code.
| Note This count does not include the termination byte.