From ed2bdbdd17b003558f0b52b7042dbd818aaaa28c Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Mon, 12 Dec 2022 15:59:27 +0100 Subject: [PATCH] Add PCAN support through python-can --- dronecan/driver/__init__.py | 3 +++ dronecan/driver/python_can.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dronecan/driver/__init__.py b/dronecan/driver/__init__.py index 9222f4e..d4b7a24 100644 --- a/dronecan/driver/__init__.py +++ b/dronecan/driver/__init__.py @@ -41,6 +41,9 @@ def make_driver(device_name, **kwargs): windows_com_port = device_name.replace('\\', '').replace('.', '').lower().startswith('com') unix_tty = device_name.startswith('/dev/') + if device_name.startswith('PCAN'): + kwargs['bustype'] = 'pcan' + if device_name.startswith("mavcan:"): if not have_mavcan: raise DriverError('MAVCAN is not available, ensure pymavlink is installed') diff --git a/dronecan/driver/python_can.py b/dronecan/driver/python_can.py index 23c7603..4b4aa6d 100644 --- a/dronecan/driver/python_can.py +++ b/dronecan/driver/python_can.py @@ -39,7 +39,7 @@ def __init__(self, channel, **_extras): if channel is None: self._bus = can.interface.Bus() # get bus from environment's config file else: - if not hasattr(_extras,'bustype'): + if not 'bustype' in _extras: _extras['bustype'] = 'socketcan' self._bus = can.interface.Bus(channel=channel, bustype=_extras['bustype'], bitrate=_extras['bitrate']) except Exception as ex: