Serial Port for EEG crashes Psychopy

OS (Win10):
PsychoPy version (2023.2.3):
Standard Standalone? (y/)
What are you trying to achieve?:
Start an experiment using audio components and text while gathering EEG data
What did you try to make it work?:
Tried to update psychopy, uninstall the 2023 version and re-install it again, nothing changes.

What specifically went wrong when you tried that?:
This is strange because this experiment used to work a month ago. I did not change a single thing in the code or the setup, but now when I try to run it it goes smoothly until it reaches the Serial Port component, at which point it crashes. By crashing I mean that it does not close itself, signal a potential error and goes back to the builder, but it rather freezes completely and I have to shut down PsychoPy from the task manager. I thought it might be a windows update problem but it seems unlikely, since the experiment still works provided I eliminate the serialport.

Does anybody has any advice? Or something similar happened to you? I honestly don’t know how to fix it. Thank you!

Sounds like an OS-level issue. There was potentially a Windows update that changed the driver, through which the serial port communicates with the EEG system. What EEG system are you using, and is there a vendor provided driver or serial port communication that you can reinstall? I believe PsychoPy is hanging for you because the I/O request never returns when being sent to the serial port for some reason, likely due to corrupted driver.

I see, that would make sense. I’m using a 64 channel EEG system through a Brainvision usb software that runs on a different pc, an old windows (xp) purposely kept offline, so updating that would be quite the hassle.
Do you think that the only way to solve the problem is updating the “receiving” software? My goal would be resolving the problem on the Psychopy\Windows 10 end if possible.

I don’t think this is a “receiving” software problem. I think the issue is happening to the Win 10 computer “sending” trigger codes, i.e., the computer that you are running PsychoPy on. My suspicion is that your Windows 10 OS is having trouble opening serial port after a recent update. My recommendation is to focus on that - which could involve reinstalling any driver involved in the serial port communication.

Here’s a simple test: if you plug in the serial port but don’t actually connect it to the BrainVision computer. I.e…, leave the serial port one end unconnected while the other connects to your PsychoPy computer. What happens when you run the experiment under this setting? If you still have the frozen PsychoPy, then this has nothing to do with BrainVision or EEG - it’s a problem of opening serial port on your specific Windows 10 system by PsychoPy.

Oh ok I think I understand, I will run some tests and update this post in light of your feedbacks, hopefully I’ll manage to solve the problem. Thank you!

1 Like

Back again, so. I tried different tests with and without EEG and BrainVision connected to the pc and the problem remains, it therefore appears to be a problem of serialPort unable to properly communicate between Windows 10 and Psychopy (the problem persists with other PCs as well). This unfortunately does not help me as I am not sure how to solve this problem. Any idea on how to make it work again?

Given that the entire PsychoPy process froze instead of throwing an exception, I suspect the I/O request hangs at an OS-level step instead of at the Python interpreter. Maybe the question to ask next is: is your Windows 10 able to open serial port in python at all?

PsychoPy simply uses the serial package to handle this communication with Serial Port objects. You can first check the version of serial in your PsychoPy installation. Go to Coder view and open a new Python shell at the bottom of that window.

>>> import serial
>>> serial.__version__
'3.5'

Does it show you the same version of serial as above?

Second, you want to check if the specified serial port is actually detected on your Windows 10 system. Open Device Manager, and is the COM3 or whatever port number that you are specifying for the Serial Out component in the builder view actually listed in your Device Manager?

Finally, you can try to manually create the Serial port object in the coder Python shell and see if it still hangs.

import serial
s = serial.Serial(port=xxx, baudrate=xxx, bytesize=xxx, partiy=xxx, stopbits=xxx, timeout=xxx)

If it still hangs, then this is not a PsychoPy issue but rather that the serial package no longer works on your Windows 10 for some reason. I would suggest try to debug why serial hangs on Windows 10. You may have to find a version of serial that works and then install that into PsychoPy, or reinstall the Windows OS all together. I’m not sure about the exact cause of the problem since I no longer have access to Windows 10 systems.