diff --git a/pyproject.toml b/pyproject.toml index 86f5fdc..28b3e49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ classifiers = [ [tool.poetry.dependencies] python = ">=3.10,<4.0" bacpypes3 = ">=0.0.102" -protocol-proxy = ">=2.0.0rc0" +protocol-proxy = ">=2.0.0rc2" [tool.poetry.group.dev.dependencies] # No additional dependencies. diff --git a/src/protocol_proxy/protocol/bacnet/bacnet.py b/src/protocol_proxy/protocol/bacnet/bacnet.py index d34110f..dbf7db6 100644 --- a/src/protocol_proxy/protocol/bacnet/bacnet.py +++ b/src/protocol_proxy/protocol/bacnet/bacnet.py @@ -36,13 +36,17 @@ def __init__(self, local_interface, bacnet_port=0, vendor_id=999, object_name='V objectIdentifier=("network-port", bacnet_port), objectName="NetworkPort-1", networkNumber=bacnet_port, networkNumberQuality="configured") + # TODO: In order to implement better error handling, it may be necessary to sublcass Application. + # BACPypes3 raises an AssertionError, for instance in the Application.confirmation which does not + # seem to be possible to catch without overriding the method. + # It should be possilble to make this class a subclass of Application, + # instead of having Application as an attribute. self.app = Application.from_object_list( [device_object, network_port_object], device_info_cache=device_info_cache, # TODO: If these should be passed in, add to args & launch. router_info_cache=router_info_cache, aseID=ase_id ) - #_log.debug(f'WE HAVE AN APP: {self.app.device_info_cache}') async def query_device(self, address: str, property_name: str = 'object-identifier'): """Returns properties about the device at the given address. @@ -186,15 +190,19 @@ async def confirmed_private_transfer(self, address: Address, vendor_id: int, ser serviceNumber=service_number) if service_parameters: cpt_request.serviceParameters = service_parameters - response = await self.app.request(cpt_request) - if isinstance(response, ConfirmedPrivateTransferError): - _log.warning(f'Error calling Confirmed Private Transfer Service: {response}') - return None - elif isinstance(response, ConfirmedPrivateTransferACK): - return response + try: + response = await self.app.request(cpt_request) + except Exception as e: + _log.warning(f'Exception sending Confirmed Private Transfer Request: {e}') else: - _log.warning(f'Some other Error: {response}') # TODO: Improve error handling. - return None + if isinstance(response, ConfirmedPrivateTransferError): + _log.warning(f'Error calling Confirmed Private Transfer Service: {response}') + return None + elif isinstance(response, ConfirmedPrivateTransferACK): + return response + else: + _log.warning(f'Some other Error: {response}') # TODO: Improve error handling. + return None async def scan_subnet(self, network_str: str,