• AVR Freaks

PIC18F4550 + libusb + MAC OS X

Author
vw_seb
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2006/12/20 07:36:14
  • Location: 0
  • Status: offline
2009/04/24 00:38:17 (permalink)
0

PIC18F4550 + libusb + MAC OS X

HI,

I am trying to develop an USB HID Board and communicate with it on MAC OS X with the libusb library.
My board work perfectly with the MCHID.DLL on windows.
I have start my project on this example (http://www.roboticus.org/index.php/carte-dinterface-sur-port-usb-protocole-hid-part-2.html)
I have do a simple program in C to send data to the board but when I do a usb_claim_interface I got an error (Claim Failed) and I can't send data to my board.

I have do a lot off search on web since 1 month and I the result is bad.

Can you help or send me a simple program in C for mac os and the program for the PIC18F4550

I thanks you for all help that you can give me.

Good day.

I post you my code in C :


#include <stdio.h>
#include <usb.h>


int main(void)
{
    struct usb_bus *bus;
    struct usb_device *dev;
    int i;

    i = 0;

    usb_init();

    usb_find_busses();
    usb_find_devices();

    printf("Detection of the board :\n\r");
    for (bus = usb_busses; bus; bus = bus->next)
    {
        for (dev = bus->devices; dev; dev = dev->next)
        {
            usb_dev_handle *udev;
  
            if ((dev->descriptor.idVendor == 0x04D8) && (dev->descriptor.idProduct == 0x0005))
            {
                printf("Board is found\n\r");
       
                udev = usb_open(dev);
                if (udev)
                {
                    if (usb_set_configuration(udev, 1))
                    {
                        printf("Configuration failed\n\r");
                    }
           
                    if (usb_claim_interface(udev, 0))
                    {
                        Printf("Claim failed\n\r");
                    }
               
                    usb_bulk_write(udev, 1, "N", 1, 1000);
                   
                    usb_close(udev);
                }

            }

        }
    }
}

#1

7 Replies Related Threads

    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/04/24 01:59:21 (permalink)
    0
    MacOS X has in-box HID class driver, and default kext (kernel extension, like Windows default INF) for HID. If you don't specify any kext for the device, the HID device is caught by this in-box class driver.

    To assign the device to libusb escaping from the class driver, a codeless kext is often used for this purpose.
    For the details of the example of such codeless kext, visit this post.

    http://osdir.com/ml/lib.libusb.devel.general/2007-01/msg00058.html


    Of course, you can use the in-box HID class driver, instead of libusb.

    Introduction to Working With HID Class Device Interfaces
    http://developer.apple.com/documentation/DeviceDrivers/Conceptual/HID/intro/intro.html

    Leopard Sample Code: Games: Human Interface Device & Force Feedback
    http://developer.apple.com/samplecode/Games/idxHumanInterfaceDeviceForceFeedback-date.html

    Tsuneo
    post edited by chinzei - 2009/04/24 02:29:31
    #2
    vw_seb
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2006/12/20 07:36:14
    • Location: 0
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/04/30 12:29:21 (permalink)
    0
    Hi I thanks you for your help but I can't communicate with my board and Claim it.

    Have you got an idea.

    I thanks for all help

    Good day

    Sébastien
    #3
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/04/30 18:00:39 (permalink)
    0
    Have you tried Tsuneo's first method? You need to use a codeless kext. Please follow the method in the link he provided and then report back.

      USB_Links and libusb
    #4
    vw_seb
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2006/12/20 07:36:14
    • Location: 0
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/05/04 05:50:49 (permalink)
    0
    HI,

    Yes I have tried the first solution with a kext but I can't communicate with my board.

    Have got a simple example of MPLAB PIC Program and C programm for MAC OS to illustrate the communcation.

    I'll be crazy with this communication because I'm trying it since 2 months and I can't do it ...

    Thanks you
    #5
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/05/04 06:11:14 (permalink)
    0
    pk2cmd (for PICkit 2) is working for Mac OS X as well. But it is not that simple. It does not use libusb for Mac OS X, but use the native HID API under Mac OS X. It uses libusb for Linux only.

    http://www.microchip.com/pickit2

    But the kext method should work fine. You may want to ask in Apple forum.

      USB_Links and libusb
    #6
    vw_seb
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2006/12/20 07:36:14
    • Location: 0
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/05/04 06:41:13 (permalink)
    0
    I have recently view this project.
    I'm going to try with the HID API instead of libusb ...
    If the result is bad I'll switch to windows (but I don't like it) ...


    Thanks you
    #7
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: PIC18F4550 + libusb + MAC OS X 2009/05/04 06:57:31 (permalink)
    0
    Windows is still the best platform for PIC development. You can install Windows in you Mac with Bootcamp or Parallel or similar.
     
    I use Linux a lot at home but I still use Windows as my main OS when dealing with PIC.

      USB_Links and libusb
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5