# ComFromFile

int ComFromFile (int COMPort, int fileHandle, int count, int terminationByte);

## Purpose

Reads from the specified file and writes to the output queue of a COM port.

ComFromFile times out whenever the library does not write any bytes from the output queue to the COM port during an entire timeout period. This action can occur if you enable XON/XOFF, the device sends an XOFF character without sending the follow-on XON character, and the output queue is full. The timeout also can occur if you enable hardware handshaking and the CTS line is not asserted. On a timeout, ComFromFile returns the number of bytes actually read from the COM port and sets rs232err to -99. You can set the timeout period by calling SetComTime.

To guarantee that ComFromFile removes all bytes from the output queue before it closes the port, call GetOutQLen to determine the number of bytes left in the output queue. If you close the port before ComFromFile sends every byte, you lose the bytes left in the queue.

ComFromFile returns an error code if you have not opened the port, if you pass an invalid parameter value, or if a file read error occurs.

## 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
fileHandle | integer | The file handle that contains the data to write to the output queue.
count | integer | The number of bytes to write to the selected port. If count is 0, ComFromFile ignores the value and the function terminates when terminationByte or EOF is encountered, or an error occurs.
terminationByte | integer | The byte value used to terminate the write. If the terminationByte is -1, ComFromFile ignores the value, and the function terminates when all bytes have been written, EOF is encountered, or an error occurs.
| Note terminationByte is never written to the output queue.
If terminationByte equals a carriage return and the character immediately following the carriage return is a linefeed, then both the carriage return and linefeed are discarded. If the termination byte equals a linefeed and the character immediately following the linefeed is a carriage return, then both the linefeed and the carriage return are discarded.

## Return Value

Name | Type | Description
nbytes | integer | The actual number of bytes written to the output queue.
| Note This count does not include the termination byte.
If a timeout occurs the return value is the number of bytes written to the output queue. If any other error occurs, the return value is a negative error code.