Combining MagPy-TMS with PsychoPy

OS: Win 10
PsychoPy version: 2020.2.5
Standard Standalone?: Yes, but I have also tried running my code through Anaconda using Spyder IDE, where I also have the latest psychopy package installed.
TMS apparatus: Magstim Rapid2 stimulator v9 connected to the PC via serial cable.

What are you trying to achieve?:
I am trying to build a staircase experiment to estimate a Transcranial Magnetic Stimulation (TMS) threshold for experiencing phosphenes.

What did you try to make it work?:
I have installed the python package MagPy-TMS which was created for controlling magstim stimulators. Running a script with MagPy-TMS works fine and I can control my stimulator and control all parameters.
The PsychoPy staircase works perfectly fine with no errors if I do not include the script for the stimulator.
In summary, both the TMS script and the PsychoPy staircase work fine if run separately.
However, as soon as I combine the two, python stops responding. I do not get any error, the program just crashes and I get the message “python has stopped responding”.

I have made the staircase through the standalone builder version. When that crashed, I extracted the python script and run it through my Anaconda’s Spyder IDE where I have all necessary packages installed. It crashed in the same way.

What specifically went wrong when you tried that?:
Unfortunately, I do not get any error message. What I have noticed by moving the TMS lines up and down through my script, is that as soon as my script reads the TMS lines I get the message that python has stopped responding. I am attaching the python script.

General:
I know that people have used PsychoPy with MagPy-TMS before and I have tried finding a code that previously worked to check it with my equipment. Unfortunately I had no luck. If anyone has any idea, or experienced a similar problem, I would appreciate any tips.

Phosphene_Threshold_v1.py (27.2 KB)

Hi Phivos - I see that the .py file here is an export from builder - would it be possible for you also to please share the .psyexp file you are working from?

Thanks,
Becca

sure, here it is!

Phosphene_Threshold_v1.psyexp (27.4 KB)

SOLVED:

The developer of MagPy-TMS had a looked and explained the issue to me.

The problem was that I was using the command if __name__ == "__main__": before each TMS command. The solution was using this command at the beginning of the script and including everything (except for imports).

1 Like