Hi all,
New to psychopy and coding generally! We are adapting an experimental task coded in psychopy3 and using pyserial to event mark. Our setup is PsychoPy3 → BlackBox USBTTL module → STP100D → MP150 → Aquisition Graph template on MacBook Pro. I attached an image at the bottom that contains the digital acquisition channels that can be recorded in AcqKnowledge/BIOPAC. The serial port was working and we were able to event mark using several softwares including the USB TTL Configuration Utility, Eprime, python IDLE, and psychopy3. However, after force quitting Psychopy we are no longer able to send event markers via any of the softwares. We believe this issue was caused because the serial port was not closed cleanly in PsychoPy, but we cannot figure out how to fix it. We have tried a number of things including restarting the computer, reinstalling the serial port and drivers, changing the COM port number, and running lines of code in Psychopy and python IDLE. We have read through existing threads on event marking via psychopy and the BlackBox TTL module: Event markers to BIOPAC via serial port
We have not been getting error messages with our code, and even though it says it is sending bytes, we do not see any event markers in the acquisition graph.
When running the following code snippet, psychopy did report that the serial port was opening and closing as expected:
import serial
port_name = 'COM4'
try:
# Attempt to create a serial port object
port = serial.Serial(port_name)
# Check if the port is open
if port.is_open:
print(f"The serial port {port_name} is currently open. Closing it now.")
port.close()
else:
print(f"The serial port {port_name} is already closed.")
except serial.SerialException as e:
print(f"Error: Could not access the serial port {port_name}. Details: {e}")
print("Serial port check and closure complete.")
We have also tried codes to flush the serial port:
ser.reset_input_buffer()
ser.reset_output_buffer()
And code to adjust the flow control settings:
try:
port = serial.Serial(
'COM4',
baudrate=115200,
timeout=1,
xonxoff=True,
rtscts=True,
dsrdtr=True
)
port.write("RR".encode()) # Reset USB TTL Module
port.close()
except serial.SerialException as e:
print(f"Serial port error: {e}")
Here is an example snippets of code that were working (i.e., event marking in the appropriate digital channels) prior to this issue.
Import serial
port = serial.Serial(‘COM4’, baudrate = 115200, timeout = 0)
port.write(“RR”.encode()) #Turns all digital channels off (i.e., 0), resetting them
port.write(“FF”.encode()) #Turns all digital channels on
port.write(“RR”.encode())
Port.write(“01”.encode()) #Turns on channel 28
port.write(“RR”.encode())
Port.write(“02”.encode()) #Turns on channel 29