[libhid-discuss] cannat find path to read and write
Charles Lepple
clepple at ghz.cc
Sat Sep 5 13:48:31 UTC 2009
Please send libhid-related questions to the mailing list. The list is
CC'd.
On Sep 5, 2009, at 5:16 AM, Sajjad Gerami wrote:
> hi
>
> another problem .
> i try to enumerate my usb devices but i encouterd a problem
>
> --------------------------------------------
> here's the code :
>
> #include <hid.h>
> #include <stdio.h>
> #include <string.h>
>
> char *hid_id[32]; /* FIXME: 32 devices MAX */
>
> struct usb_dev_handle;
>
> bool device_iterator (struct usb_dev_handle const* usbdev, void*
> custom,
> unsigned int len)
> {
> bool ret = false;
> int i;
> char current_dev_path[10];
> const struct usb_device *device = usb_device((struct usb_dev_handle
> *)usbdev);
>
> /* only here to prevent the unused warning */
> /* TODO remove */
> len = *((unsigned long*)custom);
>
> /* Obtain the device's full path */
> //sprintf(current_dev_path, "%s/%s", usbdev->bus->dirname,
> usbdev->device->filename);
> sprintf(current_dev_path, "%s/%s", device->bus->dirname,
> device->filename);
>
> /* Check if we already saw this dev */
> for ( i = 0 ; ( hid_id[i] != NULL ) ; i++ )
> {
> if (!strcmp(hid_id[i], current_dev_path ) )
> break;
> }
>
> /* Append device to the list if needed */
> if (hid_id[i] == NULL)
> {
> hid_id[i] = (char *) malloc (strlen(device->filename) +
> strlen(device->bus->dirname) );
> sprintf(hid_id[i], "%s/%s", device->bus->dirname, device-
> >filename);
> }
> else /* device already seen */
> {
> return false;
> }
>
> /* Filter non HID device */
> if ( (device->descriptor.bDeviceClass == 0) /* Class defined at
> interface level */
> && device->config
> && device->config->interface->altsetting->bInterfaceClass ==
> USB_CLASS_HID)
> ret = true;
> else
> ret = false;
>
> return ret;
> }
>
> int main(void)
> {
> int i;
> hid_return ret;
> HIDInterface* hid;
> HIDInterfaceMatcher matcher;
>
> /* hid_write_library_config(stdout); */
>
> /* hid_set_debug(HID_DEBUG_NOTRACES); */
> // hid_set_debug(HID_DEBUG_NONE);
> hid_set_debug(HID_DEBUG_ALL);
> hid_set_debug_stream(stderr);
> hid_set_usb_debug(0);
>
> /* data init */
> for (i = 0 ; i < 32 ; i++)
> hid_id[i] = NULL;
>
>
>
> ret = hid_init();
>
>
> hid = hid_new_HIDInterface();
>
> /* //tested - not working
> matcher.vendor_id = HID_ID_MATCH_ANY;
> matcher.product_id = HID_ID_MATCH_ANY;
> matcher.matcher_fn = device_iterator;
> */
>
> matcher.vendor_id = 0x1114;
> matcher.product_id = 0x1028;
> matcher.matcher_fn = device_iterator;
> // matcher.matcher_fn = NULL; //WARNNING : infinity loop
>
> /* open recursively all HID devices found */
> while ( (ret = hid_force_open(hid, 0, &matcher, 3)) !=
> HID_RET_DEVICE_NOT_FOUND)//Segmentation fault accures here!!!
> {
>
> printf
> ("************************************************************************\n
> ");
>
> hid_write_identification(stdout, hid);
>
> /* Only dump HID tree if asked */
> /* hid_dump_tree(stdout, hid); */
>
> hid_close(hid);
> }
>
> hid_delete_HIDInterface(&hid);
> ret = hid_cleanup();
>
> return 0;
> }
>
> /* COPYRIGHT --
> *
> * This file is part of libhid, a user-space HID access library.
> * libhid is (c) 2003-2005
> * Martin F. Krafft <libhid at pobox.madduck.net>
> * Charles Lepple <clepple at ghz.cc>
> * Arnaud Quette <arnaud.quette at free.fr> &&
> <arnaud.quette at mgeups.com>
> * and distributed under the terms of the GNU General Public License.
> * See the file ./COPYING in the source distribution for more
> information.
> *
> * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
> * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
> * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
> */
>
> --------------------------------------------
> and here's the output :
>
> root at sajjad-laptop:/home/sajjad/NetBeansProjects/libhid1/dist/Debug/
> GNU-Linux-x86# ./libhid1
> NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.
> TRACE: hid_init(): initialising USB subsystem...
> TRACE: hid_init(): scanning for USB busses...
> TRACE: hid_init(): scanning for USB devices...
> NOTICE: hid_init(): successfully initialised HID library.
> TRACE: hid_new_HIDInterface(): creating a new HIDInterface
> instance...
> TRACE: hid_force_open(): forcefully opening a device interface
> according to matching criteria...
> TRACE: hid_get_usb_handle(): acquiring handle for a USB device...
> TRACE: hid_find_usb_device(): enumerating USB busses...
> TRACE: hid_find_usb_device(): enumerating USB devices on bus 001...
> TRACE: hid_find_usb_device(): inspecting USB device 001/001[0]...
> TRACE: hid_compare_usb_device(): comparing match specifications to
> USB
> device...
> TRACE: hid_compare_usb_device(): inspecting vendor ID...
> TRACE: hid_compare_usb_device(): no match on vendor ID.
> TRACE: hid_compare_usb_device(): inspecting product ID...
> TRACE: hid_compare_usb_device(): no match on product ID.
> TRACE: hid_compare_usb_device(): calling custom matching function...
> Segmentation fault
> root at sajjad-laptop:/home/sajjad/NetBeansProjects/libhid1/dist/Debug/
> GNU-Linux-x86#
> --------------------------------------------
>
> Segmentation fault ????!!!??!?!?!?!?
A debugger is very helpful if you get a segmentation fault.
> and when i changed
> matcher.matcher_fn = device_iterator;
> to
> matcher.matcher_fn = NULL;
> it fall in the loop and check the same 1st find matching bus again and
> again.
>
> custom matching function !!!!????
> what is this ?
> i search in libhid documentation but i found nothing
> even in libhid codes again nothing
> then discuss list , nothing relative
Look again.
>
> thanks for helping.
> god bless you.
> --
> Sajjad Gerami <myworkmail2010 at gmail.com>
>
More information about the libhid-discuss
mailing list