int ComWrtByte (int COMPort, int byte);
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. The function returns immediately without waiting for the byte to be transmitted out through the serial port.
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.
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 |
byte | integer | The value of the byte to write to the selected port. Only the low-order byte is significant. |
Name | Type | Description |
nbytes | integer | 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. |