Development based on the LIBHID/LIBUSB

Source: Internet
Author: User

Operating environment: Ubuntu, based on LIBHID/LIBUSB for development Libusb Introduction:

Libusb designed a series of external APIs to be called by the application, which can manipulate the hardware through these API applications, as seen from the source code of LIBUSB, which call the kernel's underlying interface (IOCTL), and kernel The functions used in driver are similar in function, just libusb closer to the USB specification. This makes the use of libusb much easier than developing kernel drivers. See http://www.libusb.org/for related information. Chinese information see Baidu Encyclopedia Libusb.

Libhid Introduction Libhid is a layer of API on the basis of LIBUSB, simplifying the data operation, make the HID device read and write more convenient, but also closer to PC-side programming habits. SOURCE HTTP://LIBHID.ALIOTH.DEBIAN.ORG/1.LIBUSB Operating Procedure Introduction 1.1. Initialization struct Usb_bus *bus;struct Usb_device *dev; usb_init (); usb_find_busses (); usb_find_devices ();

1.2. Locate the device

for (bus = busses; bus; bus = bus->next)

{

for (dev = bus->devices; dev; dev = dev->next)

{

if (dev->descriptor.idvendor==vendor_id&& dev->descriptor.idproduct = = PRODUCT_ID)

{

Find Device

Break

}

}

}

1.3. Turn on the device dev_handle = Usb_open (dev);//Turn on the device usb_set_configuration (Dev_handle, bconfiguretype);//Set device config type usb_claim_interface (dev_handle, 0);//Register interface with operating system communication Note: Usb_claim_interfaceFailure 1) Symptom 1: function return value =-1, get usb_strerror, for operation not permitted reason: The application does not have write permission to the/DEV/MNT/USB directory. Workaround: One method is root login, the other is "chmod o+w-r/dev/bus/usb into/etc/init.d/rc shell script" 2) Phenomenon 2: function returns-2, error message "USB Error:could not The parameters in claim interface 0:no such file or directory "Usb_set_configuration must be consistent with the Bconfiguretype in the control descriptor 1.4. Get Report Descriptor usb_control_msg (Dev_handle, usb_endpoint_in+1, Usb_req_get_descriptor, (Usb_dt_report << 8) + 0, Hidif->interface, (char*) Hidif->hid_parser->reportdesc, Hidif->hid_parser->reportdescsize, usb_timeout);The report descriptor gets reportsize 1.5. Set/Get HID Report //get_input_report len = usb_control_msg (Dev_handle,usb_endpoint_in + Usb_type_class + usb_recip_interface, Hid_report_get, Hidif->hid_data->reportid + (HID_R T_input << 8), hidif->interface, buffer, reprotsize, usb_timeout);//set output report int len = Usb_con Trol_msg (Hidif->dev_handle, usb_endpoint_out + Usb_type_class + usb_recip_interface, HID_REPORT_SET, HID If->hid_data->reportid + (Hid_rt_output << 8), Hidif->interface, (char*) buffer, reprotsize, USB_T Imeout); 1.6. Turn off the device usb_release_interfaces Usb_close1.7. Debug Lib_usb_setdebug Usb_strerror  2.libhid interface using Instructions 2.1 initialization Hid_init()//with 1.1 Hid_new_hidinterface, prepare the structure memory2.2 Find the device and turn on the device to register the communication interface Hid_force_open ();//with 1.2,1.3,1.42.3 report operation Hid_get_input_report //with 1.5 hid_set_output_report //with 1.5 2.4 Debug Hid_set_debug (hid_debug_all); hid_set_usb_debug (0);

Development based on the LIBHID/LIBUSB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.