LabWindows/CVI

Table of Contents
  • LabWindows/CVI Fundamentals
  • Creating Applications
  • Distributing Applications
  • Library Reference
  • Programmer Reference
  • Hardware Information

ComRd

int ComRd (int portNumber, char buffer[], size_t count);

Purpose

Reads count bytes from the input queue of the port you specify and stores them in buffer. Returns on timeout or when count bytes have been read. Returns an integer value that indicates the number of bytes read from queue.

Note Note  This function does not append a terminating ASCII NUL byte to the value in the buffer parameter.

ComRd times out when the input queue remains empty for an entire timeout period. On a timeout, ComRd returns the number of bytes actually written and sets rs232err to -99. To set the timeout period, call SetComTime. ComRd returns an error code if you have not opened the port or if you pass an invalid parameter value.

Example Code

/* Read 100 bytes from input queue of COM1 into buf. */
int n;
char buf[100];
.
.
.
n = ComRd (1, buf, 100);
if (n != 100)

/* Timeout or error occurred before read completed. */;

Note   When executing a transfer less than 8 bits, 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
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
count size_t The number of bytes to read from the selected port. Specifying 0 takes no bytes from queue.

An error is returned if you pass a value greater than INT_MAX.
Output
Name Type Description
buffer char [] The variable in which to store the data that was read from the selected port.
Note Note  This function does not append a terminating ASCII NUL byte to the value in this parameter.

Return Value

Name Type Description
BytesRead int Number of bytes read from the input queue.

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

Examples

Refer to the following examples that use the ComRd function:

  • rs232\commcallback.cws

    Open example
  • rs232\serial.cws

    Open example

Log in to get a better experience