Cicode Programming Reference > Cicode Function Categories > Communication Functions > ComWrite


Writes characters to a communication port. The characters are written from the string buffer to the port. If the characters have not been transmitted after the specified timeout, the function returns with a timeout error. If the timeout is 0, the function returns immediately and the characters are transmitted in the background.

ComWrite() does not treat the buffer as a true string, but rather as an array of characters of the length specified - you can send any character to the communication port. Use the StrSetChar() function to build the buffer. Do not call ComWrite() while another ComWrite() is still pending on the same port, because it can produce unexpected results.

You use the iLength variable to specify the length of the buffer, or the maximum number of characters to write when ComWrite() is called. When ComWrite() returns, iLength is reset to zero.

This function is a blocking function. It blocks the calling Cicode task until the operation is complete.

This function can only be called from an I/O Server.


ComWrite(hPort, sBuffer, iLength, iTimeOut)


The communication port handle, returned from the ComOpen() function. This handle identifies the table where all data on the associated communication port is stored.


The buffer from which to write the characters. Must be a String type variable.


The number of characters to write from the buffer. The maximum number of characters you can write is 128. Must be a Long type variable.


The timeout for the write to complete.

Return Value

0 (zero) if the write is successful, otherwise an error code is returned.

Related Functions

ComOpen, ComClose, ComRead, StrGetChar


See ComOpen

See Also

Communication Functions

Published June 2018