unbit / foohid-py

Python wrapper for the foohid OSX driver
MIT License
18 stars 6 forks source link

Unable to open it_unbit_foohid service. #8

Open TwistedBlizzard opened 7 years ago

TwistedBlizzard commented 7 years ago

I am receiving the same error that seemed to be a problem in 2015. I am running macOS Sierra 10.12.5 on a mid 2015 macbook pro.

Foohid will run for a short amount of time before displaying: Traceback (most recent call last): File "test_joypad.py", line 36, in <module> foohid.create("FooHID simple joypad", struct.pack('{0}B'.format(len(joypad)), *joypad), "SN 123", 2, 3) SystemError: unable to open it_unbit_foohid service

I have followed the troubleshooting steps multiple times and also tried uninstalling/reinstalling the module with pip.

dwang733 commented 7 years ago

I think your main issue is that you're installing the module through pip. The version on pip is old and has not been updated for 2 years. If you want to install this, you'll need to git clone the repo to your computer, then run the installation script by running python setup.py install from terminal.

TwistedBlizzard commented 7 years ago

I've just tried that and I'm having the same issue. I think I had done it before as well, which would explain why pip had a fit when I asked it to uninstall the module.

dwang733 commented 7 years ago

Hmm...in that case, try doing the following:

  1. Go to /Library/Extensions/ and make sure that foohid.kext is there.
  2. Try running a different test, like test_keyboard.py, and see if that works.
  3. In case the package wasn't properly updated, go to your site-packages folder for python and delete the folders/files that start with "foohid", and try running the installation script again.
TwistedBlizzard commented 7 years ago

I have followed these steps and I'm still having the issue.

dwang733 commented 7 years ago
  1. What version of python are you using?
  2. Try typing ioreg into terminal. You'll see a list, and near the bottom of the list, you should see "it_unbit_foohid_userclient". If this is repeated a bunch of times (like 50+ times), reinstall the kext.

If this doesn't work, let me know and I'll try to send a modified version of foohid.c to try to debug this.

TwistedBlizzard commented 7 years ago

I have tried with both 2.7.13 and 3.6.0. Yeah, it's listed a whole bunch of times. In the process of unloading the kext, I get: (kernel) Can't unload kext it.unbit.foohid; classes have instances: (kernel) Kext it.unbit.foohid class it_unbit_foohid_device has 5 instances. Failed to unload it.unbit.foohid - (libkern/kext) kext is in use or retained (cannot unload). Should I just force remove it?

dwang733 commented 7 years ago

If you're getting that error, you can just delete the file manually, but I think you'll need to restart your computer for it to work. Then, you can reinstall the kext again.

TwistedBlizzard commented 7 years ago

I have now reinstalled the kext and I am still getting the same error. It worked fine until I tried to read the output from foohid at which point it crashed immediately.

dwang733 commented 7 years ago

I'm sort of confused. What do you mean by reading the output? Is it the same error as before?

TwistedBlizzard commented 7 years ago

Yes, sorry. What I'm saying is as soon as I open this to check that the script is working, the crash occurs. The script also crashes if it is left alone for a while.

dwang733 commented 7 years ago

Try running the keyboard test first and see if that works. I'm not sure if the joypad test actually works, so I'll try it on my end and see.

TwistedBlizzard commented 7 years ago

I got the same error about 5 seconds after launching the keyboard test. Interestingly, there was no keys pressed during those 5 seconds.

dwang733 commented 7 years ago

Open up foohid.c in a text editor, and replace the foohid_connect method with the following:

#include <mach/error.h>
static int foohid_connect(io_connect_t *conn) {
    io_iterator_t iterator;
    io_service_t service;
    kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(FOOHID_SERVICE), &iterator);
    printf("Get service ret: %X %X %X\n", err_get_system(ret), err_get_sub(ret), err_get_code(ret));
    if (ret != KERN_SUCCESS) return -1;

    while ((service = IOIteratorNext(iterator)) != IO_OBJECT_NULL) {
        ret = IOServiceOpen(service, mach_task_self(), 0, conn);
        printf("Iterate: %X %X %X\n", err_get_system(ret), err_get_sub(ret), err_get_code(ret));
        IOObjectRelease(service);
        if (ret == KERN_SUCCESS) {
            IOObjectRelease(iterator);
            return 0;
        }
    }

    IOObjectRelease(iterator);
    return -1;
}

Run the installation script again, and run the keyboard test again. Let me know what the output is (there should be 3 numbers per line outputted)

TwistedBlizzard commented 7 years ago

