def start(self, host, port): connection = (host, port) self.server = DatagramServer(connection, self.handle) # start to init the socket self.server.start() self.server.socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) # create application instance # not too beautifull, but the BACnetApp needs access to the socket's sendto method # this could properly be refactored in a way such that sending operates on it's own # (non-bound) socket. self.bacnet_app = BACnetApp(self.thisDevice, self.server) # get object_list and properties self.bacnet_app.get_objects_and_properties(self.dom) logger.info('Bacnet server started on: %s', connection) self.server.serve_forever()
from bacpypes.apdu import WhoIsRequest, WhoHasObject, WhoHasRequest # code for generating adpu - who-is # request = WhoIsRequest(deviceInstanceRangeLowLimit=500, deviceInstanceRangeHighLimit=50000) # test_pdu = PDU() # test_apdu = APDU() # request.encode(test_apdu) # test_apdu.encode(test_pdu) # bacnet_app = BACnetApp(test.thisDevice, test) # bacnet_app.get_objects_and_properties(test.dom) # bacnet_app.indication(test_apdu, ('127.0.0.1', 9999), test.thisDevice) # print(bacnet_app._response) # bacnet_app.response(bacnet_app._response, ('127.0.0.1', 9999)) # # logger.debug('Starting BACnet Server! at {}:{}'.format('localhost', 9999)) # # test.start('127.0.0.1', 9999) # testing who-has request_object = WhoHasObject() request_object.objectIdentifier = ('binaryInput', 12) request = WhoHasRequest(object=request_object) test_apdu = APDU() request.encode(test_apdu) test_pdu = PDU() test_apdu.encode(test_pdu) bacnet_app = BACnetApp(test.thisDevice, test) bacnet_app.get_objects_and_properties(test.dom) bacnet_app.indication(test_apdu, ('127.0.0.1', 9999), test.thisDevice) print(bacnet_app._response) bacnet_app.response(bacnet_app._response, ('127.0.0.1', 9999)) except KeyboardInterrupt: logger.debug('Stopping BACnet server') test.stop()