@@ -214,8 +214,8 @@ def connect(self):
214214 '''Connect to CAN network'''
215215 try :
216216 self .network .connect (context = self .can_context )
217- except :
218- raise ValueError ('Unable to connect to CAN network' )
217+ except Exception as err :
218+ raise ValueError ('Unable to connect to CAN network' ) from err
219219
220220 def disconnect (self ):
221221 '''Disconnect from CAN network'''
@@ -226,15 +226,15 @@ def enter_pre_operational(self):
226226 self .logger .info ("Entering pre-operational mode" )
227227 try :
228228 self .node .nmt .state = 'PRE-OPERATIONAL'
229- except :
230- raise ValueError ('Failed to enter pre-operational mode' )
229+ except Exception as err :
230+ raise ValueError ('Failed to enter pre-operational mode' ) from err
231231
232232 def _ctrl_program (self , cmd ):
233233 '''Write program control command to CANopen object dictionary (0x1f51)'''
234234 try :
235235 self .ctrl_sdo .raw = cmd
236- except :
237- raise ValueError ('Unable to write control command 0x{:02x}' .format (cmd ))
236+ except Exception as err :
237+ raise ValueError ('Unable to write control command 0x{:02x}' .format (cmd )) from err
238238
239239 def stop_program (self ):
240240 '''Write stop control command to CANopen object dictionary (0x1f51)'''
@@ -260,17 +260,17 @@ def swid(self):
260260 '''Read software identification from CANopen object dictionary (0x1f56)'''
261261 try :
262262 swid = self .swid_sdo .raw
263- except :
264- raise ValueError ('Failed to read software identification' )
263+ except Exception as err :
264+ raise ValueError ('Failed to read software identification' ) from err
265265 self .logger .info ('Program software identification: 0x{:08x}' .format (swid ))
266266 return swid
267267
268268 def flash_status (self ):
269269 '''Read flash status identification'''
270270 try :
271271 status = self .flash_sdo .raw
272- except :
273- raise ValueError ('Failed to read flash status identification' )
272+ except Exception as err :
273+ raise ValueError ('Failed to read flash status identification' ) from err
274274 return status
275275
276276 def download (self , bin_file ):
@@ -289,8 +289,8 @@ def download(self, bin_file):
289289 break
290290 outfile .write (chunk )
291291 progress .next (n = len (chunk ))
292- except :
293- raise ValueError ('Failed to download program' )
292+ except Exception as err :
293+ raise ValueError ('Failed to download program' ) from err
294294 finally :
295295 progress .finish ()
296296 infile .close ()
@@ -301,8 +301,8 @@ def wait_for_bootup(self, timeout=DEFAULT_TIMEOUT):
301301 self .logger .info ('Waiting for boot-up message...' )
302302 try :
303303 self .node .nmt .wait_for_bootup (timeout = timeout )
304- except :
305- raise ValueError ('Timeout waiting for boot-up message' )
304+ except Exception as err :
305+ raise ValueError ('Timeout waiting for boot-up message' ) from err
306306
307307 def wait_for_flash_status_ok (self , timeout = DEFAULT_TIMEOUT ):
308308 '''Wait for flash status ok'''
0 commit comments