0

首先,我不得不说我是 Python 和 BAC0 库的绝对初学者。

我想用我的 python 脚本创建一个 Bacnet 模拟值,该脚本应该发送到另一个(物理)Bacnet 设备。现在我只用bacnet = BAC0.lite()命令“创建”了一个 Bacnet 设备。这不是很多,但它的工作原理。

我花了很多时间浏览文档,但找不到让脚本发送模拟值的正确方法。

任何人都可以帮忙吗?

背景:我有一个能够非常容易地将模拟值(0 ... 10 V)发送到 MQTT 代理的设备。现在我想让 Raspi 接收该模拟值并将其“转换”为 Bacnet 模拟值。这个 Bacnet 模拟值将被发送到 DDC 以控制泵的功率。为此,我需要在 python 脚本中“创建”Bacnet 模拟值的正确命令/代码。

4

1 回答 1

1

这是一个例子:

#!/usr/bin/python

import weakref
import BAC0
from bacpypes.basetypes import EngineeringUnits, DateTime
from bacpypes.primitivedata import CharacterString, Date, Time

from BAC0.core.devices.local.models import (
    analog_input,
    datetime_value,
    character_string,
)
from BAC0.core.devices.local.object import ObjectFactory
from BAC0.core.devices.local.models import make_state_text

def start_device():
    print("Starting BACnet device")
    new_device = BAC0.lite(deviceId=10032)
    time.sleep(1)

    # Analog Values
    _new_objects = analog_input(
        instance=1,
        name="Current_Temp",
        description="Current Temperature in degC",
        presentValue=0,
        properties={"units": "degreesCelsius"},
    )
    _new_objects = analog_input(
        instance=2,
        name="Current_Pressure",
        description="Current Pressure in kPa",
        presentValue=0,
        properties={"units": "kilopascals"},
    )

    # Character Strings
    # _new_objects = character_string(
    #    instance=1,
    #    name="Location",
    #    description="City code for data",
    #    presentValue="on-24",
    #    is_commandable=True,
    # )

    _new_objects.add_objects_to_application(new_device)
return new_device
于 2021-10-19T19:46:19.683 回答