int ComWrt (int COMPort, char buffer[], int count);
Writes count bytes to the output queue of the specified port.
ComWrt returns an integer value that indicates the number of bytes placed in the queue. This function returns immediately without waiting for the bytes to be sent out of the serial port.
ComWrt 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, ComWrt returns the number of bytes actually written and sets rs232err to -99.
ComWrt 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 that remain 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 that remain in the output queue.
ComWrt returns an error if you have not opened the port or if you pass an invalid parameter value.
/* Place the string "Hello, world!" in the output queue of */
/* COM2 and check if operation was successful. */
if (ComWrt (2, "Hello, World!", 13) != 13)
/* Operation was unsuccessful. */;
or
char buf[100];
Fmt(buf,"%s","Hello, World!");
if (ComWrt (2, buf, 13) != 13)
/* Operation was unsuccessful. */;
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 |
buffer | string | The variable in which to store the data to write to the selected port. |
count | integer | The number of bytes to write to the selected port. |
Name | Type | Description |
nbytes | integer | The actual number of bytes written to 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. |