Communicate with StimTracker using C#

Hi!

We are building 3D experiments with Unity and will send triggers to StimTracker which we recently purchased. Because Unity’s programming language is C#, we cannot use the Python or C++ libraries directly. Is there a way to communicate with StimTracker from C#?

Thank you in advance!

Best,
Shaoyun

We do not have a C# library, you would need to write your own. I can think of two possible approaches, based on which USB device driver you use.

  1. You can use the VCP (Virtual COM Port) driver. With this method, Windows thinks that StimTracker is using a regular COM port (serial port). You can use standard C# function calls to open the port, send commands directly to StimTracker, and close the port when you are done. The list of commands that StimTracker accepts is fully documented. If all you want to do is send an event marker, see the section “DIGITAL OUTPUT COMMANDS — SINGLE PULSE”.

  2. Write a C# wrapper around our own C++ library. You don’t have to wrap every single function; you can do it with only the functions that you are interested in (scan port, open, close, and send a pulse).

Our C++ library uses a different USB driver called D2xx. It provides better timing: 2ms delay with zero jitter vs. about ±5-6ms for the VCP driver.

If you end up developing C# code, and regardless of which method you use, we would appreciate you sharing it with other users. We can list C# support on this page and, of course, give the developers and the lab full credit for it.

1 Like

Thank you for the suggestions, Hisham!

With the VCP approach, we successfully used C# serial port API to send XID commands to StimTracker. The jitter is not a big issue for us at the moment as we are still developing the experiments.

Although we have light sensors on the screen for accurate onset times, we would love to see better timing for software triggers too. Basically, we only need two functionalities from the C++/Python library: setting pulse duration and sending triggers. I wonder if you have any suggestions on wrapping the C++ library. The library is somewhat less documented than the XID commands…

Thank you in advance!

Best,
Shaoyun

Wrapping the C++ library in C# code requires C# experience, which we don’t have. We are unable to assist in that regard – sorry! If you can find the right person with combined C# and C++ experience, this will take them no more than half a day to implement.

Keep in that when you get the C# wrapping working, you will need to wrap more than just the two functions for setting pulse duration and sending triggers. You will also need to wrap the functions that scan the ports, open them, and close them. This is because our library does not use the VCP driver (that’s how we are able to achieve the better timing).