Here's my full output from that: Get service ret: 0 0 0 Iterate: 38 0 2C7 Get service ret: 0 0 0 Iterate: 38 0 2C7 Traceback (most recent call last): File "test_keyboard.py", line 51, in <module> foohid.create("FooHID simple keyboard", struct.pack('{0}B'.format(len(keyboard)), *keyboard), "SN 123", 2, 3) SystemError: unable to open it_unbit_foohid service

dwang733 commented 7 years ago

For some reason, you're getting an "unsupported function" error, which is really confusing. I've never encountered this error while working on this, and Google isn't particularly useful for this. The only thing I can say is just unload and remove kext, restart computer, and try to reinstall kext again. I'm not sure what the cause is, but I'll try my best to figure out the reason.

TwistedBlizzard commented 7 years ago

Thank you for all your help! I'm more than happy to help you out with any possible solutions/further diagnostics. I ran the joystick test again and it worked for about 10 seconds after a fresh install of the kext before dying again. Would the full output from that be of any help to you now that I have the modified foohid.c?

dwang733 commented 7 years ago

Yeah, that would be really useful. I only need the lines that are not "0 0 0", but full output is completely fine.

TwistedBlizzard commented 7 years ago

Here's what happened: Iterate: 38 0 2C7 Traceback (most recent call last): File "test_joypad.py", line 44, in <module> foohid.send("FooHID simple joypad", struct.pack('H4B', 0, x, y, z, rx)) SystemError: unable to open it_unbit_foohid service

What's really strange though, is that I force removed the kext, rebooted and then ran the test, forgetting to reinstall the kext but the test worked anyway. Well, until it crashed.

dwang733 commented 7 years ago

Yeah, that's really strange. I wasn't able to replicate it on my computer. Does it work if you reinstall the kext?

TwistedBlizzard commented 7 years ago

I have reinstalled the kext one last time and things seem to be going more smoothly now. I haven't had a crash yet but I'm only a couple of minutes into testing.

dwang733 commented 7 years ago

I think you should be good then, so it's your choice if you want to keep the modified version or not. If you happen to run into a "38 0 2e9" error, you should be good if you follow the troubleshooting section (I'm pretty sure you don't need to restart your computer in that case, but if you keep running into that error, restart just to be safe).

TwistedBlizzard commented 7 years ago

I just got a crash again. After the crash, if I run the script again, it will loop once or twice before crashing with some serious lag between loops.

dwang733 commented 7 years ago

I assume that it still gives a 2C7 error?

TwistedBlizzard commented 7 years ago

That is correct.

dwang733 commented 7 years ago

Yeah, sorry, I'm really not sure what's causing this. I haven't been able to replicate it at all on my computer :(

TwistedBlizzard commented 7 years ago

I've found it happens much quicker if I reduce the sleep() value - putting it at 0.05 caused the crash within 2 seconds. Other than that, is there anything I can try to maybe get some more valuable information?

dwang733 commented 7 years ago

I think those error codes are as specific as you can go. The full list is here if you're interested in it: errors. The only possible solution I can think of right now is to remove the IOObjectRelease(service); line in foohid_connect (that line was added very recently, maybe that's the problem?). This sounds like some weird memory leak caused when it's called a certain amount of times.

TwistedBlizzard commented 7 years ago

I've removed that line and reinstalled but I'm still getting the 2C7 crash. I'm doing some digging in the console and I've found that taskgated crashes at the same time with MacOS error: -67062.

dwang733 commented 7 years ago

Just wondering, do you happen to have an anti-virus? If you do, try disabling it and see if that works.

TwistedBlizzard commented 7 years ago

I don't have one installed. I'm just going through all my applications and seeing if there's anything that could interfere. I've just got rid of Virtualbox. I'm wondering if Steam is the culprit as it has it's own means for making the PS4 controller work with games that don't support it natively.

slietar commented 7 years ago

Hi, same issue here :( I am running macOS 10.12.5 and Python 2.7.13.

The examples work for ~1 minute and then crash with the same error Iterate: 38 0 2C7. When running ioreg I each time get exactly 1019 lines with it_unbit_foohid_userclient. I tried reinstalling the kext and rebooting multiple times but it didn't help.

Is there anything I can do to help or try to fix the problem ?

pavlrd commented 6 years ago

hey, same issue as well! Tried to reinstall kext kernell multiple times, used both versions of it: 0.1, and 0.2.1, no luck. Keeps terminating. it_unbit_foohid_userclient piling up when checking ioreg

Are you going to do anything about it?

There is a waiting PR for foohid driver, which might solve the issue