Detecting the presence of an U3 even when in use elsewhere

20 posts / 0 new
Last post
ullix's picture
Detecting the presence of an U3 even when in use elsewhere

I am using an U3 in Python3 on Ubuntu Linux, and it works well.

However, I am struggling with one issue: I am using several instances of my program in combination with different non-LabJack devices, and on starting the program checks for the presence of these devices.

To determine the presence of the U3 I use the command "if len(LabJackPython.listAll(3)) > 0:". But after I issue "device = u3.U3()", the command returns an empty dictionary, same as it would do if no U3 were connected.

So, I can't tell wether there is no U3 plugged in - because I might have ripped out the USB cable - or wether it is used already in another instance.

Is there a way to get a return from any command like "U3 is connected but in use"?



LabJack Support
LabJack Support's picture
Currently there is no command

Currently there is no command in LabJackPython and the U3 module that returns if a device is being used used in another process.

If you only have one U3 connected and are opening the first found device ("u3.U3()" is first found), immediately after the failing "u3.U3()" call you can check errno for EBUSY (16). Errno EBUSY is set by the Exodriver's open call when it tries to claim a device but it is busy (libusb error LIBUSB_ERROR_BUSY: if another program or driver has claimed the interface). Something like:

import u3
import ctypes

    print("Couldn't open my U3.")
    err = ctypes.get_errno()
    if err == 16:
        print("My U3 is busy, and likely opened in another process.")

ullix's picture
Thank you, it does work.

Thank you, it does work.

It does look a bit cumbersome, though, having to load another module just to get an error number, which should be available in the LabJackPython and u3 modules already?

Most importantly, does it work on Linux, Windows, and Mac in the same way?

LabJack Support
LabJack Support's picture
Most importantly, does it

Most importantly, does it work on Linux, Windows, and Mac in the same way?

No, the method described in my previous email only applies to Linux and Mac as they use errno. The Windows driver, UD, does not use errno but it does have a "LabJackPython.LabJackException: LabJack is already open via USB in another program or process" exception. This error is only available on Windows as its driver provides it. The Exodriver only provides the errno functionality which can only detect if a LabJack is busy.

I can look into detecting EBUSY errno and adding more details to the current open error message on Linux and Mac. The Windows error will remain the same.

ullix's picture
Sigh. Any simplification and

Sigh. Any simplification and homogenization will be appreicated, thanks.

LabJack Support
LabJack Support's picture
I updated LabJackPython on

I updated LabJackPython on GitHub so the USB open on Linux and macOS will detect an access or claim error, and mention so in the exception message.

As a side note, the errno check in my first post was Linux only compatible. On macOS, errno 13 (EACCES due to libusb error LIBUSB_ERROR_ACCESS) will be set if a device is claimed in another or current process.

ullix's picture
I installed the latest update

I installed the latest update, but I don't see this as a helpful improvement.

When calling u3.U3() for the second time, I get this exception message: 'Couldn't open device. Please check that the device you are trying to open is connected.' Is that what it is supposed to be?

Informationwise it is not really different from where I started, because I still can't distinguish between "not available because I ripped out the cable inadvertently", or "not available, because already in use".

I first suspected I had installed the update incorrectly and really was still using the old version, so I looked for the usual suspects for version information, like "LabJackPython.__version__" and variants, but all I could find was "LABJACKPYTHON_VERSION = "5-26-2015"", which isn't really helpful to distinguish between modifications all occuring in 2018.

Likewise, no helpful version info for u3 and ei1050.

One more suggestion: the Readme suggests to install LJP with "$ sudo python install". Well, on my Ubuntu 16.04 the command python is for version Py2, and I now need to use command python3. Although I knew this, I fell to this trap :-/. Some warning in the Readme might be helpful.

So, errno works on Linux and Mac, but Linux uses errno=16, and Mac uses errno=13, and Windows uses something different.


LabJack Support
LabJack Support's picture
I updated our LabJackPython

I updated our LabJackPython on GitHub with newer versioning. Versioning is still date based, "1.<YEAR><MONTH>", but is now PEP compliant so pip and others can do versioning with them correctly. The version is 1.201812. Also, I added LabJackPython.__version__. Version numbers are currently only in the LabJackPython module. The ei1050 is part of an example without a version.

As for the open error messages on Linux and macOS, for a u3.U3() command there are these two error messages:

Couldn't open device. Please check that the device you are trying to open is connected.
Couldn't open device. Device access or claim error. Please check that the device is not already open in another or the current process.

Two u3.U3() calls in a row should produce the second error, assuming there is a device connected and the first call was successful. Install the updated LabJackPython. If you are not seeing the "Device access or claim error." message, check if LabJackPython.__version__ 1.201820 is being used.

If after reinstalling and you don't see the new version, try cleaning up the old LabJackPython files in your installations's "site-packages" directory. Remove LabJackPython related egg and egg-info files that are not version 1.201820. If that does resolve it, further remove these files if they are present:

ullix's picture
Thanks for your efforts and

Thanks for your efforts and quick answers. I'll test it soon, but something else is confusing: My first post of this thread went into moderation. OK. The others, however, disappeared after posting; I could not even see them even while I was logged on. But they were visible the next day.

My last post has disappeared completely, not even visible now, yet, you seem to have responded to it ???

Anything wrong with forum or my mistake?

ullix's picture
I downloaded the update as a

I downloaded the update as a zip package and installed with "sudo python3 install", and all went fine!

Using year and months as version is perfectly ok with me; though given your updating pace you may need at least the day also ;-). And what holds you back from giving such versions also for u3 and ei1050? Gives me more confidence on checking my installation.

