I’m a researcher working on interfacing bacteria with electronics. To power our hardware we use touchdesigner. But lately, our program doesn’t work properly and there is one error I can’t seem to fix.
The way our hardware is setup, we have an arduino nano connected on port COM7 and a function generator (called MHS2300A) connected on port COM10;
The problem is this error bellow I get in the python terminal when the file is launched and I give an order to the arduino :
But when I try on the version of python itself (C:\Program Files\Derivative\TouchDesigner\bin\python.exe), not inside TD itself, and use this code (see bellow) it works fine.
import serial
a = serial.Serial(“COM7”)
a.open()
I tried every solution I found on the internet about this specific error, changed ports, closed programs that could use them, gave special permissions, changed cables etc…
Any ideas on how to solve this ?
Thanks for your help
Hey Markus thank you so much for the quick response,
I wasn’t the one who made the software, another researcher who also made the hardware did, so I do not know why he made this choice but changing it now would be very time expensive on my end.
do you run into the same issue in a fresh TouchDesigner when just entering
import serial
a = serial.Serial(“COM7”)
a.open()
into the textport?
I wonder if perhaps the connection is already open when it tries to open it again. So perhaps somewhere in the code it’s repeatedly trying to run the a.open() on the same port.
When I enter in the interpreter (C:\Program Files\Derivative\TouchDesigner\bin\python.exe) and in the python textport inside of (a new) TD it tells me that the port is already open but it allows me to close it and reopen it again.
Your message reminded me of this, and so I tried on my main file and before executing it, I did :
import serial
a = serial.Serial(“COM7”)
a.close()
but it still gave me the same error anyway.
it’s a bit a maze to decipher, but generally I would try to figure out what is opening the port first.
I used the Search and Replace Dialog (available under Edit>Search/Replace) to look for the string serial.Serial( and could identify 3 scripts that make use of this function.
If you add a debug() statement above each of the calls with the arguments that they are called with, I think you hopefully will be able to trace the issue.
Following this, perhaps closing ports initially might be helpful - otherwise I would recommend to centralize the functions in a way that you have only one place that is called to open ports and perhaps also manages them (are they already open? If yes reuse, if no open)
Hi, and sorry for the late response,
We found the solution to my problem : it was just a mismatch of the ports on my side, not in the code.
However, you highlighted a very good point I think : not to let the ports open all the time in the background. I’ll make sure to add, at the start of the loops, a close port command, so I won’t get any further “port is already open” in another instance.
Thank you very much for your responses
Have a good day !