[Python] How to use BAC0 to read from Bacnet.Room.Simulator

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I installed Yabe (Yet Another BACnet Simulator) and Room.Control.Simulator with that. Now I want to write a Python program to read the temperature values. This is the first step to better understand how to use the BAC0 library and the BACnet protocol.

    [​IMG]

    I tried this code to find the simulated device:

    import asyncio
    import BAC0


    async def main():
    bacnet = BAC0.start(ip="10.227.6.203", mask=24, port=47808)
    bacnet.discover()
    devices = await bacnet.devices
    print(devices)
    return devices


    if __name__ == "__main__":
    asyncio.run(main())


    and this is the error:

    [06/17/25 14:25:30] INFO 2025-06-17 14:25:30,554 - INFO | notes.py:267
    Starting Asynchronous BAC0 version
    2025.06.10 (Lite)
    INFO 2025-06-17 14:25:30,558 - INFO | notes.py:267
    Using bacpypes3 version 0.0.102
    INFO 2025-06-17 14:25:30,559 - INFO | notes.py:267
    Use BAC0.log_level to adjust
    verbosity of the app.
    INFO 2025-06-17 14:25:30,560 - INFO | notes.py:267
    Ex. BAC0.log_level('silence') or
    BAC0.log_level('error')
    INFO 2025-06-17 14:25:30,769 - INFO | Lite.py:173
    Using ip : 10.227.6.203/24 on port
    47808 | broadcast : 10.227.6.255
    [06/17/25 14:25:31] INFO 2025-06-17 14:25:31,266 - INFO | notes.py:267
    Using default JSON configuration file
    [06/17/25 14:25:31] INFO 2025-06-17 14:25:31,285 - INFO | notes.py:267
    Registered as BACnet/IP App | mode
    normal
    INFO 2025-06-17 14:25:31,294 - INFO | notes.py:267
    Device instance (id) : 3056765
    None
    [06/17/25 14:25:31] INFO 2025-06-17 14:25:31,296 - INFO | notes.py:267
    Installing recurring task Ping
    Registered Devices Task
    (id:1649739199696)
    INFO 2025-06-17 14:25:31,314 - INFO | notes.py:267
    Installing recurring task Cleanup
    Tasks List (id:1649740171536)
    Exception in callback IPv4DatagramServer.set_local_transport_protocol()()
    handle: <Handle IPv4DatagramServer.set_local_transport_protocol()()>
    Traceback (most recent call last):
    File "C:\Users\l\AppData\Local\Programs\Python\Python313\Lib\asyncio\events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\l\Documents\Repository\24T014\.venv\Lib\site-packages\bacpypes3\ipv4\__init__.py", line 176, in set_local_transport_protocol
    transport, protocol = task.result()
    ~~~~~~~~~~~^^
    File "C:\Users\l\Documents\Repository\24T014\.venv\Lib\site-packages\bacpypes3\ipv4\__init__.py", line 159, in retrying_create_datagram_endpoint
    return await loop.create_datagram_endpoint(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    IPv4DatagramProtocol, local_addr=addrTuple, allow_broadcast=True
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
    File "C:\Users\l\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 1484, in create_datagram_endpoint
    await waiter
    asyncio.exceptions.CancelledError

    Process finished with exit code 0

    Continue reading...

Compartilhe esta Página