File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5656 PCAN_CHANNEL_FEATURES ,
5757 FEATURE_FD_CAPABLE ,
5858 PCAN_DICT_STATUS ,
59+ PCAN_BUSOFF_AUTORESET ,
5960)
6061
6162
@@ -206,6 +207,10 @@ def __init__(
206207 In the range (1..16).
207208 Ignored if not using CAN-FD.
208209
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.
209214 """
210215 self .m_objPCANBasic = PCANBasic ()
211216
@@ -276,6 +281,14 @@ def __init__(
276281 "Ignoring error. PCAN_ALLOW_ERROR_FRAMES is still unsupported by OSX Library PCANUSB v0.10"
277282 )
278283
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+
279292 if HAS_EVENTS :
280293 self ._recv_event = CreateEvent (None , 0 , 0 , None )
281294 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):
363363 self .bus = can .Bus (bustype = "pcan" , device_id = dev_id )
364364 self .assertEqual (expected_result , self .bus .channel_info )
365365
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+
366376
367377if __name__ == "__main__" :
368378 unittest .main ()
You can’t perform that action at this time.
0 commit comments