File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 56
56
PCAN_CHANNEL_FEATURES ,
57
57
FEATURE_FD_CAPABLE ,
58
58
PCAN_DICT_STATUS ,
59
+ PCAN_BUSOFF_AUTORESET ,
59
60
)
60
61
61
62
@@ -206,6 +207,10 @@ def __init__(
206
207
In the range (1..16).
207
208
Ignored if not using CAN-FD.
208
209
210
+ :param bool auto_reset:
211
+ Enable automatic recovery in bus off scenario.
212
+ Resetting the driver takes ~500ms during which
213
+ it will not be responsive.
209
214
"""
210
215
self .m_objPCANBasic = PCANBasic ()
211
216
@@ -276,6 +281,14 @@ def __init__(
276
281
"Ignoring error. PCAN_ALLOW_ERROR_FRAMES is still unsupported by OSX Library PCANUSB v0.10"
277
282
)
278
283
284
+ if kwargs .get ("auto_reset" , False ):
285
+ result = self .m_objPCANBasic .SetValue (
286
+ self .m_PcanHandle , PCAN_BUSOFF_AUTORESET , PCAN_PARAMETER_ON
287
+ )
288
+
289
+ if result != PCAN_ERROR_OK :
290
+ raise PcanCanInitializationError (self ._get_formatted_error (result ))
291
+
279
292
if HAS_EVENTS :
280
293
self ._recv_event = CreateEvent (None , 0 , 0 , None )
281
294
result = self .m_objPCANBasic .SetValue (
Original file line number Diff line number Diff line change @@ -363,6 +363,16 @@ def get_value_side_effect(handle, param):
363
363
self .bus = can .Bus (bustype = "pcan" , device_id = dev_id )
364
364
self .assertEqual (expected_result , self .bus .channel_info )
365
365
366
+ def test_bus_creation_auto_reset (self ):
367
+ self .bus = can .Bus (bustype = "pcan" , auto_reset = True )
368
+ self .assertIsInstance (self .bus , PcanBus )
369
+ self .MockPCANBasic .assert_called_once ()
370
+
371
+ def test_auto_reset_init_fault (self ):
372
+ self .mock_pcan .SetValue = Mock (return_value = PCAN_ERROR_INITIALIZE )
373
+ with self .assertRaises (CanInitializationError ):
374
+ self .bus = can .Bus (bustype = "pcan" , auto_reset = True )
375
+
366
376
367
377
if __name__ == "__main__" :
368
378
unittest .main ()
You can’t perform that action at this time.
0 commit comments