LJFuse
LJFuse makes communicating with a LabJack device simple on Linux and Mac OS X. Really simple. Trivial, really.
Introduction
It’s been said (many, many, times) that everything’s a file in UNIX. LJFuse adopts that philosophy and makes the connections on a LabJack device into files on the filesystem. To do so, it uses FUSE on Linux and MacFUSE on Mac OS X.
For example, to read analog input AIN0, read a file named “AIN0”.
$ cat MyU6/connection/AIN0
3.300
To set DAC0 to 2.4V, write “2.4” to a file named “DAC0”.
$ echo 2.4 > MyU6/connection/DAC0
$ cat MyU6/connection/DAC0 # Read the DAC0 to verify it was set
2.400
To set FIO0 to digital output high, write a “1” to “FIO0”.
$ echo 1 > MyU6/connection/FIO0-dir # Set the direction to output
$ echo 1 > MyU6/connection/FIO0 # Set the state to output high
$ cat MyU6/connection/FIO0 # Read the value back
1
You can do this from any program that knows how read and write files. Your program doesn’t need to know about USB communication, drivers, or the LabJack API. The details are hidden by LJFuse.
Quickstart
Check the requirements (in short, a working LabJackPython installation on Linux or Mac OS X), and download the source code for LJFuse from GitHub. Click the “Download Source” button on the GitHub page to download.
Connect a LabJack and run LJFuse like this:
$ python ljfuse.py
After LJFuse starts, change to the “root-ljfuse/” directory it created and look around:
$ cd root-ljfuse/
$ ls
HOW_TO_UNMOUNT.txt My U6/ README.txt
There are “README.txt” files in every subdirectory with context-specific help.
When done, unmount LJFuse. The file “HOW_TO_UNMOUNT.txt” has instructions.
$ cat HOW_TO_UNMOUNT.txt
Requirements
- A U3, U6, or UE9 over USB with the latest firmware. The U3 requires 1.26 or higher; the U6 requires 1.15; and the UE9 requires control firmware 2.13 and comm firmware 1.5. Check the beta folders of the firmware section if the release version doesn’t meet the requirements.
- LabJackPython
- Exodriver, the Linux and Mac OS X driver
- On Mac OS X, LJFuse requires MacFUSE. On Linux, LJFuse uses the kernel’s fuse implementation.
LJSocket is not required, but LJFuse will automatically access LabJack devices opened by LJSocket. On Mac OS X, LJSocket also has the benefit of allowing LJFuse to run in the background (instead of tying up a terminal window).
Running
Plug in a U3, U6, or UE9 and run:
$ python ljfuse.py
On Mac OS X, it will print
$ python ljfuse.py
Making directory root-ljfuse for LJFuse
Mounting LJFuse at root-ljfuse.
When done, eject it from the Finder or run `umount LJFuse' (without quotes).
$
On Linux, it will print
$ python ljfuse.py
Making directory root-ljfuse for LJFuse
Mounting LJFuse at root-ljfuse.
Unmount it with `fusermount -u root-ljfuse' (without quotes).
$
In either case, change to the “root-ljfuse/” directory and look around. There are “README.txt” files in every subdirectory with context-specific help.
$ cd root-ljfuse/
$ ls
HOW_TO_UNMOUNT.txt My U6/ README.txt
Example session
In this session, we have a U3-HV and U6 connected when running LJFuse:
$ python ljfuse.py
Making directory root-ljfuse for LJFuse
Mounting LJFuse at root-ljfuse.
When done, eject it from the Finder or run `umount LJFuse' (without quotes).
$ cd root-ljfuse/
$ ls
HOW_TO_UNMOUNT.txt My U3-HV/ My U6/ README.txt
LJFuse made two directories, one for the U3-HV and one for the U6. It also made two text files with documentation.
You can rename a device by renaming its directory. The name of the device is saved in its flash memory:
$ mv "My U3-HV" "Marcel"
$ ls
HOW_TO_UNMOUNT.txt Marcel/ My U6/ README.txt
$ mv "My U6" MyU6
$ ls
HOW_TO_UNMOUNT.txt Marcel/ MyU6/ README.txt
Inside a device’s subdirectory, there are files relating to the device’s attributes:
$ cd MyU6/
$ ls
README.txt firmwareVersion serialNumber
connection/ modbus/
$ cat firmwareVersion
1.15
The “connection/” subdirectory is the most interesting. It contains files for the different connections on the device.
$ cd connection/
$ ls
AIN0 DAC0 FIO1 FIO3 FIO5 FIO7
AIN1 DAC1 FIO1-dir FIO3-dir FIO5-dir FIO7-dir
AIN2 FIO0 FIO2 FIO4 FIO6 README.txt
AIN3 FIO0-dir FIO2-dir FIO4-dir FIO6-dir
Wire a jumper from DAC0 to AIN0 and run:
$ echo 1.5 > DAC0 # Set DAC0 to 1.5V
$ cat DAC0 # Verify that it set
1.500
$ cat AIN0 # Read AIN0
1.499
Connect an LED from FIO2 to GND (short side in GND) and toggle it:
$ cat FIO2-dir # Check the direction of FIO2
0
$ echo 1 > FIO2-dir # Set FIO2 to output
$ cat FIO2-dir # Verify the direction changed
1
$ echo 1 > FIO2 # Set FIO2 high, turning LED on
$ echo 0 > FIO2 # Set FIO2 low, turning LED off
$ while true # Show off a little
> do # Toggle the LED once per second
> echo 1 > FIO2
> sleep 1
> echo 0 > FIO2
> sleep 1
> done
^C # Hit Ctrl-C to quit
We hope these examples demonstrate how quickly and easy LJFuse makes it to communicate with your LabJack.
Shell tricks
The shell can operate on the files in the “connection/” directory to ask interesting questions. For example, which FIO connections are set to digital output?
$ grep 1 FIO?-dir
FIO0-dir:1
FIO2-dir:1
Answer: FIO0 and FIO2. Here’s how to set them all to digital output:
$ for fiodir in FIO?-dir
> do
> echo 1 > $fiodir
> done
Verify that it worked:
$ grep 1 FIO?-dir
FIO0-dir:1
FIO1-dir:1
FIO2-dir:1
FIO3-dir:1
FIO4-dir:1
FIO5-dir:1
FIO6-dir:1
FIO7-dir:1
Here’s how to ask if a value is above a threshold. Carrying on with a previous example, wire a jumper connecting DAC0 to AIN0.
$ cat DAC0
1.500
$ cat AIN0
1.499
$ THRESHOLD=1.6
$ AIN0=$(cat AIN0)
$ if [ $(echo "$AIN0 > $THRESHOLD" | bc) -eq 1 ]
> then
> echo "AIN0: $AIN0 above threshold $THRESHOLD"
> else
> echo "AIN0: $AIN0 below threshold $THRESHOLD"
> fi
AIN0: 1.499 below threshold 1.6
$ echo 2.0 > DAC0
$ cat DAC0
2.000
$ cat AIN0
1.999
$ AIN0=$(cat AIN0)
$ if [ $(echo "$AIN0 > $THRESHOLD" | bc) -eq 1 ]
> then
> echo "AIN0: $AIN0 above threshold $THRESHOLD"
> else
> echo "AIN0: $AIN0 below threshold $THRESHOLD"
> fi
AIN0: 1.999 above threshold 1.6
Exiting and unmounting LJFuse
To stop LJFuse, all applications and terminal windows must exit the LJFuse “root-ljfuse/” directory and its subdirectories.
$ pwd
/path/to/LJFuse/root-ljfuse/MyU6/connection
$ cd ../../..
$ pwd
/path/to/LJFuse
On Linux run:
$ fusermount -u root-ljfuse
On Mac OS X, find the LJFuse icon in the Finder and eject it. You could also run:
$ umount LJFuse
If unmounting returns an error, double check that all applications and terminal windows have exited LJFuse directories. Since 10.6, the Mac OS X Finder will report which application is using a volume when trying to eject it.
Programming language examples
The following examples illustrate how to
- Read AIN0 once per second and log timestamp and value
- Toggle an LED on FIO0
in many different programming languages. The examples would not be out of place in any introductory programming book. All they do is basic file I/O.
Shell
C
Python
Ruby
PHP
Perl
Java
Scala
LabVIEW
All Support Guides
Search
Shopping Cart
Testimonials
-
Sheesh, guys. I placed this order late afternoon the day before a holiday weekend, and the best you could do is ship it an hour later? [...] My LabJack did just what it was supposed to, and at a very attractive price.
—Olin, Oxford Systems, Inc.



Comments
#1
Is it possible to use Ljfuse with labJack U12. I tried following the above steps, and get no error meeages, but myroot-ljfuse directory only contains HOW_TO_UNMOUNT.txt README.txt i.e. no "my U12". Then I noticed that U12 is not amongst the products listed in the requirements.
#2
No, LJFuse does not have U12 support.
#3
Hi Is there any way to make LJFuse communicate with a LabJack UE9 via ethernet/IP? /Roger
#4
Not at this time, but it is planned for the future.
Right now Modbus is probably the simplest interface if you want to talk to a UE9 from some unsupported software.
#5
I'm trying to get LJFuse up and running on OSX 10.6.5, with python 2.6.6. I want to talk to it with Ruby, but Ruby-libusb support seems dated/questionable, so LJFuse looked like the best shot.
I installed current exodriver, no apparent errors and the u6BasicConfigU6 example runs fine.
I installed MacFUSE, no apparent errors.
Installed fusepy, no apparent errors.
download and untar ljfuse, and then run python ljfuse.py:
Traceback (most recent call last):
File "ljfuse.py", line 25, in <module>
from fuse import FUSE, Operations, LoggingMixIn, fuse_get_context
File "/Users/aaronstewart/Downloads/LJFuse/fuse.py", line 243, in <module>
raise EnvironmentError('Unable to find libfuse')
EnvironmentError: Unable to find libfuse
Thoughts?
#6
MacFUSE needs to be installed first. Quoting the requirements, "On Mac OS X, LJFuse requires MacFUSE. On Linux, LJFuse uses the kernel’s fuse implementation."
#7
I have MacFUSE version 2.0.3 installed.
#8
Also, if you check the /usr/local/lib directory do you see libfuse.dylib . I believe that's what fuse.py is looking for, and should have been installed by MacFUSE.
#9
Sorry, I somehow missed that in your first comment. Have you tried restarting your Mac.
#10
It has been restarted since the various installations.
/usr/local/lib/libfuse.dylib is present, and symlinks to /usr/local/lib/libfuse.0.dylib.
#11
The problem was resolved in this forum topic: http://forums.labjack.com/index.php?showtopic=5008
#12
I'm very excited about using LJFuse to talk to the LabJack. Have you been able to run any performance tests using a compiled language? It would be interesting to see a table showing the different ways to talk to the LabJack and the different speeds that you can achive. For example, using C, what is the performance of using LJFuse versus making direct calls to the driver?
#13
As of right now, we haven't run any benchmarking tests on LJFuse. It is not at the top of our queue, but we will try to get some numbers soon.
It would be my guess that LJFuse will lose against direct calls to the driver. Any performance hit is more than worth it for the languages we don't directly support, or users new to the LabJack.
#14
Has anyone experience in using the LabJack interface with the programming language Runtime Revolution?
To use the LabJack DLL wrapping a DLL in C is required.
Perhaps it is even easier with LJFuse.............
#15
Any language that can do file I/O can use LJFuse. A Mac OS X or Linux user using any language that isn't C or Python is better off with LJFuse.