Find the answer to your Linux question:
Results 1 to 2 of 2
Using RH9, kernel 2.4.20-6 I need to send to and read from a USB device. So far, the hid driver seems to be the choice. The structure that I need ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2003
    Posts
    1

    Talking to a USB HID


    Using RH9, kernel 2.4.20-6

    I need to send to and read from a USB device. So far, the hid driver seems to be the choice.

    The structure that I need to send and read is:

    USHORT Buffer[9];

    I have obtained the file descriptor from:
    if ((fd=open("dev/usb/hiddev0", O_RDONLY)) < 0)
    { perror("hiddev open");
    exit(1);
    }

    I can get the report information from:

    struct hiddev_report_info
    { unsigned report_type;
    unsigned report_id;
    unsigned num_fields;
    }

    struct hiddev_usage_ref
    { unsigned report_type:
    unsigned report_id;
    unsigned field_index;
    unsigned usage_index;
    unsigned usage_code:
    _s32 value:
    }

    struct hiddev_usage_ref usage_ref;
    struct hiddev_report_info rep_info;

    --------
    calling ioctl(fd, HIDIOCGREPORTINFO, &rep_info)
    gives me rep_info.report_type = 1 (or 2 or 3)
    rep_info.id = 0
    rep_info.num_fields = 1

    How do I fill in the structures rep_info and usage_ref to handle the nine element buffer? I assume I use:

    ioctl(fd, HIDIOCSUSAGE, &usage_ref) and
    ioctl(fd, HIDIOCSREPORT, &rep_info)

    to send the buffer contents to the device, and

    ioctl(fd, HIDIOCGREPORT, rep_info)

    to read the device????????????

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Unfortunately, I haven't done any USB interface programming myself, but the experience that I have with USB-enabled code tells me that it might be easier to use libusb instead:
    http://libusb.sf.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •