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

AVEVA™ Plant SCADA

CtAPI Synchronous Operation

  • Last UpdatedJul 13, 2023
  • 3 minute read

The Plant SCADA CTAPI supports both synchronous and asynchronous (or overlapped) operations. The ctCiCode, ctListRead, and ctListWrite functions can be performed either synchronously or asynchronously. The ctTagRead and ctTagWrite functions can be performed synchronously only.

When a function is executed synchronously, it does not return until the operation has been completed. This means that the execution of the calling thread can be blocked for an indefinite period while it waits for a time-consuming operation to finish. A function called for an overlapped operation can return immediately, even though the operation has not been completed. This enables a time-consuming I/O operation to be executed in the background while the calling thread is free to perform other tasks. For example, a single thread can perform simultaneous operations on different handles, or even simultaneous read and write operations on the same handle. To synchronize its execution with the completion of the overlapped operation, the calling thread uses the ctGetOverlappedResult function or one of the wait functions to determine when the overlapped operation has been completed. You can also use the ctHasOverlappedIoCompleted macro to poll for completion.

To call a function to perform an overlapped operation, the calling thread needs to specify a pointer to a CTOVERLAPPED structure. If this pointer is NULL, the function return value may incorrectly indicate that the operation completed. The CTOVERLAPPED structure needs to contain a handle to a manual-reset, not an auto-reset event object. The system sets the state of the event object to non-signaled when a call to the I/O function returns before the operation has been completed. The system sets the state of the event object to signaled when the operation has been completed.

When a function is called to perform an overlapped operation, it is possible that the operation will be completed before the function returns. When this happens, the results are handled as if the operation had been performed synchronously. If the operation was not completed, however, the function's return value is FALSE, and the GetLastError() function returns ERROR_IO_PENDING.

A thread can manage overlapped operations by either of two methods:

  • Use the ctGetOverlappedResult function to wait for the overlapped operation to be completed.

  • Specify a handle to the CTOVERLAPPED structure's manual-reset event object in one of the wait functions and then call ctGetOverlappedResult after the wait function returns. The ctGetOverlappedResult function returns the results of the completed overlapped operation, and for functions in which such information is appropriate, it reports the actual number of bytes that were transferred.

When performing multiple simultaneous overlapped operations, the calling thread needs to specify a CTOVERLAPPED structure with a different manual-reset event object for each operation. To wait for any one of the overlapped operations to be completed, the thread specifies the manual-reset event handles as wait criteria in one of the multiple-object wait functions. The return value of the multiple-object wait function indicates which manual-reset event object was signaled, so the thread can determine which overlapped operation caused the wait operation to be completed.

You can cancel a pending asynchronous operation using the ctCancelIO function. Pending asynchronous operations are canceled when you call ctClose.

Note: Due to a session isolation feature introduced in an earlier version of Windows, CTAPI applications running as a service may be unable to connect. To overcome this, in the CTAPI application, specify an IP Address (which can be 127.0.0.1) and a valid username and password.

See Also

Read Data Using the CtAPI Functions

Related Links
TitleResults for “How to create a CRG?”Also Available in