Technical Reference > CtAPI Functions > Error Codes

Error Codes

The error codes returns from the CTAPI functions are the Microsoft WIN 32 error codes. These error codes are documented in the Microsoft SDKs. Where the error code is a CitectSCADA special error code, the error code is added to the value -ERROR_USER_DEFINED_BASE.

Note: If a CTAPI function returns the error 233, it typically means the connection to the client is not established. However, it may also mean the client has not logged in correctly. confirm both scenarios.

Example

int bRet = ctTagWrite(hCTAPI, "SP123", "12.34");
if (bRet == 0) {
dwStatus = GetLastError();
if (dwStatus < ERROR_USER_DEFINED_BASE) {
// Microsoft error codes see ERROR.H
} else {
short status;
// status is the
CitectSCADA error codes, see CitectSCADA help
status = dwStatus - ERROR_USER_DEFINE_BASE;
}
}

The following defines have been declared to make this checking easier:

IsCitectError(dwStatus)				 // test if CitectSCADA 
error
WIN32_TO_CT_ERROR(dwStatus) // Convert
to CitectSCADA status

For example:

if (IsCitectError(dwStatus)) {
short status;
// status is the
CitectSCADA error codes, see CitectSCADA help
status = WIN32_TO_CT_ERROR(dwStatus);
}

If the connection is lost between your application and CitectSCADA, you need to close the connection and reopen. An inoperative connection will be shown by the returning of a Microsoft error code. If a CitectSCADA status error is returned, the connection has not been lost. The command requested is invalid and the connection does not have to be closed and reopened.

int bRet = ctTagWrite(hCTAPI, "SP123", "12.34");
if (bRet == 0) {
dwStatus = GetLastError();
if (dwStatus < ERROR_USER_DEFINED_BASE) {
ctClose(hCTAPI);
hCTAPI = ctOpen(NULL, NULL, NULL, 0);
while (hCTAPI == NULL) {
Sleep(2000); // wait a while
hCTAPI = ctOpen(NULL, NULL, NULL, 0);
}
}
}

When the connection between your application and CitectSCADA is lost, any pending overlapped commands will time out and be canceled by CTAPI. You need to destroy handles which are associated with the connection.

In Version 5.10, the CT_OPEN_RECONNECT mode was added to ctOpen(). When this mode is enabled, CTAPI will attempt to re-establish the connection to CitectSCADA if a communication interruption occurs. Handles created with the connection will remain valid when the connection is re-created. While the connection is down, functions will be ineffective and will report errors.

See Also