pyuaf.util.opcuastatuscodes

This module contains a very long list of numerical OPC UA status codes, as defined by the OPC UA standard.

The UAF status codes (which are defined in the pyuaf.util.statuscodes module) are not to be confused with the OPC UA status codes (which are defined in the pyuaf.util.opcuastatuscodes module).

  • The OPC UA status codes are 32-bit integers defined by the OPC UA standard. They provide low-level information about the OPC UA communication. Whenever you see an OPC UA status code (often as an attribute called opcUaStatusCode), it is produced by the SDK or the Stack (in other words, not by the UAF).
  • The UAF status codes are 32-bit integers defined by the UAF. They provide high-level information. For all “bad” status codes (those ending with Error), there is a corresponding error defined in pyuaf.util.errors. For instance, a pyuaf.util.statuscodes.InvalidServerUriError corresponds to a pyuaf.util.errors.InvalidServerUriError. UAF status codes are used exclusively to determine which error is held by a pyuaf.util.Status object. For instance, if the statusCode attribute of a pyuaf.util.Status instance is equal to pyuaf.util.statuscodes.InvalidServerUriError, then the Status object in fact holds a pyuaf.util.errors.InvalidServerUriError instance.

The list of OPC UA status codes is not shipped with the UAF, as it is generated from the stack header files.

The list is way too long to document here, so you are referred to the OPC UA specification documents.

All codes start with an OpcUa_ prefix.

Here are some examples:

opcuastatuscodes.OpcUa_Good = 0
opcuastatuscodes.OpcUa_GoodMoreData = 10878976
opcuastatuscodes.OpcUa_GoodNoData = 10813440
opcuastatuscodes.OpcUa_GoodShutdownEvent = 11010048
opcuastatuscodes.OpcUa_Uncertain = 1073741824
opcuastatuscodes.OpcUa_UncertainReferenceOutOfServer = 1080819712
opcuastatuscodes.OpcUa_Bad = 2147483648
opcuastatuscodes.OpcUa_BadArgumentsMissing = 2155216896
opcuastatuscodes.OpcUa_BadAttributeIdInvalid = 2150957056
opcuastatuscodes.OpcUa_BadConnectionClosed = 2158886912
opcuastatuscodes.OpcUa_BadCertificateRevoked = 2149384192
opcuastatuscodes.OpcUa_BadCertificateInvalid = 2148663296
opcuastatuscodes.OpcUa_BadCertificateUntrusted = 2149187584
opcuastatuscodes.OpcUa_BadUserAccessDenied = 2149515264
opcuastatuscodes.OpcUa_BadMaxAgeInvalid = 2154823680
opcuastatuscodes.OpcUa_BadInvalidArgument = 2158690304
opcuastatuscodes.OpcUa_BadNoData = 2157641728

And here’s a little script you can use to print all status codes to the standard out (“stdout”, e.g. the Windows DOS Prompt or the Linux shell) or write them to a file:

# examples/pyuaf/util/how_to_print_all_opcua_status_codes.py
"""
Example: how to print all OPC UA status codes
====================================================================================================
""" 

import pyuaf

# create a list that will contain tuples of (<codeName>, <codeIdentifier>)
# such as ('OpcUa_BadTimeout', -2146828288)
statusCodes = []

# add all identifier items from the module to the list
for item in pyuaf.util.opcuastatuscodes.__dict__.items():
    if isinstance(item[1], int) and item[0][0] != '_':
        statusCodes.append(item)

# sort the list
statusCodes = sorted(statusCodes, key=lambda x: x[1])

# modify these flags to instruct the script to print the items to
# the screen and/or to write them to a file:
printToScreen = True
writeToFile   = False

# print the items to the screen if necessary
if printToScreen:
    for item in statusCodes:
        print("%s %d" %item)

# write the items to a file if necessary
if writeToFile:
    f = open('opcuastatuscodes.txt', 'w')
    for item in statusCodes:
        f.write("%s %d\n" %item)
    f.close()