Dear Psychopy users,
What I want to achieve: I am trying to send triggers (Oddball paradigm) via USB to LTP using Python or Psychopy and display them on BrainVision Recorder.
What works: the Windows Manager recognize in COM4 a Virtual Serial Port
What doesn’t work: when I run the python code to get access to the port:
import serial
import time
import threading
Connected = True
PulseWidth = 0.01
def ReadTHread(port):
while Connected:
if port.InWaiting ()> o:
print (“0x%X”%ord(port.read(1)))
#Open the Windows device manager search for the TriggerBox VirtualSerialPort
#in Ports/COM & LPT) and enter the port number in the constructor
port = serial.Serial(“COM4”)
#Start the read thread
thread = threading.Thread(targe=ReadThread, args=(port,))
thread.start()
#Set the port to an initial state
port.write([0x00])
time.sleep(PulseWidth)
#outlet.push_sample(x=[1])
while True:
#Set Bit 0 Pin 1 of the Output (to Amp) connector
port.write([0x01])
time.sleep(PulseWidth)
#Reset Bit0, Pin 2 of the Output (to Amp) connector
port.write([0x00])
time.sleep(PulseWidth)
I get this error
"could not open port ‘COM4’: PermissionError(13, ‘a device connected to the system is not in function.’, None, 31)
Basically, python does not recognize the COM4 port.
Thank you in advance to everyone will provide constructive feedback,
Best
Francesco
To me looks kind of weird as python just access to the systems ports.