Skip to content

Commit

Permalink
Support version string of older PCAN basic API (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 authored Aug 17, 2023
1 parent d81a16b commit 3814254
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion can/interfaces/pcan/pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions test/test_pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 3814254

Please sign in to comment.