Hi there, i'm a new user of libusb and i'm with a problem here.
Well, a need to add in my qt4 project (I working on a GIS application) a
realtime gps tracking tool, so, to do that i've downloaded the libusb and a
made a Qt4 project with libusb. The project compile well and i can get
informations about the usb devices connected on my computer. But when a try
do access my garmin Vista HCX (idVendor = 0x091e or 2334 and idProduct =
0x0003 or 3) i get the -12 error (LIBUSB_ERROR_NOT_SUPPORTED). How can i
make libusb open my garmin gps? One more thing, i need to make this work on
win32 and linux.

Here is my code to try to access my garmin...

int main(int argc, char *argv[])
{
    libusb_device **devs;
    libusb_context* ctx = NULL;
    int r;
    ssize_t cnt;

    r = libusb_init(&ctx);
    if (r < 0)
    {
        qDebug("Init error: %d", r);
        return 1;
    }
    libusb_set_debug(ctx, 3);

    cnt = libusb_get_device_list(ctx, &devs);
    if (cnt < 0)
    {
        qDebug("Device error");
        return (int) cnt;
    }

    open_dev(ctx); Here i try to access my garmin device...

    for(int i = 0; i < cnt; i++)
    {
        print_dev(devs[i], ctx);
    }

    libusb_free_device_list(devs, 1);

    libusb_exit(ctx);

    QApplication a(argc, argv);
    MainWindow w;

    w.show();
    return a.exec();
}

static void open_dev(libusb_context* ctx)
{
    libusb_device_handle *dev_handle = libusb_open_device_with_vid_pid(ctx,
0x091e, 0x0003);
    if(!dev_handle)
    {
        qDebug("Cannot open device");
        return;
    }
    else
    {
        qDebug("Device opened");
    }

    unsigned char *data = new unsigned char[4];
    int actual;
    if(libusb_kernel_driver_active(dev_handle, 0) == 1)
    {
        qDebug("Kernel Driver Active");
        if(libusb_detach_kernel_driver(dev_handle, 0) == 0)
            qDebug("Kernel Driver Detached!");
    }

    int r = libusb_claim_interface(dev_handle, 0);
    if(r < 0)
        qDebug("Cannot claim device");

    qDebug("Device claimed");
    qDebug("data-> %s", data);

    qDebug("Reading data...");
    r = libusb_bulk_transfer(dev_handle, (3 | LIBUSB_ENDPOINT_IN), data, 4,
&actual, 0);
    if(r == 0 && actual == 4)
        qDebug("Reading Successful");
    else
        qDebug("Read error");

    r = libusb_release_interface(dev_handle, 0);
    if(r != 0)
        qDebug("Cannot release interface");
    qDebug("Interface released");

    libusb_close(dev_handle);
    delete[] data;
}

I'm a cartographic engineer and i never worked in a lower level c
programming. So i'm getting a little trouble to do this tracking tool.

Can someone help me please?

About the need of work on linux and windows. It's possible to do that
(access my garmin device) without installing libusb on the OS? I mean, i
wanna use my .pro with the libusb code to do that. I don't want my program
users to install any dependences to use my program.

Best regards and thanks in advance!!!
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to