From d938834d36d5d40c322c488a29fc4b71b3a7b63b Mon Sep 17 00:00:00 2001 From: todd Date: Wed, 4 Sep 2024 13:31:19 +0100 Subject: [PATCH] BF: Detect when a half-complete message is in the buffer before sending a command --- psychopy_bbtk/tpad.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/psychopy_bbtk/tpad.py b/psychopy_bbtk/tpad.py index b32fc0c..e8a71a6 100644 --- a/psychopy_bbtk/tpad.py +++ b/psychopy_bbtk/tpad.py @@ -301,7 +301,7 @@ def __init__(self, *args, **kwargs): class TPad(sd.SerialDevice): - name = "TPad" + name = b"TPad" def __init__( self, port=None, baudrate=115200, @@ -426,6 +426,15 @@ def addListener(self, listener): # add listener to all nodes for node in self.nodes: node.addListener(listener) + + def sendMessage(self, message, autoLog=True): + # dispatch any messages on the buffer to completion before sending message + maxIter = 5 + while maxIter >= 0 and (self.com.in_waiting or self._lastLine): + self.dispatchMessages() + self.pause() + + return sd.SerialDevice.sendMessage(self, message, autoLog) def dispatchMessages(self): # do nothing if there's already a dispatch in progress