LabWindows/CVI

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

ComWrtByte

int ComWrtByte (int portNumber, int byte);

Purpose

Writes a byte to the output queue of a COM port. The byte written is the low-order byte of the integer.

ComWrtByte returns a 1 to indicate the operation is successful or a negative error code to indicate the operation failed. In an output buffer has been configured for the port, this function returns immediately after buffering the byte, without waiting for it to be sent out of the serial port. If the output queue has been disabled, this function does not return until the transfer completes.

ComWrtByte times out whenever the library does not write any bytes from the output queue to the COM port during an entire timeout period. This 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. It also can occur if you enable hardware handshaking and the CTS line is not asserted. On a timeout, ComWrtByte returns 0 and sets rs232err to -99.

ComWrtByte sends bytes from the output queue to the serial device under interrupt control without program intervention. If you close the port before all bytes are sent, you lose the bytes left in the queue. To guarantee that all bytes are removed from the output queue before you close the port, call GetOutQLen. GetOutQLen returns the number of bytes left in the output queue.

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

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
byte int The value of the byte to write to the selected port. Only the low-order byte is significant.

Return Value

Name Type Description
BytesWritten int The actual number of bytes written to the output queue.

0—a timeout occurred
1—one byte placed in the output queue

If a timeout occurs the return value is the number of bytes written. If any other 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

Example

Refer to rs232\serial.cws for an example of using the ComWrtByte function.

Log in to get a better experience