Hi, just received our testing U3, and I can succesfully use loadlib in matlab to load the exodriver:
Great job. In our limited Matlab experience, you finished the hardest part.
Does the exodriver provide the same functionality as the labjackUD (it has many more fucntions listed by matlab)?
No. The Exodriver is a thin layer around the hardware (think exoskeleton). It provides 4 primary functions: Open, Write, Read, and Close. A minimal program works something like this:
1. Open the U3 (
LJUSB_OpenDevice)
2. Write a command to the U3 (
LJUSB_Write)
3. Read the response (
LJUSB_Read)
4. Repeat 2 and 3
5. Close when done (
LJUSB_CloseDevice)
You use
Section 5 of the U3 User's Guide to build the commands the U3 expects. There are lots of examples of how to do this C in and Python. The
Exodriver examples has the C code. There's a
u3.h that implements the UD driver "e-" functions. This is the difference between the Exodriver and the UD driver. The UD driver has those functions built-in, the Exodriver has implementations in user application code. If you know how you may be able to call
eDO from u3.h if you build u3.c as a library and load it into Matlab. We've never done this, so we don't know if it would work. In your case, it sounds easier to us to just send the bytes your self rather than rely on the C code.
To know what bytes to write to the U3, we recommend grabbing a copy of LabJackPython. It is a great way to see the bytes coming and going to the U3. To set FIO4 to be output high and then output low:
>>> import u3
>>> d = u3.U3()
>>> d.debug = True
>>> d.getFeedback( u3.BitDirWrite(4, 1), u3.BitStateWrite(4, 1) )
Sent: [0x1d, 0xf8, 0x3, 0x0, 0x20, 0x1, 0x0, 0xd, 0x84, 0xb, 0x84, 0x0]
Response: [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None, None]
>>> d.getFeedback( u3.BitDirWrite(4, 1), u3.BitStateWrite(4, 0) )
Sent: [0x9c, 0xf8, 0x3, 0x0, 0xa0, 0x0, 0x0, 0xd, 0x84, 0xb, 0x4, 0x0]
Response: [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None, None]
In the code above, we're sending a feedback command which is documented in
Section 5.2.5 of the U3 User's Guide. In the feedback command, we're sending
BitDirWrite to set FIO4 to output, and
BitStateWrite to set FIO4's state to high.
So to set FIO4 to output high from Matlab, all you would have to do is have a function that calls LJUSB_Write() with these bytes:
Sent: [0x1d, 0xf8, 0x3, 0x0, 0x20, 0x1, 0x0, 0xd, 0x84, 0xb, 0x84, 0x0]
And then call LJUSB_Read() to read 10 bytes, which you can ignore since they don't tell you much.
It's a low-level interface, but it's very efficient, and it's explicit about what it's doing. Your application seems simple enough that you could hide the low level bytes to send in one or two functions.
Let us know how it goes. We'd like to know about more Mac OS X customers using their LabJacks with Matlab.