Skip to content

Property dublicated across several devices #546

Description

@Harbringer1

Hello there! Great library!
I am working on a BACnet simulator that uses a JSON configuration to create devices and their objects with properties.
The problem is... let's say we have 2 devices:

  1. Device 18800, addr: "127.0.0.1/24:47809"
    • Objects: CharacterString:1 (PresentValue = "OBJECT 1. CHAR_STRING")

  2. Device 18801, addr: "127.0.0.1/24:47810"
    • Objects: CharacterString:1 (PresentValue = "OBJECT 2. CHAR_STRING")

Both devices have redefined the CharacterString data type for PresentValue.
Here's a snippet of my implementation of the CharacterString data type:
`
class CustomStringProperty(Property):
value = CharacterString("")

def __init__(self, identifier):
    Property.__init__(self, identifier, CharacterString, default=CharacterString(""), optional=False, mutable=False)

def ReadProperty(self, obj, arrayIndex=None):

    # access an array
    if arrayIndex is not None:
        raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray')
    # sleep(0)

    return CharacterString(self.value)

def WriteProperty(self, obj, value, arrayIndex=None, priority=None, direct=False):
    # print("StringProperty | Запись: " + value)
    self.value = CharacterString(value)
    # raise ExecutionError(errorClass='property', errorCode='writeAccessDenied')

def set_Props(self, initial_value, generation, errors):
    print("CustomStringProperty | Setting rules for generation. Initial presentValue: " + str(initial_value) + "Gen.Type: " + str(generation.type))
    self.value = initial_value

`

And the implementation of CharacterString:
`
class CustomCharacterStringValueObject(CharacterStringValueObject):

properties = [
    CustomStringProperty('presentValue'),
]

def __init__(self, **kwargs):
    CharacterStringValueObject.__init__(self, **kwargs)

def set_Props(self, generation, errors, initial_value):
    self.properties[0].set_Props(initial_value=CharacterString(initial_value), generation=generation, errors=errors)

register_object_type(CustomCharacterStringValueObject)
`

Now, here's an example of how I create objects:

def init_device(device):
new_device = LocalDeviceObject(vendorIdentifier=device.device_name, objectIdentifier=device.device_id)
new_application = EmulatorApplication(new_device, device.address)
for object in device.objects:
logger.info("Processing " + object.type + " ; NAME: " + object.name + " ; " + str(object.present_value))
if object.type == "CHARACTER_STRING":
obj = entities.CustomCharacterStringValueObject(
objectIdentifier=('characterstringValue', object.instance),
objectName=object.name,
description=object.description
)
obj.set_Props(object.generation, object.error, object.present_value)
new_application.add_object(obj)
allObjects.append(obj)

In screenshots 1 and 2, you can see what YABE displays:
Image
Image

The problem goes beyond this. If I overwrite, for example, (Device 18800) AnalogValue:1 (which is redefined as well), it overwrites all AnalogValues for other devices.

I am not actually a Python developer, so I don't know if this problem is caused by incorrect use of the language/library or if it's actually a bug...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions