diff --git a/can/interfaces/pcan/pcan.py b/can/interfaces/pcan/pcan.py index 13775e983..d2973ade6 100644 --- a/can/interfaces/pcan/pcan.py +++ b/can/interfaces/pcan/pcan.py @@ -416,7 +416,10 @@ def get_api_version(self): if error != PCAN_ERROR_OK: raise CanInitializationError(f"Failed to read pcan basic api version") - return version.parse(value.decode("ascii")) + # fix https://github.com/hardbyte/python-can/issues/1642 + version_string = value.decode("ascii").replace(",", ".").replace(" ", "") + + return version.parse(version_string) def check_api_version(self): apv = self.get_api_version() diff --git a/test/test_pcan.py b/test/test_pcan.py index be6c5ad64..9f4e36fc4 100644 --- a/test/test_pcan.py +++ b/test/test_pcan.py @@ -120,6 +120,19 @@ def test_api_version_read_fail(self) -> None: with self.assertRaises(CanInitializationError): self.bus = can.Bus(interface="pcan") + def test_issue1642(self) -> None: + self.PCAN_API_VERSION_SIM = "1, 3, 0, 50" + with self.assertLogs("can.pcan", level="WARNING") as cm: + self.bus = can.Bus(interface="pcan") + found_version_warning = False + for i in cm.output: + if "version" in i and "pcan" in i: + found_version_warning = True + self.assertTrue( + found_version_warning, + f"No warning was logged for incompatible api version {cm.output}", + ) + @parameterized.expand( [ ("no_error", PCAN_ERROR_OK, PCAN_ERROR_OK, "some ok text 1"),