LabJack on linux to read in inputs/triggers for screen flips in matlab

Hi PTB community!

I have a PTB3 installed on my ubuntu 22.04 laptop and have been using a labjack U3 for quite reliable TTL outputs for screen flips using the linux exodriver and following function:

I would also like to use the labjack to read in TTL/voltage inputs to trigger screen flips but I have been having trouble getting the code to work in matlab. Has anyone been able to read in inputs in Matlab?

Thanks and best!

Hi, this should be easy to do with the exodriver, although my code wasn’t designed to read data, just send triggers etc.

I vaguely remember someone shared a MATLAB class to read data with the exodriver on the LabJack forums. I did a quick Google search but didn’t find it.

The general docs are here:

It was many years since I looked at this and I switched over to the LabJack T4 ages ago (which also has a really nice Linux/macOS interface, ModBus), where I did set up read+write.

The Python library probably has the code that would help remind which commands are needed: LabJackPython for UD, Exodriver, U12 - Windows, Mac, Linux

I have little time to do this, so while it is IMO easy to add, I won’t be able to get round to it in the near future.

Thanks so much for the info and responding!

I have tried the python interface which works for reading in inputs from the U3, but have been having trouble getting matlab lab to read this in, which I am guessing may be from the command.

If T4 has read and write capabilities, we may try that! Thanks!

I can much more easily help with T series as we are actively using them and as the Modbus commands are slightly easier to setup. I still really like the exodriver (tiny library, easy to set up, easy to load into MATLAB), but the T series has several advantages (and the modbus library is also still really small when compared to the bloated drivers that NI or MC need for their USB DAQs). For example for command-response it has a tiny Lua engine so you can send commands quickly and let Lua do processing in the background while PTB keeps in its loop.

My main class is here, I tried to keep the interface consistent with the U series but it has added commands:

Example use:

l = labJackT('openNow', true);
l.sendStrobe(128); % sends value 128 : 0-2047 controls EIO0-8 & CIO0-3 11bit word - 2048 TTLs CIO-4 for 10ms
v = l.getAIN(1); % get a voltage
l.startStream() % start data streaming mode
l.stopStream(); % stop data streaming mode
l.close;

Thank you! I will look into this! By any chance do you see a large latency delay in using a labjack T4 vs an arduino with IOport to generate TTLs?

  1. Using a classic arduino and MATLAB’s current Arduino toolbox: T4 is much much better. this is mostly due to MATLAB’s terribly bloated arduino toolbox. I got variable delays > 30ms.
  2. Using the older MATLAB arduino toolbox (legacy version): T4 is faster than a classic arduino and not clearly slower than a more powerful USB3 Seeduino Xiao.

In general command-response (as you use with a TTL or strobed word) times are sub-millisecond on U and T series Labjacks. USB is a tiny bit slower than ethernet when I tested on a T4.

At least for digitial output, there isn’t a strong advantage of a LabJack over an arduino other than the hardware itself makes it a bit easier with the DB15 and screw terminals etc.

I haven’t test the latest Arduino Uno R4, but the previous generation were clearly slower than alternative arduino boards like the Xiao I mentioned above. Some performance code for different arduino’s and serial libraries can be found here: https://psychtoolbox.discourse.group/t/serial-port-interface-code-a-performance-comparison – I imagine the new R4 would remove this gap…