Triggers from PsychoPy to triggerbox from brain products

Good afternoon,

We are unable to get our triggers to work for our NIRSScout system by Brain Products. Our connection is the following:
Stimultation Windows laptop (running Psychopy) → USB cable → Brain Products TriggerBox → TriggerBox “Amp” output → BP-245-1565 → NIRScout trigger cable → NIRScout trigger input on the machine.

I see some queries about this on the forum but did not see a definitive solution. Can someone help us with this?

The code that Brain Products gave us is :

import serial
import time
import threading
Connected = True
PulseWidth = 0.01
def ReadThread(port):
while Connected:
if port.inWaiting() > 0:
print (“0x%X”%ord(port.read(1)))

Open the Windows device manager, search for the “TriggerBox VirtualSerial Port (COM6)”

in “Ports /COM & LPT)” and enter the COM port number in the constructor.

port = serial.Serial(“COM6”)

Start the read thread

thread = threading.Thread(target=ReadThread, args=(port,))
thread.start()

Set the port to an initial state

port.write([0x00])
time.sleep(PulseWidth)

Set Bit 0, Pin 2 of the Output(to Amp) connector

port.write([0x01])
time.sleep(PulseWidth)

Reset Bit 0, Pin 2 of the Output(to Amp) connector

port.write([0x00])
time.sleep(PulseWidth)

Reset the port to its default state

port.write([0xFF])
time.sleep(PulseWidth)

Terminate the read thread

Connected = False
thread.join(1.0)

Close the serial port

port.close()

Hi @swijeakumar,

could you surround the code example you share with triple backticks (```)? It will make it more readable. :slight_smile:
It would also be helpful if you were a bit more specific in what you mean by being unable to get the triggers to work. The code you pasted is a little hard to read, but it looks like it is defining a function to send triggers with - how do you use that function in your code, do you get any errors if you try to do so or no errors but also no recorded triggers?

Hi there,

We have run into a more specific and strange issue now - the first 20 or so triggers appear on our neuroimaging software and then no other triggers appear. I have pasted the code below. I could also send you my task if you could take a look or chat on Teams?

I inserted a custom code component in the Trial Routine and added the following bits of code to the different tabs:

Under ‘Begin Experiment’:

import time
import threading
Connected = True
PulseWidth = 0.5
            
# Open the Windows device manager, search for the "TriggerBox VirtualSerial Port (COM6)" # in "Ports /COM & LPT)" and enter the COM port number in the constructor.
port = serial.Serial("COM3")

def ReadThread(port): 
    while Connected: 
        if port.inWaiting() > 0: 
            print ("0x%X"%ord(port.read(1))) ```

Under 'Begin Routine':

```# Start the read thread
thread = threading.Thread(target=ReadThread, args=(port,))
thread.start()

# Set Bit 0, Pin 2 of the Output(to Amp) connector
port.write([0x01])
time.sleep(PulseWidth)

# Reset Bit 0, Pin 2 of the Output(to Amp) connector
port.write([0x00])
time.sleep(PulseWidth)```

Then I inserted a new custom code component at the very end of the experiment and added the following code under 'End Experiment':

```# Terminate the read thread
Connected = False
thread.join(1.0)

# Close the serial port
port.close()```

Any advice on what we are doing wrong would be massively appreciated.

Best,
Sobana

Hi @swijeakumar, sorry I respond after a delay. The issue you report now indeed sounds strange.
I never sent triggers in the same way as you do, so I may be of little help here, but I will try. :slight_smile: First of all I would try to see if sending the triggers through a python script gives you the same problem. So you could reformat the code snippet you pasted so that, for example, it sends one trigger every 250 ms, sending triggers from 1 to 255 (sequentially). If this fails (at some point) you will at least know: a) that PsychoPy is not part of the problem; b) how many triggers are received (the value of the last received trigger).