Untitled
unknown
plain_text
a year ago
2.4 kB
11
Indexable
#!/usr/bin/python
import logging
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
from bacpypes.consolelogging import ConfigArgumentParser
from bacpypes.core import run
from bacpypes.app import BIPSimpleApplication
from bacpypes.object import AnalogValueObject, BinaryValueObject
from bacpypes.local.device import LocalDeviceObject
from bacpypes.apdu import ReadPropertyRequest
from bacpypes.pdu import Address
from bacpypes.primitivedata import ObjectIdentifier
from bacpypes.service.device import WhoIsIAmServices
# Set up logging to print debug messages to the console
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
# Debugging
_debug = 1
_log = ModuleLogger(globals())
@bacpypes_debugging
class BACnetClientApplication(BIPSimpleApplication, WhoIsIAmServices):
def read_property(self, address, object_type, object_instance, property_id):
"""Reads a property from a BACnet device."""
request = ReadPropertyRequest(
objectIdentifier=ObjectIdentifier(object_type, object_instance),
propertyIdentifier=property_id
)
request.pduDestination = Address(address)
if _debug:
_log.debug("Sending ReadPropertyRequest: %r", request)
# Create an IOCB indirectly via request() method, handles confirmed requests automatically
self.request(request)
def main():
# Parse command line arguments
parser = ConfigArgumentParser(description="BACnet Client")
args = parser.parse_args()
if _debug:
_log.debug("BACnet Client Starting")
# Create a local BACnet device object
local_device = LocalDeviceObject(ini=args.ini)
# Create BACnet client application
bacnet_client = BACnetClientApplication(local_device, args.ini.address)
# Define target BACnet device address (replace with actual server IP/port)
server_address = "127.0.0.1:47899" # Change this to match your BACnet environment
# Read AnalogValueObject (Object Type: analogValue, Instance ID: 1)
bacnet_client.read_property(server_address, "analogValue", 1, "presentValue")
# Read BinaryValueObject (Object Type: binaryValue, Instance ID: 1)
bacnet_client.read_property(server_address, "binaryValue", 1, "presentValue")
run()
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment