Commit 454bf64e authored by olivier R-D's avatar olivier R-D

cast int to enum for nodeclass and valuerank in BinaryClient.

parent eed7aa5c
......@@ -289,6 +289,16 @@ class BinaryClient(object):
data = self._uasocket.send_request(request)
response = ua.ReadResponse.from_binary(data)
response.ResponseHeader.ServiceResult.check()
# cast to Enum attributes that need to
for idx, rv in enumerate(parameters.NodesToRead):
if rv.AttributeId == ua.AttributeIds.NodeClass:
dv = response.Results[idx]
if dv.StatusCode.is_good():
dv.Value.Value = ua.NodeClass(dv.Value.Value)
elif rv.AttributeId == ua.AttributeIds.ValueRank:
dv = response.Results[idx]
if dv.StatusCode.is_good() and dv.Value.Value in (-3, -2, -1, 0, 1, 2, 3, 4):
dv.Value.Value = ua.ValueRank(dv.Value.Value)
return response.Results
def write(self, params):
......
......@@ -449,10 +449,10 @@ def _create_variable(server, parentnodeid, nodeid, qname, val, isproperty=False)
attrs.DataType = _guess_uatype(val)
attrs.Value = val
if isinstance(val, list) or isinstance(val, tuple):
attrs.ValueRank = 0
attrs.ValueRank = ua.ValueRank.OneDimension
else:
attrs.ValueRank = -1
# attrs.ArrayDimensions = 0
attrs.ValueRank = ua.ValueRank.Scalar
#attrs.ArrayDimensions = None
attrs.WriteMask = ua.OpenFileMode.Read
attrs.UserWriteMask = ua.OpenFileMode.Read
attrs.Historizing = 0
......
import struct
import logging
import hashlib
from enum import IntEnum
import opcua.uaprotocol_auto as auto
import opcua.uatypes as uatypes
......@@ -13,9 +14,27 @@ logger = logging.getLogger('opcua.uaprotocol')
OPC_TCP_SCHEME = 'opc.tcp'
class ValueRank(IntEnum):
"""
Defines dimensions of a variable.
This enum does not support all cases since ValueRank support any n>0
but since it is an IntEnum it can be replace by a normal int
"""
ScalarOrOneDimension = -3
Any = -2
Scalar = -1
OneOrMoreDimensions = 0
OneDimension = 1
# the next names are not in spec but so common we express them here
TwoDimensions = 2
ThreeDimensions = 3
FourDimensions = 3
class AccessLevelMask(object):
"""
used by AccessLevel and UserAccessLevel
Used by AccessLevel and UserAccessLevel
"""
CurrentRead = 0
CurrentWrite = 1
......
......@@ -765,7 +765,7 @@ class Variant(FrozenClass):
raise Exception("Could not guess UA type of {} with type {}, specify UA type".format(val, type(val)))
def __str__(self):
return "Variant(val:{},type:{})".format(self.Value, self.VariantType)
return "Variant(val:{!s},type:{})".format(self.Value, self.VariantType)
__repr__ = __str__
def to_binary(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment