Skip to content

Commit 3814254

Browse files
authored
Support version string of older PCAN basic API (#1644)
1 parent d81a16b commit 3814254

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ def get_api_version(self):
416416
if error != PCAN_ERROR_OK:
417417
raise CanInitializationError(f"Failed to read pcan basic api version")
418418

419-
return version.parse(value.decode("ascii"))
419+
# fix https://github.com/hardbyte/python-can/issues/1642
420+
version_string = value.decode("ascii").replace(",", ".").replace(" ", "")
421+
422+
return version.parse(version_string)
420423

421424
def check_api_version(self):
422425
apv = self.get_api_version()

test/test_pcan.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ def test_api_version_read_fail(self) -> None:
120120
with self.assertRaises(CanInitializationError):
121121
self.bus = can.Bus(interface="pcan")
122122

123+
def test_issue1642(self) -> None:
124+
self.PCAN_API_VERSION_SIM = "1, 3, 0, 50"
125+
with self.assertLogs("can.pcan", level="WARNING") as cm:
126+
self.bus = can.Bus(interface="pcan")
127+
found_version_warning = False
128+
for i in cm.output:
129+
if "version" in i and "pcan" in i:
130+
found_version_warning = True
131+
self.assertTrue(
132+
found_version_warning,
133+
f"No warning was logged for incompatible api version {cm.output}",
134+
)
135+
123136
@parameterized.expand(
124137
[
125138
("no_error", PCAN_ERROR_OK, PCAN_ERROR_OK, "some ok text 1"),

0 commit comments

Comments
 (0)