StimTracker with Unity

Hello, I need some help on sending triggers from Unity to StimTracker (first generation, model ST-100) and then to BioSemi EEG recording equipment.

I wrote a C# script to send triggers to the serial port (in which the stimtracker is). I specified the serial port’s baud rate, data bits, stop bits, and other communication settings in the script. However, there was no event marker shown in the EEG recordings and nor any marker flash was observed on the StimTracker. No error was shown in Unity window. I am sure I am using the correct port name in my code.

I first tried to install and update the drivers for serial port. Then I tried to skip the StimTracker part by connecting the computer directly with BioSemi trigger interface (via the BioSemi’s cable). This worked and the markers were recorded correctly in EEG data, which means the Unity code is working well. But since we need to sync the audio stimuli, we have to use StimTracker.

My guess is, there was something wrong with the baud rate or other communication parameters. It might be something special for the 1G model which I did not find on the stimtracker’s website.

I am using these parameters in my script:

  • Baud rate: 115000
  • Parity: none
  • data bits: 8
  • stop bits: 1

Every time I opened the serial port, I specified these parameters and set the port to an initial state 0x00. Every time I finished sending a pulse, I reset the port to 0x00.

Are you sending the “mh” and “mp” commands to StimTracker?

See a description of XID Commands. Only a subset will work with the original StimTracker ST-100, but the mp/mh commands should be all you need.

Hi Hisham, Thank you for your reply. I have included the command “mh” in my script. Now I can see some numbers marked in my EEG data. However, the number values are not those I designed. For example, a number 128 repeatedly appeared and I do not have any event number designed to be 128.

Here is the code I am using (C# language):

    sPort = new SerialPort("COM3", 115000, Parity.None, 8, StopBits.One); 
    sPort.Open();

    int trigger_integar = event_number.current_event; // will read the value from another script; 0-255
    trigger = (byte) trigger_integar;

    // for stimtracker: 
    byte ignoredByte = 0; // this value will not influence the output, it is just a placeholder
    byte[] commandBytes = new byte[] { (byte)'m', (byte)'h', trigger, ignoredByte };
    sPort.Write(commandBytes, 0, commandBytes.Length);

    //reset 
    commandBytes = new byte[] { (byte)'m', (byte)'h', 0x00, ignoredByte };
    sPort.Write(commandBytes, 0, commandBytes.Length);

I am thinking if the variable trigger has been reset. So I tried to reset the port data every time sending is done. I have been also wondering if I need to close and reopen the port every time following a pulse being sent. I am currently not doing this. I open the port only when I initiated the port.

Please see this StimTracker 1G Interface to BioSemi ActiveTwo support note. The interface allows only 3 bits of data to be shared with BioSemi. The remaining 13 bits are used for other types of signals.

The newer StimTracker Duo and Quad can forward up to all 16 bits if you need it to.

Hi Hisham, For the 3 bits shared with BioSemi, are these the bits at the bit 1-3, or 8-10, or the last 3 bits?
In this line of code, how should I set up the value for trigger?
byte[] commandBytes = new byte[] { (byte)‘m’, (byte)‘h’, trigger, ignoredByte };

The order of the bits is documented in the support note.

Unfortunately, we cannot assist with users’ code. Why not use use trial and error – try different values to see which ones work.