LabWindows/CVI

Content Type
Programming Language
Current manual

ComToFile

int ComToFile (int portNumber, int fileHandle, int count, int terminationByte);

Purpose

Reads from the input queue of a specified COM port and writes the data to the file specified by fileHandle. ComToFile reads bytes from the input queue until it satisfies count, encounters terminationByte, a timeout occurs, or an error occurs. This function returns the number of bytes successfully written to the file.

ComToFile times out whenever the input queue remains empty for an entire timeout period. On a timeout, ComToFile returns the number of bytes actually written to the COM port and sets rs232err to -99. You can set the timeout period by calling SetComTime.

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

Note   When executing a less than 8 bits transfer, 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 device driver. Most drivers set the value to 0.

Parameters

Input
Name Type Description
portNumber int A number that indicates the COM port on which to operate.

This number maps to the COM port specified by deviceName in the call to OpenCom or OpenComConfig. The portNumber 1, for example, may not necessarily map to COM1.

(Linux) The portNumber 1, for example, may not necessarily map to /dev/ttyS0.

Valid Range: 1—1,000
fileHandle int The file handle to which the data is written.
count int The number of bytes to read from the selected port.

If count is 0, ComToFile ignores it and terminates on terminationByte or on an error.
terminationByte int The byte value used to terminate the read.

Note   The termination byte is never written to the file.

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 terminationByte equals a linefeed and the character immediately following the linefeed is a carriage return, then both the linefeed and the carriage return are discarded. If terminationByte is valid, the function stops when it encounters a byte that has the value of terminationByte; ComToFile removes the termination byte from the input queue and does not write it to the file.

Return Value

Name Type Description
BytesRead int The actual number of bytes written to the file.

Note   This count does not include the termination byte.
If a timeout occurs, the function returns the number of bytes written. If an error occurs, the return value is a negative error code.

Additional Information

Library: RS-232 Library

Include file: rs232.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?

Previous

ComRdByte

Next

ComWrt

Previous

ComRdByte

Next

ComWrt

Log in to get a better experience

Help us improve your future ni.com experience.

What are you trying to do?

Submit