How to use the bacpypes.primitivedata.Unsigned function in bacpypes

To help you get started, we’ve selected a few bacpypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JoelBender / bacpypes / tests / test_primitive_data / test_unsigned.py View on Github external
def test_unsigned_tag(self):
        if _debug: TestUnsigned._debug("test_unsigned_tag")

        tag = Tag(Tag.applicationTagClass, Tag.unsignedAppTag, 1, xtob('01'))
        obj = Unsigned(tag)
        assert obj.value == 1

        tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob(''))
        with self.assertRaises(InvalidTag):
            Unsigned(tag)

        tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff'))
        with self.assertRaises(InvalidTag):
            Unsigned(tag)

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            Unsigned(tag)
github JoelBender / bacpypes / sandbox / xtest_issue_45.py View on Github external
priority = int(args[6])
            if _debug: TestConsoleCmd._debug("    - priority: %r", priority)

            # get the datatype
            datatype = get_datatype(obj_type, prop_id)
            if _debug: TestConsoleCmd._debug("    - datatype: %r", datatype)

            # change atomic values into something encodeable, null is a special case
            if (value == 'null'):
                value = Null()
            elif issubclass(datatype, Atomic):
                if datatype is Integer:
                    value = int(value)
                elif datatype is Real:
                    value = float(value)
                elif datatype is Unsigned:
                    value = int(value)
                value = datatype(value)
            elif issubclass(datatype, Array) and (indx is not None):
                if indx == 0:
                    value = Integer(value)
                elif issubclass(datatype.subtype, Atomic):
                    value = datatype.subtype(value)
                elif not isinstance(value, datatype.subtype):
                    raise TypeError, "invalid result datatype, expecting %s" % (datatype.subtype.__name__,)
            elif not isinstance(value, datatype):
                raise TypeError, "invalid result datatype, expecting %s" % (datatype.__name__,)
            if _debug: TestConsoleCmd._debug("    - encodeable value: %r %s", value, type(value))

            # build a request
            request = WritePropertyRequest(
                objectIdentifier=(obj_type, obj_inst),
github JoelBender / bacpypes / tests / test_primitive_data / test_unsigned.py View on Github external
def unsigned_endec(v, x):
    """Pass the value to Unsigned, construct a tag from the hex string,
    and compare results of encode and decoding each other."""
    if _debug: unsigned_endec._debug("unsigned_endec %r %r", v, x)

    tag = unsigned_tag(x)
    if _debug: unsigned_endec._debug("    - tag: %r, %r", tag, tag.tagData)

    obj = Unsigned(v)
    if _debug: unsigned_endec._debug("    - obj: %r, %r", obj, obj.value)

    assert unsigned_encode(obj) == tag
    assert unsigned_decode(tag) == obj
github JoelBender / bacpypes / tests / test_objects / test_MultiStateInputObject.py View on Github external
self.identifiers = self.build_list_of_identifiers(self.obj.properties)
        self.numberOfPropertiesRequired = 23
        self.writeValue = 0
        self.listOfProperties = \
        [ (ReadableProperty,'presentValue', Unsigned)
        , (OptionalProperty,'deviceType', CharacterString)
        , (ReadableProperty,'statusFlags', StatusFlags)
        , (ReadableProperty,'eventState', EventState)
        , (OptionalProperty,'reliability', Reliability)
        , (ReadableProperty,'outOfService', Boolean)
        , (ReadableProperty,'numberOfStates', Unsigned)
        , (OptionalProperty,'stateText', ArrayOf(CharacterString))
        , (OptionalProperty,'timeDelay', Unsigned)
        , (OptionalProperty,'notificationClass', Unsigned)
        , (OptionalProperty,'alarmValues', SequenceOf(Unsigned))
        , (OptionalProperty,'faultValues', SequenceOf(Unsigned))
        , (OptionalProperty,'eventEnable', EventTransitionBits)
        , (OptionalProperty,'ackedTransitions', EventTransitionBits)
        , (OptionalProperty,'notifyType', NotifyType)
        , (OptionalProperty,'eventTimeStamps', ArrayOf(TimeStamp))
        , (OptionalProperty,'eventMessageTexts', ArrayOf(CharacterString))
        , (OptionalProperty,'eventMessageTextsConfig', ArrayOf(CharacterString))
        , (OptionalProperty,'eventDetectionEnable', Boolean)
        , (OptionalProperty,'eventAlgorithmInhibitRef', ObjectPropertyReference)
        , (OptionalProperty,'eventAlgorithmInhibit', Boolean)
        , (OptionalProperty,'timeDelayNormal', Unsigned)
        , (OptionalProperty,'reliabilityEvaluationInhibit', Boolean)
        ]
github JoelBender / bacpypes / tests / test_primitive_data / test_unsigned.py View on Github external
def test_unsigned_int(self):
        if _debug: TestUnsigned._debug("test_unsigned_int")

        obj = Unsigned(1)
        assert obj.value == 1
        assert str(obj) == "Unsigned(1)"

        with self.assertRaises(ValueError):
            Unsigned(-1)
github JoelBender / bacpypes / tests / test_primitive_data / test_unsigned.py View on Github external
def unsigned_decode(tag):
    """Decode an unsigned application tag into an unsigned."""
    if _debug: unsigned_decode._debug("unsigned_decode %r", tag)

    obj = Unsigned(tag)
    if _debug: unsigned_decode._debug("    - obj: %r", obj)

    return obj
github JoelBender / bacpypes / tests / test_objects / test_ProgramObject.py View on Github external
self.objType = 'program'
        self.identifiers = self.build_list_of_identifiers(self.obj.properties)
        self.numberOfPropertiesRequired = 18
        self.writeValue = 0
        self.listOfProperties = \
        [ (ReadableProperty,'programState', ProgramState)
        , (WritableProperty,'programChange', ProgramRequest)
        , (OptionalProperty,'reasonForHalt', ProgramError)
        , (OptionalProperty,'descriptionOfHalt', CharacterString)
        , (OptionalProperty,'programLocation', CharacterString)
        , (OptionalProperty,'instanceOf', CharacterString)
        , (ReadableProperty,'statusFlags', StatusFlags)
        , (OptionalProperty,'reliability', Reliability)
        , (ReadableProperty,'outOfService', Boolean)
        , (OptionalProperty,'eventDetectionEnable', Boolean)
        , (OptionalProperty,'notificationClass', Unsigned)
        , (OptionalProperty,'eventEnable', EventTransitionBits)
        , (OptionalProperty,'ackedTransitions', EventTransitionBits)
        , (OptionalProperty,'notifyType', NotifyType)
        , (OptionalProperty,'eventTimeStamps', ArrayOf(TimeStamp))
        , (OptionalProperty,'eventMessageTexts', ArrayOf(CharacterString))
        , (OptionalProperty,'eventMessageTextsConfig', ArrayOf(CharacterString))
        , (OptionalProperty,'reliabilityEvaluationInhibit', Boolean)
        ]
github JoelBender / bacpypes / tests / test_objects / test_AlertEnrollmentObject.py View on Github external
def setUp(self):
        if _debug: Test_AlertEnrollmentObject._debug("Test_AlertEnrollmentObject")
        self.obj = AlertEnrollmentObject()
        self.objType = 'alertEnrollment'
        self.identifiers = self.build_list_of_identifiers(self.obj.properties)
        self.numberOfPropertiesRequired = 12
        self.writeValue = 0
        self.listOfProperties = \
        [ (ReadableProperty,'presentValue', ObjectIdentifier)
        , (ReadableProperty,'eventState', EventState)
        , (OptionalProperty,'eventDetectionEnable', Boolean)
        , (ReadableProperty,'notificationClass', Unsigned)
        , (OptionalProperty,'eventEnable', EventTransitionBits)
        , (OptionalProperty,'ackedTransitions', EventTransitionBits)
        , (OptionalProperty,'notifyType', NotifyType)
        , (OptionalProperty,'eventTimeStamps', ArrayOf(TimeStamp))
        , (OptionalProperty,'eventMessageTexts', ArrayOf(CharacterString))
        , (OptionalProperty,'eventMessageTextsConfig', ArrayOf(CharacterString))
        , (OptionalProperty,'eventAlgorithmInhibitRef', ObjectPropertyReference)
        , (OptionalProperty,'eventAlgorithmInhibit', Boolean)
        ]
github JoelBender / bacpypes / tests / test_objects / test_ChannelObject.py View on Github external
def setUp(self):
        if _debug: Test_ChannelObject._debug("Test_ChannelObject")
        self.obj = ChannelObject()
        self.objType = 'channel'
        self.identifiers = self.build_list_of_identifiers(self.obj.properties)
        self.numberOfPropertiesRequired = 21
        self.writeValue = 0
        self.listOfProperties = \
        [ (WritableProperty,'presentValue', ChannelValue)
        , (ReadableProperty,'lastPriority', Unsigned)
        , (ReadableProperty,'writeStatus', WriteStatus)
        , (ReadableProperty,'statusFlags', StatusFlags)
        , (OptionalProperty,'reliability', Reliability)
        , (ReadableProperty,'outOfService', Boolean)
        , (WritableProperty,'listOfObjectPropertyReferences', ArrayOf(DeviceObjectPropertyReference))
        , (OptionalProperty,'executionDelay', ArrayOf(Unsigned))
        , (OptionalProperty,'allowGroupDelayInhibit', Boolean)
        , (WritableProperty,'channelNumber', Unsigned)
        , (WritableProperty,'controlGroups', ArrayOf(Unsigned))
        , (OptionalProperty,'eventDetectionEnable', Boolean)
        , (OptionalProperty,'notificationClass', Unsigned)
        , (OptionalProperty,'eventEnable', EventTransitionBits)
        , (OptionalProperty,'eventState', EventState)
        , (OptionalProperty,'ackedTransitions', EventTransitionBits)
        , (OptionalProperty,'notifyType', NotifyType)
        , (OptionalProperty,'eventTimeStamps', ArrayOf(TimeStamp))
github JoelBender / bacpypes / tests / test_objects / test_AccessRightsObject.py View on Github external
def setUp(self):
        if _debug: Test_AccessRightsObject._debug("Test_AccessRightsObject")
        self.obj = AccessRightsObject()
        self.objType = 'accessRights'
        self.identifiers = self.build_list_of_identifiers(self.obj.properties)
        self.numberOfPropertiesRequired = 8
        self.writeValue = 0
        self.listOfProperties = \
        [ (WritableProperty,'globalIdentifier', Unsigned)
        , (ReadableProperty,'statusFlags', StatusFlags)
        , (ReadableProperty,'reliability', Reliability)
        , (ReadableProperty,'enable', Boolean)
        , (ReadableProperty,'negativeAccessRules', ArrayOf(AccessRule))
        , (ReadableProperty,'positiveAccessRules', ArrayOf(AccessRule))
        , (OptionalProperty,'accompaniment', DeviceObjectReference)
        , (OptionalProperty,'reliabilityEvaluationInhibit', Boolean)
        ]