Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Multiple request_dict Returns One #485

Open
chrisreichert53 opened this issue Sep 27, 2024 · 4 comments
Open

Read Multiple request_dict Returns One #485

chrisreichert53 opened this issue Sep 27, 2024 · 4 comments

Comments

@chrisreichert53
Copy link

I believe there is a bug in the readMultiple method when providing request_dict. It looks like in each iteration of the response, it resets the request_dict[object_identifier] to an empty list. This works fine for single properties but only returns the last property when multiple are provided.

BAC0/BAC0/core/io/Read.py

Lines 297 to 317 in ef972e3

if not isinstance(response, ErrorRejectAbortNack):
"""
TODO : Need improvement here and look for the property identifier that is coming from the response
Then we'll be able to support multiple properties for the same object in the read multiple function
"""
for (
object_identifier,
property_identifier,
property_array_index,
property_value,
) in response:
self._log.debug(
"{!r:<20} {!r:<20} {!r:<30} {!r:<20}".format(
property_identifier,
property_array_index,
property_value,
# datatype,
"",
)
)
dict_values[str(object_identifier)] = []

Suggestion in place of:

dict_values[str(object_identifier)] = []

to

if str(object_identifier) not in dict_values:
    dict_values[str(object_identifier)] = []
@ChristianTremblay
Copy link
Owner

If you can test develop branch, your proposal is added

Thanks

@ChristianTremblay
Copy link
Owner

@bill-clapham please add details as I thought it was fixed

@bill-clapham
Copy link

Hi Christian, thanks for looking in to this.
In the main branch of BAC0 2024.9.20 the bug highlighted by @chrisreichert53 on line 317 of Read.py is what was causing my error.
for document continuity I will add my code extracts.

Sample code

    bacnet = BAC0.start(BACNET_ADAPTER)
    _rpm = {'address': '192.168.2.100:47808',
              'objects': {'analogValue:14': ['objectName', 'presentValue', 'statusFlags', 'units'],
                          'analogValue:15': ['presentValue', 'objectName']}}

    readRes = await bacnet.readMultiple('192.168.2.100:47808', request_dict=_rpm)
    pprint(readRes)

Above code produced:

{'analog-value,14': [(<PropertyIdentifier: units>, <EngineeringUnits: degrees-celsius>)],
 'analog-value,15': [(<PropertyIdentifier: object-name>, "JesPl'CHEP_FCU_106'RHvacCoo'TCtlC'SpCPrt")]}

After making the suggested change to Read.py the same code produces:

{'analog-value,14': [(<PropertyIdentifier: object-name>, "JesPl'CHEP_FCU_106'RHvacCoo'TCtlC'SpCCmf"),
                     (<PropertyIdentifier: present-value>, 24.0),
                     (<PropertyIdentifier: status-flags>, <StatusFlags: >),
                     (<PropertyIdentifier: units>, <EngineeringUnits: degrees-celsius>)],
 'analog-value,15': [(<PropertyIdentifier: present-value>, 40.0),
                     (<PropertyIdentifier: object-name>, "JesPl'CHEP_FCU_106'RHvacCoo'TCtlC'SpCPrt")]}

The correct data is now shown but in a different structure as documented in https://bac0.readthedocs.io/en/latest/read.html

Using:
Python, Version 3.13
BAC0, Version: 2024.9.20
bacpypes3, Version: 0.0.98

Again, big thanks for your work Christian 👍👍

@ChristianTremblay
Copy link
Owner

Have you tried the develop branch to see if the issue is fixed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants