How to use the bacpypes.primitivedata.Tag 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_double.py View on Github external
def test_double_tag(self):
        if _debug: TestDouble._debug("test_double_tag")

        tag = Tag(Tag.applicationTagClass, Tag.doubleAppTag, 8, xtob('3ff0000000000000'))
        obj = Double(tag)
        assert obj.value == 1.0

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

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

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            Double(tag)
github JoelBender / bacpypes / tests / test_primitive_data / test_boolean.py View on Github external
def boolean_tag(value):
    """Convert an integer to an boolean application tag."""
    if _debug: boolean_tag._debug("boolean_tag %r", value)

    tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, int(value), xtob(''))
    if _debug: boolean_endec._debug("    - tag: %r", tag)

    return tag
github JoelBender / bacpypes / tests / test_primitive_data / test_double.py View on Github external
def test_double_tag(self):
        if _debug: TestDouble._debug("test_double_tag")

        tag = Tag(Tag.applicationTagClass, Tag.doubleAppTag, 8, xtob('3ff0000000000000'))
        obj = Double(tag)
        assert obj.value == 1.0

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

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

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            Double(tag)
github JoelBender / bacpypes / tests / test_primitive_data / test_object_identifier.py View on Github external
def object_identifier_tag(x):
    """Convert a hex string to an object_identifier application tag."""
    if _debug: object_identifier_tag._debug("object_identifier_tag %r", x)

    b = xtob(x)
    tag = Tag(Tag.applicationTagClass, Tag.objectIdentifierAppTag, len(b), b)
    if _debug: object_identifier_endec._debug("    - tag: %r", tag)

    return tag
github JoelBender / bacpypes / tests / test_primitive_data / test_bit_string.py View on Github external
def test_bit_string_tag(self):
        if _debug: TestBitString._debug("test_bit_string_tag")

        tag = Tag(Tag.applicationTagClass, Tag.bitStringAppTag, 1, xtob('08'))
        obj = BitString(tag)
        if _debug: TestBitString._debug("    - obj.value: %r", obj.value)
        assert obj.value == []

        tag = Tag(Tag.applicationTagClass, Tag.bitStringAppTag, 2, xtob('0102'))
        obj = BitString(tag)
        if _debug: TestBitString._debug("    - obj.value: %r", obj.value)
        assert obj.value == [0, 0, 0, 0, 0, 0, 1]

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

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

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            BitString(tag)
github JoelBender / bacpypes / tests / test_primitive_data / test_null.py View on Github external
def null_encode(obj):
    """Encode an Integer object into a tag."""
    if _debug: null_encode._debug("null_encode %r", obj)

    tag = Tag()
    obj.encode(tag)
    if _debug: null_encode._debug("    - tag: %r", tag)

    return tag
github JoelBender / bacpypes / tests / test_primitive_data / test_octet_string.py View on Github external
def octet_string_tag(x):
    """Convert a hex string to an octet_string application tag."""
    if _debug: octet_string_tag._debug("octet_string_tag %r", x)

    b = xtob(x)
    tag = Tag(Tag.applicationTagClass, Tag.octetStringAppTag, len(b), b)
    if _debug: octet_string_endec._debug("    - tag: %r", tag)

    return tag
github JoelBender / bacpypes / tests / test_primitive_data / test_real.py View on Github external
def test_real_tag(self):
        if _debug: TestReal._debug("test_real_tag")

        tag = Tag(Tag.applicationTagClass, Tag.realAppTag, 1, xtob('3f800000'))
        obj = Real(tag)
        assert obj.value == 1.0

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

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

        tag = Tag(Tag.openingTagClass, 0)
        with self.assertRaises(InvalidTag):
            Real(tag)
github JoelBender / bacpypes / samples / VendorReadWriteProperty.py View on Github external
# give it to the application
            deferred(this_application.request_io, iocb)

            # wait for it to complete
            iocb.wait()

            # do something for success
            if iocb.ioResponse:
                apdu = iocb.ioResponse

                # peek at the value tag
                value_tag = apdu.propertyValue.tagList.Peek()
                if _debug: ReadWritePropertyConsoleCmd._debug("    - value_tag: %r", value_tag)

                # make sure that it is application tagged
                if value_tag.tagClass != Tag.applicationTagClass:
                    sys.stdout.write("value is not application encoded\n")

                else:
                    # find the datatype
                    datatype = Tag._app_tag_class[value_tag.tagNumber]
                    if _debug: ReadWritePropertyConsoleCmd._debug("    - datatype: %r", datatype)
                    if not datatype:
                        raise TypeError("unknown datatype")

                    # cast out the value
                    value = apdu.propertyValue.cast_out(datatype)
                    if _debug: ReadWritePropertyConsoleCmd._debug("    - value: %r", value)

                    sys.stdout.write("%s (%s)\n" % (value, datatype))

                sys.stdout.flush()