@@ -39,8 +39,8 @@ def __init__(self, port, baudrate=115200, notifyCallbackFunc=None, fatalErrorCal
3939 # Reentrant lock for managing concurrent write access to the underlying serial port
4040 self ._txLock = threading .RLock ()
4141
42- self .notifyCallback = notifyCallbackFunc or self . _placeholderCallback
43- self .fatalErrorCallback = fatalErrorCallbackFunc or self . _placeholderCallback
42+ self .notifyCallbackFunc = notifyCallbackFunc
43+ self .fatalErrorCallbackFunc = fatalErrorCallbackFunc
4444
4545 self .com_args = args
4646 self .com_kwargs = kwargs
@@ -78,12 +78,10 @@ def _handleLineRead(self, line, checkForResponseTerm=True):
7878 # No more chars on the way for this notification - notify higher-level callback
7979 #print 'notification:', self._notification
8080 self .log .debug ('notification: %s' , self ._notification )
81- self .notifyCallback (self ._notification )
81+ if self .notifyCallbackFunc :
82+ self .notifyCallbackFunc (self ._notification )
8283 self ._notification = []
8384
84- def _placeholderCallback (self , * args , ** kwargs ):
85- """ Placeholder callback function (does nothing) """
86-
8785 def _readLoop (self ):
8886 """ Read thread main loop
8987
@@ -119,7 +117,8 @@ def _readLoop(self):
119117 except Exception : #pragma: no cover
120118 pass
121119 # Notify the fatal error handler
122- self .fatalErrorCallback (e )
120+ if self .fatalErrorCallbackFunc :
121+ self .fatalErrorCallbackFunc (e )
123122
124123 def write (self , data , waitForResponse = True , timeout = 5 , expectedResponseTermSeq = None ):
125124 data = data .encode ()
0 commit comments