JoelBender / bacpypes

BACpypes provides a BACnet application layer and network layer written in Python for daemons, scripting, and graphical interfaces.
MIT License
299 stars 129 forks source link

Stripped down way to send a single service on the network #537

Open tunamako opened 1 day ago

tunamako commented 1 day ago

Hello,

I maintain a BACnet-based test framework in python at my company that uses MBS's BTF as a basis for communicating over the network, but I was interested in switching to bacpypes because it's open source.

After tinkering with the examples I could get a pretty basic version of the 'ReadObjectList' sample running, but it still requires me to queue up the service request with 'deffered' and then call 'run()'. The problem is, in my environment we can send hundreds (or thousands) of requests to our devices in a single test and we do other processing in between them, such as making assertions, logging, and general test execution. Since I can't queue up every service ahead of time, will I need to call 'run()' for every BACnet service I want to send?

Thank you!

JoelBender commented 1 day ago

This project is the "legacy" version, please switch to the asyncio based BACpypes3 for Python3.8+ and you will find it much easier to use. The discover-objects.py sample application reads properties of objects from a device, the read-batch.py can read lots of properties from lots of devices "at the same time."

The short answer could be something like...

    async def test_function(...)
        rslt = await app.write_property(...)
        # log the result
        await asyncio.sleep(timeout)
        rslt = await app.read_property(...)
        # check the value
        ...

Calls to test_function() return a coroutine object that you can await for single threaded-like behavior, bundle into a group and asyncio.gather() the results, etc.