Skip to content

Commit b12ab13

Browse files
author
Greg Brooks
committed
Convert BusState to enum when read with configparser (#1956)
1 parent 958fc64 commit b12ab13

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ def __init__(
268268

269269
self.check_api_version()
270270

271+
if not isinstance(state, BusState):
272+
try:
273+
state = BusState[state]
274+
except KeyError as e:
275+
raise ValueError("State must be ACTIVE or PASSIVE") from e
276+
271277
if state in [BusState.ACTIVE, BusState.PASSIVE]:
272278
self.state = state
273279
else:

doc/interfaces/pcan.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Here is an example configuration file for using `PCAN-USB <https://www.peak-syst
1515
[default]
1616
interface = pcan
1717
channel = PCAN_USBBUS1
18-
state = can.bus.BusState.PASSIVE
18+
state = PASSIVE
1919
bitrate = 500000
2020

2121
``channel`` (default ``"PCAN_USBBUS1"``)

0 commit comments

Comments
 (0)