pyuaf.util
¶
SUMMARY of submodules:
SUMMARY of classes:
See sidebar.
class Address¶
-
class
pyuaf.util.
Address
(*args)¶ An Address points to a node within an server address space by means of an absolute address (an ExpandedNodeId) or by means of a relative address (a path relative to another address).
An “address” is a term defined by the UAF, and not by the OPC UA standard. It’s basically a union class that holds the information to identify a node within an address space. Several addresses can all point to the same node.
A relative address may point to other relative addresses. More formally, the starting point of an Address based on a relative path, may also be an Address based on a relative path in turn. This way you can define large and complex hierarchies of relative addresses, with just a single absolute address (based on an ExpandedNodeId) as the starting point.
Methods:
-
__init__
(*args)¶ Construct a new Address by providing either
- an
ExpandedNodeId
- another
Address
(the starting point) and aRelativePath
(the path).
Usage example:
>>> import pyuaf >>> from pyuaf.util import Address, NodeId, ExpandedNodeId, RelativePathElement, QualifiedName, BrowsePath >>> # the following ways of constructing a Address are possible: >>> address0 = Address( ExpandedNodeId("someId", "someNsUri", "someServerUri") ) >>> address1 = Address( NodeId("someId", "someNsUri"), "someServerUri" ) >>> address2 = Address( address0, [RelativePathElement(QualifiedName("someName", "someNsUri"))] ) >>> address3 = Address( address1, [RelativePathElement(QualifiedName("someOtherName", 3))] ) >>> address3 = Address( BrowsePath( ExpandedNodeId("someId", "someNsUri", "someServerUri"), ... [RelativePathElement(QualifiedName("someOtherName", 3))] ) ) >>> # you may also provide a single RelativePathElement in case the relative path contains just >>> # one element: >>> address4 = Address( address1, RelativePathElement(QualifiedName("someOtherNameToo", 3)) )
- an
-
isExpandedNodeId
()¶ Check if the address is defined as an ExpandedNodeId.
Returns: True if the address is based on an ExpandedNodeId
(and you’re allowed to callgetExpandedNodeId()
), False if not.Return type: bool
-
isRelativePath
()¶ Check if the address is defined as a RelativePath.
Returns: True if the address is based on a RelativePath
and anotherAddress
(and you’re allowed to callgetStartingAddress()
andgetRelativePath()
), False if not.Return type: bool
-
getExpandedNodeId
()¶ Get the ExpandedNodeId in case
isExpandedNodeId()
returns True.Returns: The ExpandedNodeId corresponding with this Address. Return type: ExpandedNodeId
-
getRelativePath
()¶ Get the RelativePath in case
isRelativePath()
returns True.Returns: The RelativePath corresponding with this Address, as a tuple
ofRelativePathElement
.
-
getStartingAddress
()¶ Get a pointer (not a copy of the actual object itself!) to the starting address in case
isRelativePath()
returns True.Returns: A reference to the starting address. Return type: Address
-
class ApplicationDescription¶
-
class
pyuaf.util.
ApplicationDescription
(*args)¶ An ApplicationDescription instance describes a Server or Client or ClientAndServer, or a DiscoveryServer.
Methods:
Attributes:
-
applicationUri
¶ The application URI as a string (type
str
).
-
productUri
¶ The product URI as a string (type
str
).
-
applicationName
¶ The application name as a localized text (type
LocalizedText
).
-
applicationType
¶ The application type as an int (as defined in
pyuaf.util.applicationtypes
).
-
gatewayServerUri
¶ The gateway server URI as a string (type
str
).
-
discoveryProfileUri
¶ The discovery profile URI as a string (type
str
).
-
discoveryUrls
¶ The discovery URLs as a list of strings (type
StringVector
).
-
class ApplicationDescriptionVector¶
-
class
pyuaf.util.
ApplicationDescriptionVector
(*args)¶ An ApplicationDescriptionVector is a container that holds elements of type
pyuaf.util.ApplicationDescription
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofApplicationDescription
.Usage example:
>>> import pyuaf >>> from pyuaf.util import ApplicationDescriptionVector, ApplicationDescription >>> # construct a ApplicationDescriptionVector without elements: >>> descriptions = ApplicationDescriptionVector() >>> noOfElements = len(descriptions) # will be 0 >>> descriptions.append(ApplicationDescription()) >>> noOfElements = len(descriptions) # will be 1 >>> descriptions.resize(4) >>> noOfElements = len(descriptions) # will be 4 >>> description0 = descriptions[0] >>> # you may construct an ApplicationDescriptionVector from a regular Python list: >>> otherDescriptions = ApplicationDescriptionVector( [ApplicationDescription(), ApplicationDescription()] )
class BrowsePath¶
-
class
pyuaf.util.
BrowsePath
(*args)¶ A BrowsePath holds a path from a resolved starting node (an ExpandedNodeId) to another node within the address space.
Methods:
-
__init__
([startingExpandedNodeId[, relativePath]])¶ Construct a new BrowsePath.
You may optionally provide a starting point for the browse path (a
pyuaf.util.ExpandedNodeId
) and optionally provide a relative path (which is aRelativePath
, resembling alist
ofRelativePathElement
).
-
Attributes:
-
startingExpandedNodeId
¶ The starting point (as an
ExpandedNodeId
)) of the relative path.
-
relativePath
¶ The relative path as a list of qualified names The type of this attribute is
RelativePath
, which resembles alist
ofRelativePathElement
.
-
class ByteStringVector¶
-
class
pyuaf.util.
ByteStringVector
(*args)¶ An ByteStringVector is a container that holds elements of the built-in Python type
bytearray
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofbytearray
.Usage example:
>>> import pyuaf >>> from pyuaf.util import ByteStringVector >>> # construct a ByteStringVector without elements: >>> vec = ByteStringVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(bytearray("abcd")) >>> noOfElements = len(vec) # will be 1 >>> vec.resize(4) >>> noOfElements = len(vec) # will be 4 >>> # vec[0] was already assigned to bytearray("abcd") >>> vec[1] = bytearray("efgh") >>> vec[2] = bytearray("ijkl") >>> vec[3] = bytearray("mnop")
class DataChangeFilter¶
-
class
pyuaf.util.
DataChangeFilter
(*args)¶ A DataChangeFilter specifies a deadband filter for monitored data items.
Methods:
Class attributes:
for the dead band type:
-
DeadBandType_None
= 0¶ An
int
identifying the kind of deadband: in this case no deadband at all!
-
DeadBandType_Absolute
= 1¶ An
int
identifying the kind of deadband: in this case an absolute deadband.
-
DeadBandType_Percent
= 2¶ An
int
identifying the kind of deadband: in this case a relative deadband (in percent).
-
for the data change trigger:
-
DataChangeTrigger_Status
= 0¶ An
int
identifying the kind of trigger: in this case trigger when the status changes!
-
DataChangeTrigger_StatusValue
= 1¶ An
int
identifying the kind of trigger: in this case trigger when the status or the value changes!
-
DataChangeTrigger_StatusValueTimestamp
= 2¶ An
int
identifying the kind of trigger: in this case trigger when the status or the value or the timestamp changes!
-
Attributes:
-
trigger
¶ The kind of trigger, as one of these
int
values:DataChangeTrigger_Status
orDataChangeTrigger_StatusValue
orDataChangeTrigger_StatusValueTimestamp
.
-
deadBandType
¶ The type of dead band, as one of these
int
values:DeadBandType_None
orDeadBandType_Absolute
orDeadBandType_Percent
.
-
deadBandValue
¶ Value of the deadband, as a
float
.
-
class DataValue¶
-
class
pyuaf.util.
DataValue
(*args)¶ A DataValue holds some data value, a status, timestamps, ...
Methods:
Attributes:
-
data
¶ The data, as one of the data types described in A note on dynamic data types.
-
opcUaStatusCode
¶ The OPC UA status code (see specs part 4) of the data, as an
int
.
-
sourcePicoseconds
¶ The number of 10 picosecond intervals that need to be added to the source timestamp (to get a higher time resolution), as an
int
.
-
serverPicoseconds
¶ The number of 10 picosecond intervals that need to be added to the server timestamp (to get a higher time resolution), as an
int
.
-
class DataValueVector¶
-
class
pyuaf.util.
DataValueVector
(*args)¶ An DataValueVector is a container that holds elements of type
pyuaf.util.DataValue
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofpyuaf.util.DataValue
.Usage example:
>>> import pyuaf >>> from pyuaf.util import DataValueVector, DataValue >>> from pyuaf.util import NodeId, LocalizedText >>> from pyuaf.util import primitives >>> # construct a DataValueVector without elements: >>> vec = DataValueVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append( DataValue(primitives.UInt32(1234)) ) >>> noOfElements = len(vec) # will be 1 >>> vec.resize(4) >>> noOfElements = len(vec) # will be 4 >>> # vec[0] was already assigned to an UInt32 >>> vec[1].data = primitives.String("some text") >>> vec[2].data = NodeId("SomeId", "SomeNsUri") >>> vec[3].data = LocalizedText("en", "Some English Text") >>> # you may construct an DataValueVector from a regular Python list: >>> otherVec = DataValueVector( [ DataValue(), DataValue(primitives.Boolean(True))] )
class DateTime¶
-
class
pyuaf.util.
DateTime
(*args)¶ An DateTime holds a timestamp.
Short example:
>>> import pyuaf >>> import time, datetime >>> from pyuaf.util import DateTime >>> nowDateTime = DateTime.now() >>> nowDateTime2 = DateTime(time.time()) # equally valid alternative >>> nowStringRepresentation = str(nowDateTime) >>> # create a time in the future (note that 567 milliseconds have been added on the last line!) >>> futureTimeFloat = time.mktime(datetime.datetime(year = 2023, ... month = 6, ... day = 18, ... hour = 9, ... minute = 12, ... second = 34).timetuple()) + 0.567 >>> futureDateTime = DateTime(futureTimeFloat) >>> # equally valid alternative: >>> futureDateTime2 = DateTime() >>> futureDateTime2.setCtime(futureTimeFloat) >>> # calculate the number of days difference between "now" and the "future" >>> daysDifference = nowDateTime.daysTo(futureDateTime)
Methods:
-
__init__
(*args)¶ You can construct a pyuaf.util.DateTime instance by providing a floating point number which represents the number of seconds (+ milliseconds after the comma) since UTC 1 January 1970 (= 1970-01-01T00:00:00Z).
-
isNull
()¶ True if the datetime is NULL, False if it has a real value.
Returns: True if the datetime is NULL, false if it has a real value. Return type: bool
-
toFileTime
()¶ Get the time as a FILETIME, i.e. as a 64-bit integer corresponding to the number of 100-nanosecond intervals since January 1, 1601 UTC).
Returns: The time as a 64-bit number. Return type: long
-
__str__
()¶ Get the time as a string representation, e.g. “2013-05-21T12:34:56.789Z”.
Returns: The time as a string. Return type: str
-
toDateString
()¶ Get the date part as a string representation, e.g. “2013-05-21”.
Returns: The date as a string. Return type: str
-
toTimeString
()¶ Get the time part as a string representation, e.g. “12:34:56.789Z”.
Returns: The time without the date, as a string. Return type: str
-
toTime_t
()¶ Get the time part as the number of seconds since UTC 1 January 1970 (= 1970-01-01T00:00:00Z).
Returns: The time as an integer. Return type: int
-
setCtime
(t)¶ Update the time to the given floating point value, corresponding to the number of seconds (+ milliseconds, after the comma) since UTC 1 January 1970 (= 1970-01-01T00:00:00Z).
Parameters: t ( float
) – The time , e.g.time.time()
for the current time.Returns: The time as a DateTime
object.Return type: DateTime
-
msec
()¶ Get the milliseconds part of the timestamp.
Returns: The number of milliseconds after the second. Return type: int
-
daysTo
(other)¶ Get the number of days from this instance to the argument instance.
Parameters: other ( DateTime
) – Another DateTime instance.Returns: The number of days difference. Return type: int
-
secsTo
(other)¶ Get the number of seconds from this instance to the argument instance.
Parameters: other ( DateTime
) – Another DateTime instance.Returns: The number of seconds difference. Return type: int
-
msecsTo
(other)¶ Get the number of milliseconds from this instance to the argument instance.
Parameters: other ( DateTime
) – Another DateTime instance.Returns: The number of milliseconds difference. Return type: int
-
addSecs
(secs)¶ Add a number of seconds to the timestamp.
Parameters: secs ( int
) – Number of seconds to add.
-
addMilliSecs
(msecs)¶ Add a number of milliseconds to the timestamp.
Parameters: msecs ( int
) – Number of milliseconds to add.
-
Static functions:
-
static
now
()¶ Static function to get the current time.
Returns: The current time. Return type: DateTime
-
static
fromString
(s)¶ Static function to convert the given string into a DateTime object.
Parameters: s ( str
) – The string, e.g. “2013-05-21T12:34:56.789Z”.Returns: The time from the string. Return type: DateTime
-
static
fromTime_t
(t)¶ Static function to convert the given time (as an integer corresponding to
long(time.time())
) into a DateTime object.This time (“time_t”) is the number of seconds since UTC 1 January 1970 = 1970-01-01T00:00:00Z.
Parameters: t ( long
) – The time , e.g.long(time.time()) + 3
for the current time + 3 seconds.Returns: The time as a DateTime
object.Return type: DateTime
-
static
fromFileTime
(t)¶ Static function to convert the given time (as a 64-bit integer corresponding to FILETIME (= the number of 100-nanosecond intervals since January 1, 1601 UTC).
Parameters: t ( long
) – The FILETIME.Returns: The time as a DateTime
object.Return type: DateTime
-
static
sleep
(secs)¶ Static function to sleep a number of seconds.
Parameters: secs ( int
) – Number of seconds to sleep.
-
static
msleep
(msecs)¶ Static function to sleep a number of milliseconds.
Parameters: msecs ( int
) – Number of milliseconds to sleep.
-
static
class DateTimeVector¶
-
class
pyuaf.util.
DateTimeVector
(*args)¶ A DateTimeVector is a container that holds elements of type
pyuaf.util.DateTime
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofDateTime
.Usage example:
>>> import pyuaf >>> import time, datetime >>> from pyuaf.util import DateTimeVector, DateTime >>> # construct a DateTimeVector without elements: >>> vec = DateTimeVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(DateTime(time.time())) >>> noOfElements = len(vec) # will be 1 >>> vec.resize(2) >>> vec[1].setCtime(time.time()) >>> vec[1].addSecs(3) >>> noOfElements = len(vec) # will be 2 >>> # you may construct a DateTimeVector from a regular Python list: >>> fromTime = time.mktime(datetime.datetime(year = 2013, ... month = 6, ... day = 18, ... hour = 9, ... minute = 12, ... second = 34).timetuple()) + 0.567 # 567 msec >>> toTime = time.mktime(datetime.datetime(year = 2014, ... month = 1, ... day = 30, ... hour = 12, ... minute = 34, ... second = 56).timetuple()) + 0.789 # 789 msec >>> someOtherVec = DateTimeVector( [ DateTime(fromTime), DateTime(toTime) ] )
class EndpointDescription¶
-
class
pyuaf.util.
EndpointDescription
(*args)¶ An EndpointDescription instance describes an endpoint of a Server (as returned during the discovery process, so that the client can choose an endpoint and connect to it).
Methods:
Attributes:
-
endpointUrl
¶ The endpoint URL (type
str
).
-
server
¶ The application description of the server (type
ApplicationDescription
).
-
serverCertificate
¶ The server certificate data (type
bytearray
).
-
securityMode
¶ The message security mode (e.g.
pyuaf.util.messagesecuritymodes.Mode_SignAndEncrypt
) (anint
, as defined inpyuaf.util.messagesecuritymodes
).
-
securityPolicyUri
¶ The security policy URI (e.g.
pyuaf.util.securitypolicies.UA_Basic128
), (anint
, as defined inpyuaf.util.securitypolicies
).
-
userIdentityTokens
¶ The allowed user identity token policies (as a
pyuaf.util.UserTokenPolicyVector
).
-
transportProfileUri
¶ The transport profile URI (type
StringVector
).
-
securityLevel
¶ The security level (type
int
).
-
class EndpointDescriptionVector¶
-
class
pyuaf.util.
EndpointDescriptionVector
(*args)¶ An EndpointDescriptionVector is a container that holds elements of type
pyuaf.util.EndpointDescription
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofpyuaf.util.EndpointDescription
.Usage example:
>>> import pyuaf >>> from pyuaf.util import EndpointDescriptionVector, EndpointDescription >>> # construct a EndpointDescriptionVector without elements: >>> descriptions = EndpointDescriptionVector() >>> noOfElements = len(descriptions) # will be 0 >>> descriptions.append(EndpointDescription()) >>> noOfElements = len(descriptions) # will be 1 >>> descriptions.resize(4) >>> noOfElements = len(descriptions) # will be 4 >>> description0 = descriptions[0] >>> # you may construct an EndpointDescriptionVector from a regular Python list: >>> otherDescriptions = EndpointDescriptionVector( [EndpointDescription(), EndpointDescription()] )
class EnumValue¶
-
class
pyuaf.util.
EnumValue
(*args)¶ An EnumValue represents a child of an enumerated value definition.
Methods:
-
__init__
(*args)¶ Construct a new EnumValue, in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import EnumValue, LocalizedText >>> e0 = EnumValue() >>> e1 = EnumValue(1) >>> e2 = EnumValue(1, "manual") >>> e3 = EnumValue(1, "manual", LocalizedText("en", "Manual operation mode") )
-
value
()¶ Get the numeric value of the EnumValue.
Returns: The numeric value. Return type: int
-
setValue
(i)¶ Set the numeric value of the EnumValue.
Parameters: i ( int
) – The new numeric value.
-
name
()¶ Get the name of the EnumValue.
Returns: The name. Return type: str
-
setName
(name)¶ Set the name of the EnumValue.
Parameters: name ( str
) – The new name.
-
documentation
()¶ Get the documentation of the EnumValue.
Returns: Documentation about the value. Return type: LocalizedText
-
setDocumentation
(documentation)¶ Set the documentation of the EnumValue.
Parameters: documentation ( LocalizedText
) – The new documentation.
-
class EventFilter¶
-
class
pyuaf.util.
EventFilter
(*args)¶ An EventFilter selects and filters the events to be received by a client.
Methods:
Attributes:
-
selectClauses
¶ The select clauses, as a
SimpleAttributeOperandVector
.
-
class ExpandedNodeId¶
-
class
pyuaf.util.
ExpandedNodeId
(*args)¶ An ExpandedNodeId fully identifies the node by means of a NodeId part, and a part containing the serverIndex and/or serverUri of the server hosting the node.
Methods:
-
__init__
(*args)¶ Construct a new ExpandedNodeId in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import ExpandedNodeId, NodeId >>> # suppose we have a node with the following properties: >>> nodeIdStringIdentifier = "myStringIdentifier" >>> nameSpaceUri = "myNameSpaceUri" >>> nameSpaceIndex = 3 >>> serverUri = "myServerUri" >>> serverIndex = 2 >>> # and one with the same namespace and server properties, but with a different identifier: >>> nodeIdNumericIdentifier = 1234 >>> # then these ExpandedNodeIds all point to the nodes: >>> exp0 = ExpandedNodeId(nodeIdStringIdentifier , nameSpaceUri , serverUri ) >>> exp1 = ExpandedNodeId(nodeIdStringIdentifier , nameSpaceUri , serverIndex ) >>> exp2 = ExpandedNodeId(nodeIdStringIdentifier , nameSpaceUri , serverUri , serverIndex) >>> exp3 = ExpandedNodeId(nodeIdStringIdentifier , nameSpaceIndex , serverUri ) >>> exp4 = ExpandedNodeId(nodeIdStringIdentifier , nameSpaceIndex , serverIndex ) >>> exp5 = ExpandedNodeId(nodeIdStringIdentifier , nameSpaceIndex , serverUri , serverIndex) >>> exp6 = ExpandedNodeId(nodeIdNumericIdentifier , nameSpaceUri , serverUri ) >>> exp7 = ExpandedNodeId(nodeIdNumericIdentifier , nameSpaceUri , serverIndex ) >>> exp8 = ExpandedNodeId(nodeIdNumericIdentifier , nameSpaceUri , serverUri , serverIndex) >>> exp9 = ExpandedNodeId(nodeIdNumericIdentifier , nameSpaceIndex , serverUri ) >>> exp10 = ExpandedNodeId(nodeIdNumericIdentifier , nameSpaceIndex , serverIndex ) >>> exp11 = ExpandedNodeId(nodeIdNumericIdentifier , nameSpaceIndex , serverUri , serverIndex) >>> # you can also define the NodeId first and provide this + serverIndex and/or serverUri >>> nodeId = NodeId(nodeIdStringIdentifier, nameSpaceUri, nameSpaceIndex) >>> exp12 = ExpandedNodeId(nodeId, serverUri ) >>> exp13 = ExpandedNodeId(nodeId, serverIndex ) >>> exp14 = ExpandedNodeId(nodeId, serverUri , serverIndex)
-
hasServerIndex
()¶ Check if a server index was given.
Returns: True if a serverIndex has been defined, False if not. Return type: bool
-
hasServerUri
()¶ Check if a non-empty server URI was given.
Returns: True if this ExpandedNodeId contains a non-empty server URI, False if not. Return type: bool
-
serverIndex
()¶ Get the server index of the ExpandedNodeId.
This function will always return an
int
, so call hasServerIndex() to see if it’s a valid one.Returns: The server index. Return type: int
-
serverUri
()¶ Get the server URI of the ExpandedNodeId.
This function will always return a string, so call hasServerUri() to see if it’s a valid one.
Returns: The server URI. Return type: str
-
nodeId
()¶ Get the NodeId part of the ExpandedNodeId.
Returns: The NodeId part. Return type: pyuaf.util.NodeId
-
class ExpandedNodeIdVector¶
-
class
pyuaf.util.
ExpandedNodeIdVector
(*args)¶ A ExpandedNodeIdVector is a container that holds elements of type
pyuaf.util.ExpandedNodeId
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofExpandedNodeId
.Usage example:
>>> import pyuaf >>> from pyuaf.util import ExpandedNodeIdVector, ExpandedNodeId >>> # construct a ExpandedNodeIdVector without elements: >>> vec = ExpandedNodeIdVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(ExpandedNodeId("some id", "http://Some/Namespace/URI", "Some:Server:URI")) >>> noOfElements = len(vec) # will be 1 >>> if vec[0].hasServerUri(): ... serverUri = vec[0].serverUri() ... else: ... serverUri = None >>> vec.resize(2) >>> noOfElements = len(vec) # will be 2 >>> # you may construct a ExpandedNodeIdVector from a regular Python list: >>> someOtherVec = ExpandedNodeIdVector( [ ExpandedNodeId("id 0", "MyNamespace", "serverX"), ... ExpandedNodeId("id 1", "MyNamespace", "serverY") ] )
class ExtensionObject¶
class EUInformation¶
-
class
pyuaf.util.
EUInformation
(*args)¶ A EUInformation conveys information about the engineering unit of a variable.
Methods:
-
__init__
(*args)¶ Construct a new EUInformation in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import EUInformation, ExtensionObject, LocalizedText >>> info1 = EUInformation() >>> info2 = EUInformation(ExtensionObject()) >>> info3 = EUInformation("nsUri", 23, LocalizedText("en", "display name"), LocalizedText("en", "description"))
-
clear
()¶ Clear the object.
-
getNamespaceUri
()¶ Get the namespace uri as a
`str`
.
-
getUnitId
()¶ Get the unit id as an
`int`
.
-
getDisplayName
()¶ Get the display name as a
LocalizedText
.
-
getDescription
()¶ Get the description as a
LocalizedText
.
-
setNamespaceUri
(nsUri)¶ Set the namespace uri.
Parameters: namespaceUri ( `str`
.) – The namespace URI.
-
setUnitId
(unitId)¶ Set the unit id.
Parameters: unitId ( `int`
.) – The unit ID.
-
setDisplayName
(displayName)¶ Set the display name.
Parameters: displayName ( LocalizedText
.) – The display name.
-
getDescription
() Set the description.
Parameters: description ( LocalizedText
.) – The description.
-
class GenericStructureValue¶
-
class
pyuaf.util.
GenericStructureValue
(*args)¶ A GenericStructureValue instance holds a structure of fields. The fields may represent values (Double, LocalizedText, ...) or other GenericStructureValue instances or arrays of GenericStructureValue.
See also
Check out example How to read and write structures? for more information.
Class attributes:
Methods:
-
__init__
(*args)¶ Construct a new GenericStructureValue in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import GenericStructureValue, ExtensionObject, StructureDefinition >>> struct1 = GenericStructureValue() >>> struct2 = GenericStructureValue(ExtensionObject(), StructureDefinition())
-
clear
()¶ Clear the structure.
-
setGenericValue
(*args)¶ Fill the generic structure value.
Either you can provide a ByteString, Encoding and StructureDefinition as arguments:
ByteString
dataint
representing the encoding, such asEncoding_Binary
StructureDefinition
structureDefinition
Or you can provide an ExtensionObject and a StructureDefinition:
ExtensionObject
extensionObjectStructureDefinition
structureDefinition
-
setField
(*args)¶ Change the value of a field.
This method has two arguments.
The first argument identifies the field. It can either be:
- the number of the field (an
int
) - or the name of the field (a
str
).
The second argument sets the new value. It can either be:
- a value such as
UInt32
,Double
,String
,DateTime
,LocalizedText
,QualifiedName
- a
GenericStructureValue
instance - a
list
ofGenericStructureValue
instances. (Or aGenericStructureVector
, this is similar to a list.) In other words, an array of structures. - a
GenericUnionValue
instance - a
list
ofGenericUnionValue
instances. (Or aGenericUnionVector
, this is similar to a list.) In other words, an array of unions.
- the number of the field (an
-
value
(*args)¶ Get the value of the specified field, in case the specified field represents a built-in OPC UA value. In other words, in case the
valueType()
method returns theint
pyuaf.util.structurefielddatatypes.Variant
.The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
This method will return a tuple of (value, statuscode).
- the value can be a primitive such as
UInt32
,Double
,String
, or typical built-in OPC UA types such asDateTime
,LocalizedText
,QualifiedName
, ... - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to one of the values mentioned above. If the value is something else (e.g. a structure), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the number of the field (an
-
genericStructure
(*args)¶ Get the structure value of the specified field, in case the specified field represents a structure. In other words, in case the
valueType()
method returns theint
pyuaf.util.structurefielddatatypes.GenericStructure
.The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
This method will return a tuple of (structureValue, statuscode).
- the structureValue is an instance of
GenericStructureValue
. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to a structure. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the number of the field (an
-
genericStructureArray
(*args)¶ Get the structure value of the specified field, in case the specified field represents an array of structures. In other words, in case the
valueType()
method returns theint
pyuaf.util.structurefielddatatypes.GenericStructureArray
.The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
This method will return a tuple of (structureValueArray, statuscode).
- the structureValue is a Python
list
ofGenericStructureValue
instances. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to an array of structures. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the number of the field (an
-
genericUnion
(*args)¶ Get the union value of the specified field, in case the specified field represents a union. In other words, in case the
valueType()
method returns theint
pyuaf.util.structurefielddatatypes.GenericUnion
.The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
This method will return a tuple of (unionValue, statuscode).
- the unionValue is an instance of
GenericUnionValue
. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to a union. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the number of the field (an
-
genericUnionArray
(*args)¶ Get the structure value of the specified field, in case the specified field represents an array of unions. In other words, in case the
valueType()
method returns theint
pyuaf.util.structurefielddatatypes.GenericUnionArray
.The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
This method will return a tuple of (unionValueArray, statuscode).
- the unionValue is a Python
list
ofGenericUnionValue
instances. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to an array of unions. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the number of the field (an
-
definition
()¶ Get the definition of the structure.
Returns: The definition of the structure. Return type: StructureDefinition
-
setDefinition
(definition, createDefaultValues=False)¶ Set the definition of the structure.
Parameters: definition ( StructureDefinition
) – New definition.
-
isFieldSet
(*args)¶ Check if the field is set or not.
The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
Returns: True if the field is set, False if not. Return type: bool
- the number of the field (an
-
unsetField
(*args)¶ Unset a field.
The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
Returns: The status: Good if the field could be unset, Bad otherwise. The statusCode
of theSdkStatus
will beOpcUa_BadInvalidArgument
if the specified field could not be found.Return type: SdkStatus
- the number of the field (an
-
valueType
(index)¶ Get the datatype (built-in type, structure, structure array, union, ...) of a field.
The field can be specified via the index argument.
Parameters: index ( int
) – Index of the field.This method will return a tuple of (type, statuscode).
- the type is a Python
int
, as defined bypyuaf.util.structurefielddatatypes
. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_BadInvalidArgument
if the index is out of range, orOpcUa_Good
otherwise.
- the type is a Python
-
toExtensionObject
(*args)¶ Convert the structure into an
ExtensionObject
.This ExtensionObject can be written back to the server, e.g. after some fields have been changed.
Parameters: - extensionObject (
ExtensionObject
) – The ExtensionObject to update. - encoding (
int
) – Optional argument: the encoding for the ExtensionObject. If not specified, then the default valueEncoding_Binary
will be used.
- extensionObject (
-
__str__
(*args)¶ Get a string representation.
-
class GenericStructureVector¶
-
class
pyuaf.util.
GenericStructureVector
(*args)¶ A GenericStructureVector is an array that holds elements of type
GenericStructureValue
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofGenericStructureVector
.Usage example:
>>> import pyuaf >>> from pyuaf.util import GenericStructureVector, GenericStructureValue >>> # construct a GenericStructureVector without elements: >>> vec = GenericStructureVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(GenericStructureValue()) >>> noOfElements = len(vec) # will be 1 >>> definition = vec[0].definition() >>> vec.resize(2) >>> noOfElements = len(vec) # will be 2 >>> # you may construct a GenericStructureVector from a regular Python list: >>> someOtherVec = GenericStructureVector( [ GenericStructureValue(), GenericStructureValue() ] )
class GenericUnionValue¶
-
class
pyuaf.util.
GenericUnionValue
(*args)¶ A GenericUnionValue instance holds a union of fields. The fields may represent values (Double, LocalizedText, ...) or GenericStructureValue instances or other GenericUnionValue instances or arrays of GenericUnionValue or ...
See also
Check out example How to read and write structures? for more information.
Class attributes:
Methods:
-
__init__
(*args)¶ Construct a new GenericUnionValue in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import GenericUnionValue, ExtensionObject, StructureDefinition >>> union1 = GenericUnionValue() >>> union2 = GenericUnionValue(ExtensionObject(), StructureDefinition())
-
clear
()¶ Clear the union.
-
setGenericUnion
(*args)¶ Fill the generic union value.
Either you can provide a ByteString, Encoding and StructureDefinition as arguments:
ByteString
dataint
representing the encoding, such asEncoding_Binary
StructureDefinition
structureDefinition
Or you can provide an ExtensionObject and a StructureDefinition:
ExtensionObject
extensionObjectStructureDefinition
structureDefinition
-
setValue
(*args)¶ Change the value of a field.
This method has two arguments.
The first argument identifies the field. It can either be:
- the number of the field (an
int
) - or the name of the field (a
str
).
The second argument sets the new value. It can either be:
- a value such as
UInt32
,Double
,String
,DateTime
,LocalizedText
,QualifiedName
- a
GenericStructureValue
instance - a
list
ofGenericStructureValue
instances. (Or aGenericStructureVector
, this is similar to a list.) In other words, an array of structures. - a
GenericUnionValue
instance - a
list
ofGenericUnionValue
instances. (Or aGenericUnionVector
, this is similar to a list.) In other words, an array of unions.
- the number of the field (an
-
value
()¶ Get the value of the active field, in case this field represents a built-in OPC UA value.
This method will return a tuple of (value, statuscode).
- the value can be a primitive such as
UInt32
,Double
,String
, or typical built-in OPC UA types such asDateTime
,LocalizedText
,QualifiedName
, ... - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to one of the values mentioned above. If the value is something else (e.g. a structure), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the value can be a primitive such as
-
genericStructure
()¶ Get the structure value of the active field, in case this field represents a structure.
This method will return a tuple of (structureValue, statuscode).
- the structureValue is an instance of
GenericUnionValue
. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to a structure. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the structureValue is an instance of
-
genericStructureArray
()¶ Get the structure value of the active field, in case this field represents an array of structures.
This method will return a tuple of (structureValueArray, statuscode).
- the structureValue is a Python
list
ofGenericUnionValue
instances. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to an array of structures. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the structureValue is a Python
-
genericUnion
()¶ Get the union value of the active field, in case this field represents a union.
This method will return a tuple of (unionValue, statuscode).
- the unionValue is an instance of
GenericUnionValue
. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to a union. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the unionValue is an instance of
-
genericUnionArray
()¶ Get the structure value of the active field, in case this field represents an array of unions.
This method will return a tuple of (unionValueArray, statuscode).
- the unionValue is a Python
list
ofGenericUnionValue
instances. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_Good
if the field corresponds indeed to an array of unions. If the value is something else (e.g. a Double), then the statuscode will beOpcUa_BadInvalidArgument
. If the field is empty, you can expect aOpcUa_BadNoData
. You can easily print the name of the status code by creating aSdkStatus
(with the OPC UA status code as the argument for the constructor).
- the unionValue is a Python
-
definition
()¶ Get the definition of the structure.
Returns: The definition of the structure. Return type: StructureDefinition
-
switchValue
()¶ Get the number of the active field (the switch field).
Returns: Switch field number. Return type: int
-
field
()¶ Get currently used field.
Returns: The currently used field. Return type: StructureField
-
toExtensionObject
(*args)¶ Convert the structure into an
ExtensionObject
.This ExtensionObject can be written back to the server, e.g. after the field has been changed.
Parameters: - extensionObject (
ExtensionObject
) – The ExtensionObject to update. - encoding (
int
) – Optional argument: the encoding for the ExtensionObject. If not specified, then the default valueEncoding_Binary
will be used.
- extensionObject (
-
__str__
(*args)¶ Get a string representation.
-
class GenericUnionVector¶
-
class
pyuaf.util.
GenericUnionVector
(*args)¶ A GenericUnionVector is an array that holds elements of type
GenericUnionValue
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofGenericUnionVector
.Usage example:
>>> import pyuaf >>> from pyuaf.util import GenericUnionVector, GenericUnionValue >>> # construct a GenericUnionVector without elements: >>> vec = GenericUnionVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(GenericUnionValue()) >>> noOfElements = len(vec) # will be 1 >>> definition = vec[0].definition() >>> vec.resize(2) >>> noOfElements = len(vec) # will be 2 >>> # you may construct a GenericUnionVector from a regular Python list: >>> someOtherVec = GenericUnionVector( [ GenericUnionValue(), GenericUnionValue() ] )
class Guid¶
-
class
pyuaf.util.
Guid
(*args)¶ A Guid represents a Globally unique identifier.
Usage example:
>>> import pyuaf >>> from pyuaf.util import Guid, NodeId, Address >>> >>> # create a NodeId for a known node: >>> namespaceUri = "http://www.vendorXYZ.com/products/temperaturecontrollers" >>> guid = Guid("{00000000-0000-0000-0000-000000000001}") >>> nodeId = NodeId(guid, namespaceUri) >>> >>> # create an address which points to that NodeId hosted by a specific server: >>> serverUri = "/ourcompany/plantfloor/temperaturecontrollers/3" >>> address = Address(nodeId, serverUri) >>> >>> # now we can create a Client and read/write/monitor/... the addressed node
Methods:
class LocalizedText¶
-
class
pyuaf.util.
LocalizedText
(*args)¶ A LocalizedText is text with a locale attached.
Methods:
-
__init__
([locale[, text]])¶ Construct a new LocalizedText in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import LocalizedText >>> # the following ways of constructing a QualifiedName are possible: >>> lText0 = LocalizedText() # incomplete, no information given! >>> lText1 = LocalizedText("en", "My English Text") # OK >>> lText2 = LocalizedText("", "My Text") # OK (no specific locale given) >>> # strings are assumed to be UTF-8 encoded! >>> unicodeObject = u"40\u00B0 Celsius ist eine hei\u00DFe Temperatur!" >>> lText3 = LocalizedText("de", unicodeObject.encode("UTF-8"))
-
isNull
()¶ Check if the localized text has a NULL value. When the localized text has a null value, the
text
andlocale
methods will return empty strings.Returns: True if NULL. Return type: bool
-
text
()¶ Get the text part of the LocalizedText, as an UTF-8 encoded string.
Returns: The text part. Return type: str
-
locale
()¶ Get the locale part of the LocalizedText.
Returns: The locale part (e.g. “en”, “de”, “nl”, “”, ...). Return type: str
-
toFullString
()¶ Get a string of the locale part + the text part.
Returns: The localized text. Return type: str
-
class LoggingInterface¶
-
class
pyuaf.util.
LoggingInterface
¶ A LoggingInterface interface class can be implemented to receive log messages.
For instance, the pyuaf.client.Client class is implementing this interface. As a regular UAF user, you should not have to deal with this interface directly.
Methods:
-
__dispatch_logMessageReceived__
(message)¶ A new log message was received.
Parameters: message ( pyuaf.util.LogMessage
) – The log message that was received.
-
class LogMessage¶
-
class
pyuaf.util.
LogMessage
(*args)¶ A LogMessage instance contains a timestamp, a log level, an informative message, etc.
Usage example:
>>> import pyuaf >>> import time >>> # normally you receive log messages from a pyuaf.client.Client instance, >>> # but in this case we'll create a log message manually: >>> msg = pyuaf.util.LogMessage(pyuaf.util.loglevels.Debug, ... "MyApp", ... "MyLogger", ... "Something has happened,\n" ... + "requiring a big multi-line description!") >>> niceLocalTimeString = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(msg.ctime)) >>> niceLocalTimeString += ".%.3d" %msg.msec >>> stringToWrittenToFile = "New log message:" >>> stringToWrittenToFile += " - time received : %s" %niceLocalTimeString >>> stringToWrittenToFile += " - application name : %s" %msg.applicationName >>> stringToWrittenToFile += " - logger name : %s" %msg.loggerName >>> stringToWrittenToFile += " - level : %d = %s" %(msg.level, pyuaf.util.loglevels.toString(msg.level)) >>> for line in msg.message.splitlines(): ... stringToWrittenToFile += " - message lines : %s" %line >>> theWholeMessageAtOnce = str(msg)
Methods:
Attributes:
-
ctime
¶ The timestamp as a 64-bit number (the “c-time”) expressing the seconds that passed since the epoch, as an
int
.
-
msec
¶ The number of milliseconds past the ctime, as an
int
.
-
level
¶ The log level as an
int
(as defined inpyuaf.util.loglevels
).
-
applicationName
¶ The name of the application that owns the logger (type
str
).
-
loggerName
¶ The name of the logger that produced the log message (type
str
).
-
message
¶ The actual informative message to be logged (type
str
).
-
class Mask¶
-
class
pyuaf.util.
Mask
(*args)¶ This is a boolean mask to mark items as ‘set’ (boolean True) or ‘unset’ (boolean False).
The mask keeps track of the number of ‘set’ and ‘unset’ values. This means you can very efficiently call countSet() and countUnset().
Methods:
-
__init__
([initialSize[, initialValue]])¶ Construct a new Mask.
The initial size can optionally be given. If the initial size is given, also the initial value of all initial elements can be given.
Parameters: - initialSize (
int
) – (Optional) Initial number of elements of the mask. - initialValue (
bool
) – (Optional) Value (True or False) of the initial elements.
- initialSize (
-
resize
(newSize)¶ Resize the mask.
Parameters: newSize ( int
) – The size the mask should be having.
-
size
()¶ The current size of the mask.
Returns: The current number of elements. Return type: int
-
setCount
()¶ Get the number of ‘set’ elements.
Returns: The current number of ‘set’ elements. Return type: int
-
unsetCount
()¶ Get the number of ‘unset’ elements.
Returns: The current number of ‘unset’ elements. Return type: int
-
set
(i)¶ Set the i’th mask item (i.e. make it True).
Parameters: i ( int
) – The number of the item that should be ‘set’.
-
unset
(i)¶ Unset the i’th mask item (i.e. make it False).
Parameters: i ( int
) – The number of the item that should be ‘unset’.
-
__and__
(otherMask)¶ Logically AND this mask with another mask element-wise.
Parameters: otherMask ( pyuaf.util.Mask
) – The other mask.Returns: A new mask, the logical AND result of the current one and the other one. Return type: pyuaf.util.Mask
-
class Matrix¶
-
class
pyuaf.util.
Matrix
(*args)¶ Matrix holds an n-dimensional matrix.
Methods:
-
__init__
(*args)¶ Construct an empty matrix.
-
clear
()¶ Clear the matrix.
-
status
()¶ Returns: Good if the matrix is valid, bad if not. Return type: pyuaf.util.Status
-
getElement
(dimensionNumbers)¶ Get the element at certain dimension numbers.
For example, getElement([1,3,2]) to get matrix[1][3][2]
Parameters: dimensionNumbers – a list of int
, e.g. [1,2,3].Returns: The element corresponding to the dimensionNumbers
-
setElement
(dimensionNumbers, value)¶ Change the element at certain dimension numbers.
For example, setElement([1,3,2], UInt32(3)) to set matrix[1][3][2].
Parameters: - dimensionNumbers – a list of
int
, e.g. [1,2,3]. - value – The element corresponding to the dimensionNumbers, which could be of several types: see A note on dynamic data types.
- dimensionNumbers – a list of
-
getElementNumber
(dimensionNumbers)¶ Get the element number for given dimension numbers.
For example, getElementNumber([0,0,0]) returns 0, getElementNumber([0,0,1]) returns 1, and so on.
Parameters: dimensionNumbers – a list of int
, e.g. [1,2,3].Returns: The element number corresponding to the dimensionNumbers, as an int
.
-
Attributes:
-
type
¶ The built-in OPC UA type of the matrix (an
int
defined inpyuaf.util.opcuatypes
).
-
elements
¶ A list of elements, which could be of several types: see A note on dynamic data types.
-
dimensions
¶ The dimensions of the matrix, as a list of
int
.
-
class ModelChangeStructureDataType¶
class ModificationInfo¶
-
class
pyuaf.util.
ModificationInfo
(*args)¶ A ModificationInfo instance holds some information about a historical data modification.
Methods:
Class attributes:
Possible HistoryUpdateType values:
-
HistoryUpdateType_Insert
= 1¶ An
int
identifying the type of modification: in this case an insertion!
-
HistoryUpdateType_Replace
= 2¶ An
int
identifying the type of modification: in this case a replacement!
-
HistoryUpdateType_Update
= 3¶ An
int
identifying the type of modification: in this case an update! (in percent).
-
HistoryUpdateType_Delete
= 4¶ An
int
identifying the type of modification: in this case a deletion!
-
Attributes:
class ModificationInfoVector¶
-
class
pyuaf.util.
ModificationInfoVector
(*args)¶ A ModificationInfoVector is a container that holds elements of type
pyuaf.util.ModificationInfo
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofModificationInfo
.Usage example:
>>> import pyuaf >>> from pyuaf.util import ModificationInfoVector, ModificationInfo, DateTime >>> # construct a ModificationInfoVector without elements: >>> vec = ModificationInfoVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(ModificationInfo()) >>> noOfElements = len(vec) # will be 1 >>> vec[0].userName = "John" >>> vec.resize(2) >>> noOfElements = len(vec) # will be 2 >>> vec[1].userName = "Wim" >>> vec[1].historyUpdateType = ModificationInfo.HistoryUpdateType_Delete >>> vec[1].modificationTime = DateTime.now() >>> # you may construct a ModificationInfoVector from a regular Python list: >>> someOtherVec = ModificationInfoVector( [ ModificationInfo(), ModificationInfo() ] )
class NodeId¶
-
class
pyuaf.util.
NodeId
(*args)¶ A NodeId identifies the node within an address space. It is not bound to a specific server (use an
pyuaf.util.ExpandedNodeId
for that).Methods:
-
__init__
(*args)¶ Construct a NodeId.
A NodeId should contain an identifier (e.g. a string or a numeric value) and some information about the namespace (a namespace URI and/or a namespace index).
Usage example:
>>> import pyuaf >>> from pyuaf.util import NodeId, Guid, NodeIdIdentifier >>> >>> nsUri = "myNameSpaceUri" >>> nsIndex = 3 >>> nodeId0 = NodeId() # contains no information >>> nodeId1 = NodeId("myStringIdentifier", nsUri) >>> nodeId2 = NodeId("myStringIdentifier", nsUri, nsIndex) # nsIndex is redundant information, avoid! >>> nodeId3 = NodeId("myStringIdentifier", nsIndex) # namespace indexes may change, better use namespace uris! >>> nodeId4 = NodeId(2345, nsUri) >>> nodeId5 = NodeId(2345, nsUri, nsIndex) # nsIndex is redundant information, avoid! >>> nodeId6 = NodeId(2345, nsIndex) # namespace indexes may change, better use namespace uris! >>> guid = Guid("{00000000-0000-0000-0000-000000000001}") >>> nodeId7 = NodeId(guid, nsUri) >>> nodeId8 = NodeId(guid, nsUri, nsIndex) # nsIndex is redundant information here, avoid! >>> nodeId9 = NodeId(guid, nsIndex) # namespace indexes may change, better use namespace uris! >>> identifier = NodeIdIdentifier("myStringIdentifier") >>> nodeId10 = NodeId(identifier, nsUri) >>> nodeId11 = NodeId(identifier, nsUri, nsIndex) # nsIndex is redundant information here, avoid! >>> nodeId12 = NodeId(identifier, nsIndex) # namespace indexes may change, better use namespace uris!
-
hasNameSpaceUri
()¶ Check if a non-empty namespace URI was given.
Returns: True if this NodeId contains a non-empty server URI, False if not. Return type: bool
-
hasNameSpaceIndex
()¶ Check if a namespace index was given.
Returns: True if a namespaceIndex has been defined, False if not. Return type: bool
-
nameSpaceUri
()¶ Get the namespace URI of the NodeId.
This function will always return a string, so call hasNameSpaceUri() to see if it’s a valid one.
Returns: The namespace URI. Return type: str
-
nameSpaceIndex
()¶ Get the namespace index of the NodeId.
This function will always return an
int
, so call hasNameSpaceIndex() to see if it’s a valid one.Returns: The namespace index. Return type: int
-
identifier
()¶ Get the NodeIdIdentifier part of the NodeId.
Returns: The NodeIdIdentifier part. Return type: pyuaf.util.NodeIdIdentifier
-
setNameSpaceUri
(uri)¶ Set the namespace URI of the NodeId.
Parameters: uri ( str
) – The namespace URI.
-
setNameSpaceIndex
(index)¶ Set the namespace index of the NodeId.
Parameters: uri ( int
) – The namespace index.
-
isNull
()¶ Was the NodeId initialized with some contents?
Returns: True if the NodeId does not have any contents. Return type: bool
-
class NodeIdIdentifier¶
-
class
pyuaf.util.
NodeIdIdentifier
(*args)¶ A NodeIdIdentifier is the identifier part of a NodeId.
Methods:
-
__init__
(*args)¶ Construct a NodeIdIdentifier.
- The constructor accepts
- an
int
in order to construct a Numeric identifier - a
str
in order to construct a String identifier - a
Guid
in order to construct a Guid identifier - a
bytearray
in order to construct a Guid identifier
- an
-
isNull
()¶ Was the identifier initialized with some contents?
Returns: True if the identifier does not have any contents. Return type: bool
-
Attributes:
-
type
¶ The type of the NodeIdIdentifier (e.g.
pyuaf.util.nodeididentifiertypes.Identifier_String
) as defined withinpyuaf.util.nodeididentifiertypes
.
-
idString
¶ The
str
value in casetype
equalspyuaf.util.nodeididentifiertypes.Identifier_String
.
-
idNumeric
¶ The
int
value in casetype
equalspyuaf.util.nodeididentifiertypes.Identifier_Numeric
.
-
idGuid
¶ The
Guid
value in casetype
equalspyuaf.util.nodeididentifiertypes.Identifier_Guid
.
-
idOpaque
¶ The
bytearray
(a built-in Python type) value in casetype
equalspyuaf.util.nodeididentifiertypes.Identifier_Opaque
.
-
class PkiCertificate¶
-
class
pyuaf.util.
PkiCertificate
(*args)¶ A PkiCertificate holds a X509 certificate.
Here’s some example code to set up a certificate:
>>> import pyuaf >>> from pyuaf.util import PkiRsaKeyPair, PkiIdentity, PkiCertificateInfo, PkiCertificate >>> # we'll need the hostname of the computer later on: >>> import socket >>> hostName = socket.gethostname() >>> # we will create a self-signed certificate, which means that the subject and issuer are the same! >>> keyPair = PkiRsaKeyPair(1024) >>> issuerPrivateKey = keyPair.privateKey() >>> subjectPublicKey = keyPair.publicKey() >>> identity = PkiIdentity() >>> identity.commonName = "Wim Pessemier" >>> identity.organization = "KU Leuven" >>> identity.organizationUnit = "Institute of Astronomy" >>> identity.locality = "Leuven" >>> identity.country = "BE" >>> info = PkiCertificateInfo() >>> info.uri = "urn:%s:InstituteOfAstronomy::MyExampleCode" %hostName # must be unique! >>> info.dns = hostName >>> info.eMail = "Wxx.Pxxxxxxxx@ster.kuleuven.be" >>> info.validTime = 60*60*24*365*5 # 5 years >>> certificate = PkiCertificate(info, identity, subjectPublicKey, identity, issuerPrivateKey)
Class attributes:
-
Action_Reject
= 0¶
-
Action_AcceptTemporarily
= 1¶
-
Action_AcceptPermanently
= 2¶
-
Extension_SubjectAltName
= 85¶
-
Extension_BasicConstraints
= 87¶
-
Extension_NetscapeComment
= 78¶
-
Extension_SubjectKeyIdentifier
= 82¶
-
Extension_AuthorityKeyIdentifier
= 90¶
-
Extension_KeyUsage
= 83¶
-
Extension_ExtendedKeyUsage
= 126¶
-
Methods:
-
__init__
(*args)¶ Construct a new PkiCertificate with the following arguments:
Parameters: - info (
PkiCertificateInfo
) – The certificate info. - subject (
PkiIdentity
) – The subject identity. - subjectPublicKey (
PkiPublicKey
) – The subject public key. - issuer (
PkiIdentity
) – The issuer identity. - issuerPrivateKey (
PkiPrivateKey
) – The issuer private key.
- info (
-
isNull
()¶ Check if the certificate has data.
Returns: True if the certificate has data, False if not. Return type: bool
-
isValid
()¶ Check if the signature is not expired.
Returns: True if the certificate is valid, False if not. Return type: bool
-
isSelfSigned
()¶ Check if the certificate is self-signed (i.e. if the subject and issuer are the same).
Returns: True if the certificate is self-signed, False if not. Return type: bool
-
publicKey
()¶ Get the public key of the certificate.
Returns: The public key of the certificate. Return type: PkiPublicKey
-
commonName
()¶ Convenience method to get the common name of the subject. (equals
myPkiCertificate.subject().commonName
).Returns: The common name of the subject. Return type: str
-
subject
()¶ Get the identity of the subject of the certificate.
Returns: The subject. Return type: PkiIdentity
-
issuer
()¶ Get the identity of the issuer of the certificate.
Returns: The issuer. Return type: PkiIdentity
-
subjectNameHash
()¶ Get the hash of the subject name.
Returns: The hash of the subject name (e.g. 1877523877). Return type: long
-
info
()¶ Get information from the X509v3 extension “subjectAltName” (SAN). It allows various values to be associated with a security certificate.
Warning
validTime
will not be filled, usevalidFrom()
andvalidTo()
instead!Returns: The certificate info without validTime. Return type: PkiCertificateInfo
-
validFrom
()¶ Get the start date from when the certificate is valid.
Returns: The start date from when the certificate is valid. Return type: DateTime
-
validTo
()¶ Get the end date until when the certificate is valid.
Returns: The end date until when the certificate is valid. Return type: DateTime
-
serialNumber
()¶ Get the X.509 serial number (a unique number issued by the certificate issuer), as a hexadecimal string.
Returns: The serial number (e.g. “542BA97B”). Return type: str
-
signatureTypeNID
()¶ Get the numerical ID (NID) of the signature algorithm type.
Returns: The signature algorithm type NID (e.g. 65). Return type: int
-
signatureTypeString
()¶ Get a string representation of the numerical ID (NID) of the signature algorithm type.
Returns: The signature algorithm type as a string (e.g. “RSA-SHA1”). Return type: str
-
hasExtension
(extension)¶ Check if the certificate has the given extension.
Parameters: extension ( int
) – Extension ID, e.g.pyuaf.util.PkiCertificate.Extension_SubjectAltName
.Returns: True if the extension is present, False if not. Return type: bool
-
extensionValue
(extension)¶ Get the value of the given extension if the extension is present.
Parameters: extension ( int
) – Extension ID, e.g.pyuaf.util.PkiCertificate.Extension_SubjectAltName
.Returns: The value as a string. Return type: str
-
toDER
()¶ Get a DER encoded bytearray of the certificate.
Returns: DER encoded data. Return type: bytearray
-
toDERFile
(fileName)¶ Write the certificate to a DER-encoded file with the given filename. An error code is returned (0 if success).
Note that the directories in which the file should reside, must already exist! This function will only create a file, no directories!
Parameters: fileName ( str
) – The filename (may be relative or absolute).Returns: Error code (0 if success). Return type: int
-
toPEMFile
(fileName)¶ Write the certificate to a PEM-encoded file with the given filename. An error code is returned (0 if success).
Note that the directories in which the file should reside, must already exist! This function will only create a file, no directories!
Parameters: fileName ( str
) – The filename (may be relative or absolute).Returns: Error code (0 if success). Return type: int
-
thumbPrint
()¶ Get a SHA1 thumb print (finger print) of the certficate. It is a short sequence of bytes used to identify a certificate efficiently.
Returns: Thumb print data. Return type: bytearray
-
PkiPublicKey.
getErrors
()¶ Get a list of errors.
Returns: A list of error descriptions. Return type: list
ofstr
-
Class methods:
-
static
fromDER
()¶ Static method to get a certificate from a DER encoded bytearray.
Parameters: data ( bytearray
) – DER data.Returns: A new certificate instance. Return type: PkiCertificate
-
static
fromDERFile
()¶ Static method to get a certificate from a DER encoded file.
Parameters: fileName ( str
) – File name of the DER file.Returns: A new certificate instance. Return type: PkiCertificate
-
static
fromPEMFile
()¶ Static method to get a certificate from a PEM encoded file.
Parameters: fileName ( str
) – File name of the PEM file.Returns: A new certificate instance. Return type: PkiCertificate
-
static
class PkiCertificateInfo¶
-
class
pyuaf.util.
PkiCertificateInfo
(*args)¶ - A PkiCertificateInfo holds some information about a PkiCertificate.
Methods:
-
__init__
(*args)¶ Construct a new PkiCertificateInfo.
-
Attributes:
-
uri
¶ The URI of the application certificate, as a string (type
str
).
-
ipAddresses
¶ The IP addresses of the application certificate, as a
StringVector
. Optional if no DNS is available.
-
dnsNames
¶ The DNS names of the application certificate, as a
StringVector
.
-
eMail
¶ The e-mail address of the application certificate, as a string (type
str
).
-
validTime
¶ The valid time of the application certificate, in seconds, as a
long
.
-
class PkiPrivateKey¶
-
class
pyuaf.util.
PkiPrivateKey
(*args)¶ - A PkiPrivateKey is just a container for a private key.
Note
A private key only makes sense in combination with a public key. Therefore you should never create a PkiPrivateKey instance using the constructor of PkiPrivateKey. Instead, always create a
PkiRsaKeyPair
and get the private key from there (i.e. via itsprivateKey()
method). See the documentation ofPkiRsaKeyPair
to see example code of how to create a private key via a key pair.Methods:
-
__init__
(*args)¶ Construct a new PkiPrivateKey... in a bad way! See the note above to understand why you should avoid calling this constructor directly!
-
class PkiPublicKey¶
-
class
pyuaf.util.
PkiPublicKey
(*args)¶ - A PkiPublicKey can hold an RSA or DSA encrypted public key.
Note
A public key only makes sense in combination with a private key. Therefore you should never create a PkiPublicKey instance using the constructor of PkiPublicKey. Instead, always create a
PkiRsaKeyPair
and get the public key from there (i.e. via itspublicKey()
method). See the documentation ofPkiRsaKeyPair
to see example code of how to create a public key via a key pair.Warning
The SDK (up to 1.4.2) contains a bug so that your application may crash (segmentation fault) if the data of the PkiPublicKey make no sense. To avoid this, always create a public key from a key pair (which should also contain sensible data).
Class attributes:
Class methods:
-
static
fromDER
(data)¶ Read the public key from a DER encoded
bytearray
.Parameters: data ( bytearray
) – The DER encoded data.Returns: A new PkiPublicKey instance. Return type: PkiPublicKey
-
static
Instance Methods:
-
__init__
(*args)¶ Construct a new PkiPublicKey... in a bad way! See the note above to understand why you should avoid calling this constructor directly!
-
Attributes:
class PkiRsaKeyPair¶
-
class
pyuaf.util.
PkiRsaKeyPair
(*args)¶ A PkiRsaKeyPair holds a private and a public key pair.
Creating a PkiRsaKeyPair is the only sensible way to create a
PkiPublicKey
andPkiPrivateKey
:>>> import pyuaf >>> pair = pyuaf.util.PkiRsaKeyPair(1024) >>> publicKey = pair.publicKey() >>> privateKey = pair.privateKey()
Warning
The SDK (up to 1.4.2) contains a bug so that your application may crash (segmentation fault) if the data of the key pair make no sense. To avoid this, always make sure your key pair has sensible data (e.g. don’t use
pyuaf.util.PkiRsaKeyPair.fromPEMFile()
with gibberish data).Class methods:
-
static
fromPEMFile
(args*)¶ Read the key pair from a PEM file.
If the file is not protected by a password, then just provide one argument (the file name). If the file is protected by a password, then provide 2 arguments (the file name must be the first argument, the password must be the second argument).
Parameters: - fileName (
str
) – The filename, e.g. “keypair.pem” or “somefolder/keypair.pem” or an absolute path. - password (
str
) – The password of the file.
Returns: A new PkiRsaKeyPair instance.
Return type: - fileName (
-
static
checkKeyPair
(args*)¶ Check if a public and private key pair matches.
Parameters: - publicKey (
PkiPublicKey
) – The public key. - privateKey (
PkiPrivateKey
) – The private key.
Returns: True if the keys match, False if not.
Return type: bool
Warning
This method may crash when empty keys are checked, due to a bug in the SDK!!! Bug present in SDK v1.4.2.
- publicKey (
-
static
Instance Methods:
-
__init__
(bits = 1024)¶ Construct a new PkiRsaKeyPair.
Parameters: bits ( int
) – The encryption bitsize.
-
privateKey
()¶ Get the private key of this pair.
Returns: The private key. Return type: PkiPrivateKey
-
publicKey
()¶ Get the public key of this pair.
Returns: The public key. Return type: PkiPublicKey
-
toPEMFile
(args*)¶ Write the key pair to an unprotected PEM file.
If the file is not protected by a password, then just provide one argument (the file name). If the file is protected by a password, then provide 2 arguments (the file name must be the first argument, the password must be the second argument).
Note that the directories in which the file should reside, must already exist! This function will only create a file, no directories!
Parameters: - fileName (
str
) – The filename, e.g. “keypair.pem” or “somefolder/keypair.pem” or an absolute path. - password (
str
) – The password of the file.
Returns: exit code (0 on success).
Return type: int
- fileName (
-
toDER
()¶ Write the key pair to a DER encoded
bytearray
.Returns: The DER encoded bytearray. Return type: bytearray
-
isValid
()¶ Check if the key pair is valid.
Returns: True if the key pair is valid, False if not. Return type: bool
-
getErrors
()¶ Get a list of errors.
Returns: A list of error descriptions. Return type: list
ofstr
-
class PkiIdentity¶
-
class
pyuaf.util.
PkiIdentity
(*args)¶ - PkiIdentity holds the identity of the subject and issuer of a certificate.
Methods:
Attributes:
-
organization
¶ The organization as a string (type
str
).
-
organizationUnit
¶ The organization unit as a string (type
str
).
-
locality
¶ The locality as a string (type
str
).
-
state
¶ The state as a string (type
str
).
-
country
¶ The country code as a string (type
str
).Note that invalid data (e.g. “Belgium” instead of the correct “BE”) will be stored by the PkiIdentity, but this data may get lost when it is converted to a X509 certificate.
-
commonName
¶ The common name as a string (type
str
).
-
domainComponent
¶ The domain component as a string (type
str
).
-
class QualifiedName¶
-
class
pyuaf.util.
QualifiedName
(*args)¶ An QualifiedName consists of a name and a corresponding namespace index or namespace URI.
Methods:
-
__init__
([name[, nameSpaceUri[, nameSpaceIndex]]])¶ Construct a new QualifiedName in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import QualifiedName >>> name = "MyName" >>> nsUri = "myNameSpaceUri" >>> nsIndex = 2 >>> # the following ways of constructing a QualifiedName are possible: >>> qName0 = QualifiedName() # incomplete, no information given! >>> qName1 = QualifiedName(name) # incomplete, no namespace information! >>> qName2 = QualifiedName(name, nsUri) # OK, fully qualified >>> qName3 = QualifiedName(name, nsIndex) # OK, fully qualified >>> qName4 = QualifiedName(name, nsUri, nsIndex) # OK, fully qualified >>> # strings are assumed to be UTF-8 encoded! >>> unicodeObject = u"40\u00B0 Celsius ist eine hei\u00DFe Temperatur!" >>> qName5 = QualifiedName(unicodeObject.encode("UTF-8"), nsUri)
-
hasNameSpaceUri
()¶ Check if a non-empty namespace URI was given.
Returns: True if this QualifiedName contains a non-empty server URI, False if not. Return type: bool
-
hasNameSpaceIndex
()¶ Check if a namespace index was given.
Returns: True if a namespaceIndex has been defined, False if not. Return type: bool
-
name
()¶ Get the name part of the QualifiedName.
Returns: The name part. Return type: str
-
nameSpaceUri
()¶ Get the namespace URI of the QualifiedName.
This function will always return a string, so call hasNameSpaceUri() to see if it’s a valid one.
Returns: The namespace URI. Return type: str
-
nameSpaceIndex
()¶ Get the namespace index of the QualifiedName.
This function will always return an
int
, so call hasNameSpaceIndex() to see if it’s a valid one.Returns: The namespace index. Return type: int
-
setName
(name)¶ Set the name part of the QualifiedName.
Parameters: name ( str
) – The name part.
-
setNameSpaceUri
(uri)¶ Set the namespace URI of the QualifiedName.
Parameters: uri ( str
) – The namespace URI.
-
setNameSpaceIndex
(index)¶ Set the namespace index of the QualifiedName.
Parameters: uri ( int
) – The namespace index.
-
class QualifiedNameVector¶
-
class
pyuaf.util.
QualifiedNameVector
(*args)¶ A QualifiedNameVector is a container that holds elements of type
pyuaf.util.QualifiedName
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofQualifiedName
.Usage example:
>>> import pyuaf >>> from pyuaf.util import QualifiedNameVector, QualifiedName >>> # construct a QualifiedNameVector without elements: >>> vec = QualifiedNameVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(QualifiedName("some name", "/some/URI/")) >>> noOfElements = len(vec) # will be 1 >>> vec.resize(2) >>> vec[1].setName("Some other name") >>> vec[1].setNameSpaceUri("/some/other/URI/") >>> noOfElements = len(vec) # will be 2 >>> # you may construct a QualifiedNameVector from a regular Python list: >>> someOtherVec = QualifiedNameVector( [ QualifiedName("a", "uriA"), ... QualifiedName("b", "uriB") ] )
class Range¶
-
class
pyuaf.util.
Range
(*args)¶ A Range conveys information about the highest and lowest value of a variable.
Methods:
-
__init__
(*args)¶ Construct a new Range in one of the following ways:
>>> import pyuaf >>> from pyuaf.util import Range, ExtensionObject >>> range1 = Range() >>> range2 = Range(ExtensionObject()) >>> range3 = Range(0.0, 100.0)
-
clear
()¶ Clear the object.
-
getLow
()¶ Get the low value as a
`float`
.
-
getHigh
()¶ Get the high value as a
`float`
.
-
setLow
(value)¶ Set the low value.
Parameters: low ( `float`
.) – The low value.
-
setHigh
(value)¶ Set the high value.
Parameters: high ( `float`
.) – The high value.
-
class ReferenceDescription¶
-
class
pyuaf.util.
ReferenceDescription
(*args)¶ A ReferenceDescription instance describes a Reference to a specific Node in some address space.
Methods:
Attributes:
-
referenceTypeId
¶ The NodeId (as a
pyuaf.util.NodeId
) of the type of the reference.
-
isForward
¶ A
bool
:True
if the server followed a forward reference,False
if not.
-
nodeId
¶ The ExpandedNodeId (as a
pyuaf.util.ExpandedNodeId
) of the node to which the reference is pointing.
-
browseName
¶ The browse name (as a
pyuaf.util.QualifiedName
) of the node to which the reference is pointing.
-
displayName
¶ The display name (as a
pyuaf.util.LocalizedText
) of the node to which the reference is pointing.
-
nodeClass
¶ The node class of the node to which the reference is pointing, as an
int
as defined in thepyuaf.util.nodeclasses
module.
-
typeDefinition
¶ The ExpandedNodeId (as a
pyuaf.util.ExpandedNodeId
) of the type of the node to which the reference is pointing to (only in case the node class of this node is an Object or a Variable).
-
class ReferenceDescriptionVector¶
-
class
pyuaf.util.
ReferenceDescriptionVector
(*args)¶ A ReferenceDescriptionVector is a container that holds elements of type
pyuaf.util.ReferenceDescription
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofReferenceDescription
.Usage example:
>>> import pyuaf >>> from pyuaf.util import ReferenceDescriptionVector, ReferenceDescription, ExpandedNodeId >>> # construct a ReferenceDescriptionVector without elements: >>> vec = ReferenceDescriptionVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(ReferenceDescription()) >>> noOfElements = len(vec) # will be 1 >>> vec.resize(2) >>> vec[1].nodeId = ExpandedNodeId("SomeId", "SomeNameSpace", "SomeServerUri") >>> vec[1].nodeClass = pyuaf.util.nodeclasses.Variable >>> noOfElements = len(vec) # will be 2 >>> # you may construct a ReferenceDescriptionVector from a regular Python list: >>> someOtherVec = ReferenceDescriptionVector( [ ReferenceDescription(), ... ReferenceDescription() ] )
class RelativePath¶
-
class
pyuaf.util.
RelativePath
(*args)¶ A RelativePath is a container that holds elements of type
pyuaf.util.RelativePathElement
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofpyuaf.util.RelativePathElement
.Usage example:
>>> import pyuaf >>> from pyuaf.util import RelativePath, RelativePathElement >>> # construct a RelativePath without elements: >>> path = RelativePath() >>> noOfElements = len(path) # will be 0 >>> path.append(RelativePathElement()) >>> noOfElements = len(path) # will be 1 >>> path.resize(4) >>> noOfElements = len(path) # will be 4 >>> element0 = path[0] >>> # you may construct a RelativePath from a regular Python list: >>> someOtherPath = RelativePath( [RelativePathElement(), RelativePathElement()] )
class RelativePathElement¶
-
class
pyuaf.util.
RelativePathElement
(*args)¶ A RelativePathElement describes one element of a RelativePath and basically contains a target (a qualified name), the type of the reference to this target, and some other properties.
Methods:
-
__init__
(*args)¶ Construct a NodeIdIdentifier by providing a string or a numeric value (or nothing at all).
You can construct a RelativePathElement like this:
>>> import pyuaf >>> from pyuaf.util import RelativePathElement, QualifiedName, NodeId >>> from pyuaf.util.opcuaidentifiers import OpcUaId_HierarchicalReferences >>> elem0 = RelativePathElement() >>> elem1 = RelativePathElement(QualifiedName("SomeBrowseName", 42)) >>> elem2 = RelativePathElement(QualifiedName("SomeBrowseName", 42), NodeId(OpcUaId_HierarchicalReferences, 0), True, False)
-
Attributes:
-
targetName
¶ The target name (a
QualifiedName
).
-
isInverse
¶ Flag specifying whether or not the inverse reference is meant (as a
bool
).
-
includeSubtypes
¶ Flag specifying if subtypes of the reference type should be included (as a
bool
).
-
class SdkStatus¶
-
class
pyuaf.util.
SdkStatus
(*args)¶ An SdkStatus stores the information (i.e. status code and message) of a Status object by the SDK.
Methods:
-
__init__
(*args)¶ Construct a new SdkStatus.
-
isGood
()¶ Check if the status has a “good” status code.
Returns: True if the status is Good. Return type: bool
-
isNotGood
()¶ Check if the status does not have a “good” status code.
Returns: True if the status is not Good. Return type: bool
-
isUncertain
()¶ Check if the status has an “uncertain” status code.
Returns: True if the status is Uncertain. Return type: bool
-
isNotUncertain
()¶ Check if the status does not have a “uncertain” status code.
Returns: True if the status is not Uncertain. Return type: bool
-
isBad
()¶ Check if the status has a “bad” status code.
Returns: True if the status is Bad. Return type: bool
-
isNotBad
()¶ Check if the status does not have a “bad” status code.
Returns: True if the status is not Bad. Return type: bool
-
Attributes:
-
statusCode
¶ Get the OPC UA status code.
OPC UA status codes are not the same as UAF status codes! See the
pyuaf.util.opcuastatuscodes
andpyuaf.util.statuscodes
modules for more info!Returns: The OPC UA status code, as defined by pyuaf.util.opcuastatuscodes
.Return type: int
-
message
¶ Get the message of the SDK status.
Returns: The message of the status. Return type: str
-
class ServerOnNetwork¶
-
class
pyuaf.util.
ServerOnNetwork
(*args)¶ A ServerOnNetwork instance describes a Server found on the network using the FindServersOnNetwork service.
class ServerOnNetworkVector¶
-
class
pyuaf.util.
ServerOnNetworkVector
(*args)¶ A ServerOnNetworkVector is a container that holds elements of type
pyuaf.util.ServerOnNetwork
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofpyuaf.util.ServerOnNetwork
.Usage example:
>>> import pyuaf >>> from pyuaf.util import ServerOnNetworkVector, \ ... ServerOnNetwork >>> # construct a ServerOnNetworkVector without elements: >>> vec = ServerOnNetworkVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(ServerOnNetwork()) >>> vec[0].discoveryUrl = "opc.tcp://192.168.100.102" >>> noOfElements = len(vec) # will be 1 >>> vec.resize(4) >>> noOfElements = len(vec) # will be 4 >>> # you may construct a ServerOnNetworkVector from a regular Python list: >>> someOtherVec = ServerOnNetworkVector( [ ServerOnNetwork(), ... ServerOnNetwork() ] )
class SimpleAttributeOperand¶
-
class
pyuaf.util.
SimpleAttributeOperand
(*args)¶ A SimpleAttributeOperand is part of a filter and can describe select clauses, where clauses, etc.
Methods:
Attributes:
-
attributeId
¶ The attribute id (e.g.
pyuaf.util.attributeids.Value
) as anint
as defined inpyuaf.util.attributeids
.
-
browsePath
¶ A “simple” browse path (actually just a list of qualified names), as a
QualifiedNameVector
.
-
indexRange
¶ The index range of an array, as a
str
.
-
class SimpleAttributeOperandVector¶
-
class
pyuaf.util.
SimpleAttributeOperandVector
(*args)¶ A SimpleAttributeOperandVector is a container that holds elements of type
pyuaf.util.SimpleAttributeOperand
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofpyuaf.util.SimpleAttributeOperand
.Usage example:
>>> import pyuaf >>> from pyuaf.util import SimpleAttributeOperandVector, \ ... SimpleAttributeOperand, \ ... QualifiedName, \ ... NodeId >>> # construct a SimpleAttributeOperandVector without elements: >>> vec = SimpleAttributeOperandVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(SimpleAttributeOperand()) >>> vec[0].attributeId = pyuaf.util.attributeids.Value >>> vec[0].browsePath.append(QualifiedName("some name", 3)) >>> vec[0].typeId = NodeId(pyuaf.util.opcuaidentifiers.OpcUaId_BaseEventType, 0) >>> noOfElements = len(vec) # will be 1 >>> vec.resize(4) >>> noOfElements = len(vec) # will be 4 >>> # you may construct a SimpleAttributeOperandVector from a regular Python list: >>> someOtherVec = SimpleAttributeOperandVector( [ SimpleAttributeOperand(), ... SimpleAttributeOperand() ] )
class Status¶
-
class
pyuaf.util.
Status
(*args)¶ - A Status object holds a UAF status code, a message and an OPC UA status code.
Attributes:
-
statusCode
¶ The UAF status code (an
int
as defined bypyuaf.util.statuscodes
).UAF status codes are not the same as OPC UA status codes! For each UAF status code (except for Good and Uncertain), there is a corresponding error. See the
pyuaf.util.statuscodes
andpyuaf.util.opcuastatuscodes
modules for more info!
-
Methods:
-
__init__
(*args)¶ Construct a Status by providing a UAF status code (as defined by
pyuaf.util.statuscodes
).UAF Status objects are Uncertain by default.
You can construct a Status like this:
>>> import pyuaf >>> from pyuaf.util import Status, statuscodes >>> from pyuaf.util.errors import InvalidServerUriError >>> status0 = Status() # Uncertain by default! >>> status1 = Status(statuscodes.Good) >>> status2 = Status(InvalidServerUriError("http://invalid/server/uri"))
-
test
()¶ Important method: raise an error if the status is Bad! E.g. if ~pyuaf.util.Status.statusCode equals pyuaf.util.statuscodes.InvalidServerUriError, then a pyuaf.util.errors.InvalidServerUriError will be raised! If the ~pyuaf.util.Status.statusCode attribute is ~pyuaf.util.statuscodes.Good or ~pyuaf.util.statuscodes.Uncertain, nothing will happen when you call this method.
-
setGood
()¶ Set the status to Good.
-
setUncertain
()¶ Set the status to Uncertain.
-
isGood
()¶ Check if the status has a “good” status code.
Returns: True if the status is Good. Return type: bool
-
isNotGood
()¶ Check if the status does not have a “good” status code.
Returns: True if the status is not Good. Return type: bool
-
isUncertain
()¶ Check if the status has an “uncertain” status code.
Returns: True if the status is Uncertain. Return type: bool
-
isNotUncertain
()¶ Check if the status does not have a “uncertain” status code.
Returns: True if the status is not Uncertain. Return type: bool
-
isBad
()¶ Check if the status has a “bad” status code.
Returns: True if the status is Bad. Return type: bool
-
isNotBad
()¶ Check if the status does not have a “bad” status code.
Returns: True if the status is not Bad. Return type: bool
-
statusCodeName
()¶ Get the name of the UAF status code.
UAF status codes are not the same as OPC UA status codes! See the
pyuaf.util.statuscodes
andpyuaf.util.opcuastatuscodes
modules for more info!Returns: The name of the UAF status code. Return type: str
-
summarize
(statuses)¶ Make a “summary” of other statuses.
Bad is dominant to Uncertain, which is dominant to Good. So if any Bad status is present, the summary will be “Bad”. If no Bad statuses are present but any Uncertain status is present, the summary will be Uncertain. And if only Good statuses are present, the summary will be Good.
Parameters: statuses ( pyuaf.util.StatusVector
.) – The statuses to summarize.
-
isRaisedBy
()¶ Check if this (bad!) status is raised by some other status.
Returns: True if this status was raised by some other status. Return type: bool
-
class StatusVector¶
-
class
pyuaf.util.
StatusVector
(*args)¶ A StatusVector is a container that holds elements of type
pyuaf.util.Status
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofpyuaf.util.Status
.Usage example:
>>> import pyuaf >>> from pyuaf.util import Status, StatusVector >>> # construct a StatusVector without elements: >>> statuses = StatusVector() >>> noOfElements = len(statuses) # will be 0 >>> statuses.append(Status()) >>> noOfElements = len(statuses) # will be 1 >>> statuses.resize(4) >>> noOfElements = len(statuses) # will be 4 >>> element0 = statuses[0] >>> # you may construct a StatusVector from a regular Python list: >>> otherStatuses = StatusVector( [Status(), Status()] )
class StringVector¶
-
class
pyuaf.util.
StringVector
(*args)¶ A StringVector is a container that holds string elements. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as a
list
of string.Usage example:
# examples/pyuaf/util/how_to_use_a_stringvector.py """ Example: how to use a StringVector ==================================================================================================== A StringVector is a container that holds string elements. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as a list of str. See the HTML documentation of PyUAF for more info! """ import pyuaf from pyuaf.util import StringVector # construct a StringVector without elements: strings = StringVector() noOfElements = len(strings) # will be 0 print("noOfElements (should be 0): %d" %noOfElements) strings.append("foo") noOfElements = len(strings) # will be 1 print("noOfElements (should be 1): %d" %noOfElements) strings.resize(4) noOfElements = len(strings) # will be 4 print("noOfElements (should be 4): %d" %noOfElements) # The first element (index 0) is "foo", the other 3 elements are empty strings ("") # So we fill these strings now: strings[1] = "x" strings[2] = "y" strings[3] = "z" print("'strings' element 0: %s" %strings[0]) print("'strings' element 1: %s" %strings[1]) print("'strings' element 2: %s" %strings[2]) print("'strings' element 3: %s" %strings[3]) # you may also construct a StringVector from a regular Python list: otherStrings = StringVector( ["foo", "bar"] ) print("'otherStrings' element 0: %s" %otherStrings[0]) print("'otherStrings' element 1: %s" %otherStrings[1])
class StructureDefinition¶
-
class
pyuaf.util.
StructureDefinition
(*args)¶ A StructureDefinition instance defines the fields of structures and unions.
See also
Check out example How to read and write structures? for more information.
Methods:
-
__init__
(*args)¶ Construct a new StructureDefinition in one of the following ways:
-
isNull
()¶ True
if the definition is NULL,False
if not.
-
clear
()¶ Clear the definition.
-
setName
(name)¶ Change the name of the structure.
Parameters: name ( str
) – The new name of the structure.
-
name
()¶ Get the name of the structure
Returns: The name of the structure definition Return type: str
-
setDocumentation
(doc)¶ Change the documentation of the structure.
Parameters: documentation ( LocalizedText
) – The new documentation of the structure.
-
documentation
()¶ Get the name of the documentation
Returns: The documentation of the structure definition Return type: LocalizedText
-
setNamespace
(name)¶ Change the namespace of the structure.
Parameters: namespace ( str
) – The new namespace of the structure.
-
getNamespace
()¶ Get the namespace of the structure
Returns: The namespace of the structure definition Return type: str
-
setBaseType
(baseType)¶ Change the base type of the definition.
Parameters: baseType ( StructureDefinition
) – The base type.
-
baseTypeId
()¶ Get the base type of the structure
Returns: The namespace of the structure definition Return type: NodeId
-
createSubtype
()¶ Create and return a subtype.
Returns: A subtype of the structure definition. Return type: StructureDefinition
-
childrenCount
()¶ Get the number of children.
Returns: The number of children of the definition. Return type: int
-
child
(i)¶ Get the specified child.
Parameters: i ( int
) – The index of the child.Returns: The field. Return type: StructureField
-
addChild
(newChild)¶ Add the given child.
Parameters: newChild ( StructureField
) – The new child.
-
remove
(fieldName)¶ Remove the field with the given name.
Parameters: i ( str
) – The name of the field.
-
isUnion
()¶ Does the definition represent a Union?
Returns: True if it’s a union. Return type: bool
-
setBinaryEncodingId
(nodeId)¶ Set the binary encoding ID.
Parameters: nodeId ( NodeId
) – The encoding NodeId.
-
setXmlEncodingId
(nodeId)¶ Set the XML encoding ID.
Parameters: nodeId ( NodeId
) – The encoding NodeId.
-
__str__
(*args)¶ Get a string representation.
-
class StructureField¶
-
class
pyuaf.util.
StructureField
(*args)¶ A StructureField holds a field of a StructureDefinition (it wraps the SDK UaStructureField quite literally).
See also
Check out example How to read and write structures? for more information.
Class attributes:
Methods:
-
__init__
(*args)¶ Construct a new StructureField.
-
isNull
()¶ Is the name of the field empty?
Returns: True if the name is empty. Return type: bool
-
name
()¶ Get the name of the field.
Returns: The name of the field. Return type: str
-
setName
(name)¶ Set the name of the field.
Parameters: name ( str
) – New name.
-
documentation
()¶ Get the documentation of the field.
Returns: The documentation of the field. Return type: LocalizedText
-
setDocumentation
(doc)¶ Set the documentation of the field.
Parameters: name ( LocalizedText
) – New documentation.
-
setDataTypeId
(dataTypeId)¶ Set the datatype id of the field.
Parameters: name ( NodeId
) – New datatype id.
-
typeId
()¶ Get the datatype id of the field.
Returns: The documentation of the field. Return type: NodeId
-
valueType
()¶ Get the built-in OPC UA type of the field.
Returns: An int
defined inpyuaf.util.opcuatypes
Return type: int
-
setValueType
(valueType)¶ Set the built-in OPC UA type of the field.
Parameters: valueType ( int
) – Anint
defined inpyuaf.util.opcuatypes
-
arrayType
()¶ Get the array type of the field.
Returns: Either ArrayType_Scalar
orArrayType_Array
Return type: int
-
setArrayType
(arrayType)¶ Set the array type of the field.
Parameters: arrayType ( int
) – EitherArrayType_Scalar
orArrayType_Array
-
GenericStructureValue.
unsetField
(*args)¶ Unset a field.
The field can be specified via the only argument: either:
- the number of the field (an
int
) - or the name of the field (a
str
).
Returns: The status: Good if the field could be unset, Bad otherwise. The statusCode
of theSdkStatus
will beOpcUa_BadInvalidArgument
if the specified field could not be found.Return type: SdkStatus
- the number of the field (an
-
GenericStructureValue.
valueType
(index)¶ Get the datatype (built-in type, structure, structure array, union, ...) of a field.
The field can be specified via the index argument.
Parameters: index ( int
) – Index of the field.This method will return a tuple of (type, statuscode).
- the type is a Python
int
, as defined bypyuaf.util.structurefielddatatypes
. - the statuscode is an
int
, as defined bypyuaf.util.opcuastatuscodes
. It will beOpcUa_BadInvalidArgument
if the index is out of range, orOpcUa_Good
otherwise.
- the type is a Python
-
GenericStructureValue.
toExtensionObject
(*args)¶ Convert the structure into an
ExtensionObject
.This ExtensionObject can be written back to the server, e.g. after some fields have been changed.
Parameters: - extensionObject (
ExtensionObject
) – The ExtensionObject to update. - encoding (
int
) – Optional argument: the encoding for the ExtensionObject. If not specified, then the default valueEncoding_Binary
will be used.
- extensionObject (
-
GenericStructureValue.
__str__
(*args)¶ Get a string representation.
-
class UInt32Vector¶
-
class
pyuaf.util.
UInt32Vector
(*args)¶ An UInt32Vector is a container that holds unsigned 32-bit
int
elements (notUInt32
objects!)It is an artifact automatically generated from the C++ UAF code, and has the same functionality as a
list
ofint
.An
UInt32Vector
is exactly the same as aStringVector
, except of course that it holdsint
elements instead ofstr
elements. For an elaborate example, check out the example at theStringVector
documentation.
class UserTokenPolicy¶
-
class
pyuaf.util.
UserTokenPolicy
(*args)¶ A UserTokenPolicy instance describes the type, ID, issued token type, etc. of a user token.
Methods:
-
__init__
(*args)¶ Construct a new UserTokenPolicy.
-
Attributes:
-
policyId
¶ The policy ID as a
str
, as defined inpyuaf.util.securitypolicies
.By default, the policyId is
UA_None
.
-
tokenType
¶ The token type (e.g.
UserName
) (anint
, as defined inpyuaf.util.usertokentypes
).By default, the tokenType is
Anonymous
.
-
issuedTokenType
¶ The issued token type as a
str
.
-
issuerEndpointUrl
¶ The issuer endpoint URL as a
str
.
-
securityPolicyUri
¶ The security policy URI as a
str
.
-
class UserTokenPolicyVector¶
-
class
pyuaf.util.
UserTokenPolicyVector
(*args)¶ A QualifiedNameVector is a container that holds elements of type
UserTokenPolicy
. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as alist
ofUserTokenPolicy
.Usage example:
>>> import pyuaf >>> from pyuaf.util import UserTokenPolicyVector, UserTokenPolicy >>> # construct a UserTokenPolicyVector without elements: >>> vec = UserTokenPolicyVector() >>> noOfElements = len(vec) # will be 0 >>> vec.append(UserTokenPolicy()) >>> vec[0].policyId = pyuaf.util.securitypolicies.UA_Basic128Rsa15 >>> noOfElements = len(vec) # will be 1 >>> vec.resize(2) >>> vec[1].policyId = pyuaf.util.securitypolicies.UA_Basic256Rsa15 >>> noOfElements = len(vec) # will be 2 >>> # you may construct a UserTokenPolicyVector from a regular Python list: >>> someOtherVec = UserTokenPolicyVector( [ UserTokenPolicy(), UserTokenPolicy() ] )
class VariantVector¶
-
class
pyuaf.util.
VariantVector
(*args)¶ A VariantVector is a container that holds variants (so variables with a dynamic data type). It is an artifact automatically generated from the C++ UAF code, and has the same functionality as a
list
of values, where the values can be instances of:None
(for a NULL value)- a primitive:
pyuaf.util.primitives.Boolean
pyuaf.util.primitives.SByte
pyuaf.util.primitives.Byte
pyuaf.util.primitives.UInt16
pyuaf.util.primitives.Int16
pyuaf.util.primitives.UInt32
pyuaf.util.primitives.Int32
pyuaf.util.primitives.UInt64
pyuaf.util.primitives.Int64
pyuaf.util.primitives.Float
pyuaf.util.primitives.Double
pyuaf.util.primitives.String
pyuaf.util.primitives.ByteString
- a non-primitive such as:
a
list
of any of the above types. This list represents an OPC UA array, so all items of this list should have the same type!!!
See also
Usage example:
# examples/pyuaf/util/how_to_use_a_variantvector.py """ Example: how to use a VariantVector ==================================================================================================== A VariantVector is a container that holds elements of a dynamic data type. It is an artifact automatically generated from the C++ UAF code, and has the same functionality as a list of variables values, where the values can be instances of: - None - pyuaf.util.primitives.Boolean - pyuaf.util.primitives.UInt32 - pyuaf.util.QualifiedName - pyuaf.util.LocalizedText - ... See the HTML documentation of PyUAF for more info! """ import pyuaf from pyuaf.util import VariantVector # construct a VariantVector without elements: vec = VariantVector() noOfElements = len(vec) print("noOfElements (should be 0): %d" %noOfElements) # now we append an unsigned 32-bit integer, a boolean, and a localized text: vec.append( pyuaf.util.primitives.UInt32(1234) ) vec.append( pyuaf.util.primitives.Boolean(True) ) vec.append( pyuaf.util.LocalizedText("en", "Some text.") ) noOfElements = len(vec) print("noOfElements (should be 3): %d" %len(vec)) print("Vector contents:") for i in xrange(noOfElements): print(" - vec[%d] = %s" %(i, repr(vec[i]))) # now we resize the vector so that it contains 4 elements (the last one being a None value) vec.resize(4) noOfElements = len(vec) print("noOfElements (should be 4): %d" %noOfElements) print("Vector contents:") for i in xrange(noOfElements): print(" - vec[%d] = %s" %(i, repr(vec[i]))) # now we append an array of Floats. # An OPC UA array can be defined as a python list. # All elements should have the same type, otherwise you will get a TypeError! vec.append( [pyuaf.util.primitives.Float(0.1), pyuaf.util.primitives.Float(0.2), pyuaf.util.primitives.Float(0.3) ] ) noOfElements = len(vec) print("noOfElements (should be 5): %d" %noOfElements) print("Vector contents:") for i in xrange(noOfElements): print(" - vec[%d] = %s" %(i, repr(vec[i]))) print("Vector contents, using iterators:") for element in vec: print(" - %s" %repr(element))