Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

ComWrite

  • Last UpdatedFeb 02, 2024
  • 2 minute read

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.

It is highly recommended that you only use ComWrite in the context where no existing driver is using the same port.

For high speed transports like TCPIP, it is recommended that timeout be set to 0.

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

Syntax

ComWrite(hPort, sBuffer, iLength, iTimeOut)

hPort:

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

sBuffer:

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

iLength:

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.

iTimeOut:

The timeout for the write to complete in seconds.

• If iTimeOut = 0 (zero), the characters are copied to the communication buffer and the function returns immediately - the characters are transmitted in the background.

• If iTimeOut > 0, the function returns after this number of seconds in Port mode 0 (and sets error 7 which is the task timeout code), or as soon as the write occurs in Port mode 1. In mode 1 if the write occurred, there will be no error.

• If iTimeOut < 0, the function waits forever to transmit the characters.

Return Value

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

ComOpen, ComClose, ComRead, StrGetChar

Example

See ComOpen.

See Also

Communication Functions

In This Topic
TitleResults for “How to create a CRG?”Also Available in