So now I simply do:

        lju3 = u3.U3()
    except Exception as e:
        stre = str(e)
        if "Couldn't open device. Please check that the device you are trying to open is connected." in stre:
            print("No LabJack device found. Is it connected?")

        elif "Couldn't open device. Device access or claim error" in stre:
            print("A LabJack device was found, but it may already be in use by a different program")

            print("Connecting to LabJack device gave unexpected error: {}".format(stre))

Since there is no (alpha-)numeric error code within the exception data e, the checking is a bit clumsy. But it works!

So, this now works for Linux and Mac, but is still different for Windows?


LabJack Support
LabJack Support's picture
In regards to the forum,

In regards to the forum, posts aren't visible until we approve them. We had forgotten to approve your post that we replied to—that's been fixed now. Sorry that it's confusing, but at least it's nothing wrong with how you're using the forum.

In regards to your other questions, we'll answer them soon.

LabJack Support
LabJack Support's picture
Windows has three errors

Windows has three errors which are based on the UD driver error system and error strings:

LabJackPython.LabJackException: LabJack not found
LabJackPython.LabJackException: Device no longer connected
LabJackPython.LabJackException: LabJack is already open via USB in another program or process

With the LabJackException.errorCode set to 1007, 1015 and 1010 respectively. "Device no longer connected" indicates a previously opened device is now disconnected. Note on Windows, its driver does not provide a close call for a single device. LabJackPython.Close() needs to be called and closes all device handles in the process.

Regarding versioning, our LabJackPython interface and its modules have just the one version collectively, which currently is only in the module. If we were to have a version in the other modules, it would just be the version from which all the other modules use. The last change to detect the device claim / no access was a a function in which applies to the U3, U6 and UE9. The ei1050 class is not part of the LabJackPython modules. It is part of example code, and we do not version examples.

ullix's picture
Well, this is a bit of a

Well, this is a bit of a bummer for your new "Python3 compatible" LabJackPython release:

I downloaded, unzipped and installed using :

$ sudo python3 install

(I suggest to add some wording that you may have to use python3 if you also have a python2 version installed!)

So far I had used LabJackPython 1.201812 (see discussion above), and my program GeigerLog ran smoothly with it. But now I get:

EXCEPTION: ''NoneType' object has no attribute 'LJUSB_OpenDevice''

when I execute

lju3 = u3.U3()



LabJack Support
LabJack Support's picture
Are you having the NoneType

Are you having the NoneType issue on Ubuntu, or a different operating system?

The NoneType errors with Exodriver calls indicates the USB driver could not be loaded during your import u3 or LabJackPython call. Usually there is a warning message during the import to indicate the Exodriver could not load. Double check the version installed with LabJackPython.__version__ and that it is the 2.0.0 release.

In the current release's README, it does mention something about multiple installations based on your previous suggestion:

To install LabJackPython, run the following command in a terminal (remove "sudo"
on Windows):

    $ sudo python install

If there are multiple versions Python installed, run the install command with
the Python version you want to install to. For example, on Linux if both
Python 2.7 and 3.5 are installed, you can install to Python 3.5 with:

    $ sudo python3.5 install

Our LabJackPython page doesn't mention the multiple installs part, so that is something we can look into adding.

ullix's picture
The os is Ubuntu Mate 16.04.5

The os is Ubuntu Mate 16.04.5 LTS with kernel 4.15.0-45.

The LJP version is reported as "2.0.0".

As I said, I had a working installation - see above posts - and all I did was to install your new LJP2.0.0. Nothing else was changed.

Looking for more error messages, I found:

<class 'LabJackPython.LabJackException'>: Could not load the Exodriver driver. Ethernet connectivity only.

Check that the Exodriver is installed, and the permissions are set correctly.
The error message was: cannot open shared object file: No such file or directory

LabJack Support
LabJack Support's picture
1. What is the output of

1. What is the output of installing Exodriver?


2. What is the output of the following command?

ls -l /usr/local/lib/liblabjack*


3. If it's still not working, reboot and try again.

ullix's picture
$ ls -l /usr/local/lib

$ ls -l /usr/local/lib/liblabjack*
ls: cannot access '/usr/local/lib/liblabjack*': No such file or directory

Same answer as already implicit in my post #15 - the file is missing.

Obviously, rebooting has no effect on this.

Remember that I did nothing like installing LabJackPython in the very same way as I did a few times during the discussion in this thread!

It had worked, but now it does not. Looks like the installation of LJP 2.0.0 had deleted the liblabjack* file?


ullix's picture
Just for comparison, here is

Just for comparison, here is the output from a 2nd computer, which is the same os and upgrade status as the 1st, and here it is working:

$ ls -l /usr/local/lib/liblabjack*
lrwxrwxrwx 1 root root    22 Mär 12  2017 /usr/local/lib/ ->
-rwxr-xr-x 1 root root 38296 Mär 12  2017 /usr/local/lib/

$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import LabJackPython as ljp
>>> ljp.__version__


LabJack Support
LabJack Support's picture
The LabJackPython 2.0.0

The LabJackPython 2.0.0 installation does not remove Exodriver library files. It only copies Python related files. Unless they were manually deleted or another application deleted them, I'm not sure why the Exodriver files are now missing.

Seeing as the files no longer exist, please reinstall the Exodriver library files:

If there are problems during Exodriver installation, let us know.

ullix's picture
Reinstalled the exodriver and

Reinstalled the exodriver and everything works fine; very strange.

Anyway, ok now with all the latest versions, thanks.