2222import time
2323import serial
2424
25+ class PyboardError (BaseException ):
26+ pass
27+
2528class Pyboard :
2629 def __init__ (self , serial_device ):
2730 self .serial = serial .Serial (serial_device )
@@ -38,7 +41,7 @@ def enter_raw_repl(self):
3841 time .sleep (0.1 )
3942 if not data .endswith (b'raw REPL; CTRL-B to exit\r \n >' ):
4043 print (data )
41- raise Exception ('could not enter raw repl' )
44+ raise PyboardError ('could not enter raw repl' )
4245
4346 def exit_raw_repl (self ):
4447 self .serial .write (b'\r \x02 ' ) # ctrl-B: enter friendly REPL
@@ -56,7 +59,7 @@ def exec(self, command):
5659 self .serial .write (b'\x04 ' )
5760 data = self .serial .read (2 )
5861 if data != b'OK' :
59- raise Exception ('could not exec command' )
62+ raise PyboardError ('could not exec command' )
6063 data = self .serial .read (2 )
6164 timeout = 0
6265 while True :
@@ -72,10 +75,10 @@ def exec(self, command):
7275 time .sleep (0.1 )
7376 if not data .endswith (b'\x04 >' ):
7477 print (data )
75- raise Exception ('timeout waiting for EOF reception' )
78+ raise PyboardError ('timeout waiting for EOF reception' )
7679 if data .startswith (b'Traceback' ) or data .startswith (b' File ' ):
7780 print (data )
78- raise Exception ('command failed' )
81+ raise PyboardError ('command failed' )
7982 return data [:- 2 ]
8083
8184 def execfile (self , filename ):
0 commit comments