Can't open U12 after restarting Mac on MacOS > Yosemite | LabJack
 

Can't open U12 after restarting Mac on MacOS > Yosemite

11 posts / 0 new
Last post
ScottC
ScottC's picture
Can't open U12 after restarting Mac on MacOS > Yosemite

I'm running "Exodriver example", which counts Labjack devices that are physically connected. I modified it to open a U12 if found. It works (LJUSB_OpenDevice returns a large int) right after I plug the U12 in, but after I restart the Mac it can't open the U12 (the returned handle is 0). Below is main.c. My mods start with the if statement. (This problem didn't happen with MacOS 10.10 and earlier)

#include <stdio.h>

#include "labjackusb.h"

 

int main (int argc, const char * argv[]) {

    printf("How many LabJacks are connected?\n");

    

    int numU3s = LJUSB_GetDevCount(U3_PRODUCT_ID);

    int numU6s = LJUSB_GetDevCount(U6_PRODUCT_ID);

    int numUE9s = LJUSB_GetDevCount(UE9_PRODUCT_ID);

    int numU12s = LJUSB_GetDevCount(U12_PRODUCT_ID);

    printf("U3s: %d\n", numU3s);

    printf("U6s: %d\n", numU6s);

    printf("UE9s: %d\n", numUE9s);

    printf("U12s: %d\n", numU12s);

    

    if (numU12s > 0) {

        HANDLE han;

        printf("Opening the first U12\n");

        han = LJUSB_OpenDevice(1, 0, U12_PRODUCT_ID);

        printf("Handle: %d\n", han);

        LJUSB_CloseDevice(han);

    }

    return 0;

}

 

A typical result of running it under MacOS 10.13.3, High Sierra, is (when the Open succeeds)

How many LabJacks are connected?

U3s: 0

U6s: 0

UE9s: 0

U12s: 1

Opening the first U12

Handle: 41945088

Program ended with exit code: 0

 

EDIT: I have both LabJackHID.kext and LabJackNoHID.kext in /System/Library/extensions. Is that normal?

LabJack Support
LabJack Support's picture
If you power cycle your U12

If you power cycle your U12 now after your reboot, can your application find the U12? Or in general after your reboot the U12 can't be found?

Check that the U12 LED is on to indicate it is enumerated. Also, you can check System Information and in USB see if you can see the U12.

Make sure no other application has your U12 open since only one process can claim a USB device. If you have another application, make sure it closes the U12 before another application tries to open it.

Make sure that the LabJackHID.kext is not blocked. The U12 requires this kext file to prevent the Mac HID driver from claiming it, and so libusb can open it. macOS 10.13 introduced "User-Approved Kernel Extension Loading", so you may need to allow the kernel extension. Double check your "Security & Privacy" and make sure it isn't blocked. This page here shows the Security & Privacy window and what to look for.

https://developer.apple.com/library/content/technotes/tn2459/_index.html

ScottC
ScottC's picture
Thanks for all the info.

Thanks for all the info. Sorry I forgot to mention that it starts working again if I unplug/replug cable in computer's USB port.

The Mac can always see the U12 when it is plugged in, and so can the Exodriver example app. The app can see it- it just can't open it until power is cycled. 

No other (user-owned) application has claimed the device.

I've visited "Security & Privacy" and there's no indication the kext is blocked. Anyway, this failure occurs in El Capitan and Sierra as well, but not Yosemite. So the problem may have been created by the change from 10.10 to 10.11.

I tried disabling "SIP" using csrutil on a Sierra system and it didn't improve things. I think SIP was introduced in 10.11, the oldest OS with this problem. 

When I start the Mac there are 4 flashes followed by 2 more, and then the light stays solid green.

LabJack Support
LabJack Support's picture
We'll try the U12 on macOS 10

We'll try the U12 on macOS 10.13 at the start of next week. U12 hasn't had much testing beyond 10.10, but no one has reported an issue like this until now.

Some other things to try in the meantime:

1. Remove all the LJUSB_GetDevCount calls and just try to open the first U12.

2. After your LJUSB_OpenDevice, use errno ("man errno" for documentation) to see if there is a useful error code. Exodriver sets errnos based on the libusb error:

https://github.com/labjack/exodriver/blob/master/liblabjackusb/labjackus...

ScottC
ScottC's picture
Removing the other

Removing the other GetDevCount's didn't seem to help.

The error after restarting is "Permission denied" (13) when the U12 is found but can't be opened. No other app was running, but that's the same error I get when another application is using the device.

 

Thanks again

Scott

LabJack Support
LabJack Support's picture
I tested on Mac running macOS

I tested on Mac running macOS 10.13.3 and I didn't see your issue. Running your code and our Exodriver example multiple times found and opened the U12 without problem.

Disconnect your U12, run the installer from the following page, plug in your U12 and see if that helps:

https://labjack.com/support/software/installers/u12

This installs the ljacklm high-level driver, Exodriver, libusb, and LabJackHID.kext. This differs from the Exodriver only installer which makes the LabJackHID.kext optional, so if you used that installer you may have missed installing it. The kext gets installed to the /System/Library/Extensions/ directory.

If you are using OS X 10.11, make sure it is running version 10.11.4 or later. Earlier versions had a USB layer bug where USB close calls were not working, keeping handles open after the process stopped.

ScottC
ScottC's picture
Thanks for the suggestions. I

Thanks for the suggestions. I am also running 10.13.3. The installer is the same as I have already installed, but I followed your directions. I was able to open the U12 as expected, but after I restarted the Mac I was unsuccessful. When you say you ran the code multiple times, have you been restarting the computer? My procedure:1. Plug in the U12

2. Confirm the U12 can be opened by running the code

3. Restart the Mac with the U12 still plugged in

4. Run the code again to see if U12 can be opened. In my case the answer, over multiple Macs and OS's (except 10.10) the answer is no.

 

Thanks

Scott

 

LabJack Support
LabJack Support's picture
To confirm your issue and

To confirm your issue and what I see, the U12 can only be used if you reconnect it after a reboot. After it reconnects, it runs as expected and a reconnect is not needed until next reboot.

It looks like if the U12 is connected while rebooting or before logging in in general, the system is using the HID driver and seemingly not using settings from the LabJackHID.kext to use the standard USB IO interface for libusb-1.0 compatibility. After logging in and connecting, it starts using LabJackHID.kext. Apple rewrote their OS X / macOS USB layer in 10.11 so when the issue started would make sense, but I'm unsure what changes are causing this.

If what I am describing is your issue, the current workaround is the U12 needs to be connected after you reboot and log in to your Mac. Alternatively there is a Watchdog feature to have the U12 reset on its own every X seconds if there are no communications, though you do not want to turn this on and off repeatedly for flash life.

Keep in mind the U12 is a legacy device and development from us on it is limited as we are focused on our more modern devices which have Mac support without this issue.

ScottC
ScottC's picture
Having to reconnect the USB

Having to reconnect the USB cable is not acceptable. Is the U3 software-compatible with the U12 with regard to MacOS? And can you guarantee that the U3 doesn't have the same problem (Have you tried the same experiment with the U3)?

 

Thanks-

Scott

ScottC
ScottC's picture
OK, I didn't think we had a

OK, I didn't think we had a U3 but someone here was able to locate an old one, hardware V1.21. I modified my modified Exodriver example to find and open a U3, which it did successfully.

 

And after a restart of the Mac it was again able to find and open the U3! So it doesn't have the U12's problem.

 

Thanks for your help.

LabJack Support
LabJack Support's picture
All other LabJack devices do

All other LabJack devices do not have this issue as you found out with the U3. Only the U12 is a HID device and uses a kext, and has the issue of Mac loading it as a HID upon system reboot instead of using the kext settings.