Skip to content

Commit

Permalink
BF: Detect when a half-complete message is in the buffer before sendi…
Browse files Browse the repository at this point in the history
…ng a command
  • Loading branch information
todd committed Sep 4, 2024
1 parent 846edf5 commit d938834
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion psychopy_bbtk/tpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d938834

Please sign in to comment.