LabJackException NOT throwing an Exception | LabJack
 

LabJackException NOT throwing an Exception

4 posts / 0 new
Last post
ullix
ullix's picture
LabJackException NOT throwing an Exception

Attempting to "harden" my application against user errors, I found the result that a LabJackException message is printed to the terminal, but it is not resulting in an Exception.

Computer has LibJackPython installed, but NOT the exodriver. The code is simply:

# Ubuntu 20.04
# Python 3.8.10
# LabJackPython 2.0.4
# U3 firmwareVersion '1.54', hardwareVersion '1.21'
try:
    import LabJackPython
    print("no exception")
except Exception as e:
    print("my exception", e)

which results in this output:

<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: liblabjackusb.so: cannot open shared object file: No such file or directory
no exception

So, while it tells me that there is an LabJackException (to be expected as the exodriver is not installed), it does not trigger an Exception. Why not?

If this does not work, any other Python way to check for a functioning presence of the Exodriver?

 

LabJack Support
labjack support's picture
LabJackException is a

LabJackException is a subclass of the exception class, so it is an exception. It is defined in LabJackPython.py:

https://github.com/labjack/LabJackPython/blob/master/src/LabJackPython.p...

In the case where the library fails to load, the exception is handled in LabJackPython.py:

https://github.com/labjack/LabJackPython/blob/master/src/LabJackPython.p...

To do something different with the library load failure, you could check the status of the staticLib object/pointer:

import LabJackPython
if LabJackPython.staticLib is None:
    # do something

ullix
ullix's picture
Thanks. So LabJackPython

Thanks. So LabJackPython.staticLib is None  tells me that the driver is not loaded. But this is a bit of catch-22, because in order to give this command I need to have LabJackPython imported, and when I do this I get the Not-Exception rising Exception that my post is about, and which I hoped to eliminate.

I am now using:

import ctypes try: l = ctypes.CDLL("liblabjackusb.so", use_errno=False) print("LabJack driver is installed: ", l) foundDriver = True except Exception as e: print(e) foundDriver = False

Can I rely on the Linux driver always being called liblabjackusb.so?

 

LabJack Support
labjack support's picture
The initial issue in your

The initial issue in your post is that a library import failure does not throw an exception in your program where you import LabJackPython. As previously stated, the library import can cause an exception, but that exception is handled as shown in LabJackPython.py. The library load failure is not necessarily fatal*, and therefore does not cause any import exception at the level of your program; you should be able to import LabJackPython and check the staticLib status as stated in our previous response.

The UD device USB driver on Linux should always be called liblabjackusb.so. Your code snippet should work, but please realize this is doing something very similar to what LabJackPython is already doing. The only differences are that you are printing something on success, and you are using a foundDriver boolean for the status instead of checking if LabJackPython.staticLib is None.

*The library import is not fatal because the LabJackPython module has an Ethernet interface for UE9 devices that is not reliant on our shared libraries.