----------  Weitergeleitete Nachricht  ----------

Subject: Fwd: Recieving data from HID with libhid (wrong attachment)
Date: Freitag, 4. November 2005 16:05
From: "Obrist Günther (AUT Wien Entwicklung)" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]

Hi, it s me again, my output attachment was the wrong one...)
Could you tell me please what this error message means and why it occurs?

requested: 12 bytes, got: 1 bytes
hid_get_input_report failed with return code 20

What have I to change in my program (see attachment)? Do you have some tips
for me or for what I have to look for?

Greetings

-------------------------------------------------------

--
Günther Obrist
[EMAIL PROTECTED]
Moeller Gebäudeautomation KG
Scheydgasse 42, 1215 Wien
AUT Entwicklung Wien

-------------------------------------------------------

-- 
Günther Obrist
[EMAIL PROTECTED]
Moeller Gebäudeautomation KG
Scheydgasse 42, 1215 Wien
AUT Entwicklung Wien

#include <hid.h>
#include <stdio.h>
#include <string.h>



bool match_serial_number(struct usb_dev_handle* usbdev, void* custom, 
unsigned int len)
{
  	bool ret;
  	char* buffer = (char*)malloc(len);
  	usb_get_string_simple(usbdev, 
	usb_device(usbdev)->descriptor.iSerialNumber, buffer, len);
  	ret = strncmp(buffer, (char*)custom, len) == 0;
  	free(buffer);
  	return ret;
}

//*****************************************************************
//***************          Funktion        ************************
//*****************************************************************

int gethexvalue(char tok)
{
	int ret = 0;
	if(tok >= '0' && tok <= '9')
		return (int)tok - '0';
	else if(tok >= 'A' && tok <= 'F')
		return (int)tok - 'A'+ 10; 
	else if(tok >= 'a' && tok <= 'f')
		return (int)tok - 'a'+ 10;
	else return -1;
}

//*****************************************************************
//***************          MAIN            ************************
//*****************************************************************

int main(int argc, char *argv[])
{
	int   i, strent, value_length, shiftval;
	unsigned long bitvalue = 0; 
	char *argvwert;
	char feld[5];
	char PACKET[5];
	#define PATHLEN 3
  	int const PATH_IN[] = { 0xffa00001, 0xffa00002, 0xffa10003 };
   	int const PATH_OUT[] = { 0xffa00001, 0xffa00002, 0xffa10005 };
	

	HIDInterface* hid;
 	hid_return ret;

	
	for(i = 1; i < argc; i++) {
		argvwert = argv[i];
		value_length = strlen(argvwert); 	//Ermittlung der Länge eines Strings
		if(value_length <= 8) { 		// 32 bit Wert
			for(strent = 0; strent < value_length; strent++) {
 				 shiftval = gethexvalue(argvwert[strent]);	
				 if(shiftval < 0) return 0;
				 bitvalue |= shiftval << (((value_length - strent - 1)) * 4); 
				 shiftval = 0;
			}
		}
		PACKET[i-1] = bitvalue;
	        //printf(" %d %X\n", bitvalue, bitvalue);//Edit
                bitvalue = 0;
        }

	for(i=0;i<sizeof(feld);i++)
		printf("Wert 1: %x-12\n", feld[i]);
	

  

  	HIDInterfaceMatcher matcher = { 0x03eb, 0x0001, NULL, NULL, 0 };

  	/* see include/debug.h for possible values */
  	hid_set_debug(HID_DEBUG_ALL);
  	hid_set_debug_stream(stderr);
  	/* passed directly to libusb */
  	hid_set_usb_debug(0);
  
  	ret = hid_init();
  	if (ret != HID_RET_SUCCESS) {
    		fprintf(stderr, "hid_init failed with return code %d\n", ret);
    		return 1;
  	}

  	hid = hid_new_HIDInterface();
  	if (hid == 0) {
    		fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
    		return 1;
  	}

  

  	ret = hid_force_open(hid, 0, &matcher, 3);
  	if (ret != HID_RET_SUCCESS) {
    		fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
    		return 1;
  	}

  	ret = hid_write_identification(stdout, hid);
  	if (ret != HID_RET_SUCCESS) {
    		fprintf(stderr, "hid_write_identification failed with return code %d\n", ret);
    		return 1;
  	}

  	ret = hid_dump_tree(stdout, hid);
  	if (ret != HID_RET_SUCCESS) {
    		fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);
    		return 1;
  	}

//*********************************************  
//*****************SEND************************
//********************************************

   	unsigned char const SEND_PACKET_LEN = 5;
   
   	// fill an example packet:	

   	ret = hid_set_output_report(hid, PATH_OUT, PATHLEN, PACKET, SEND_PACKET_LEN);
   	if (ret != HID_RET_SUCCESS) {
     		fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret);
   	}

//*********************************************  
//*****************RECV************************
//********************************************
   
	unsigned char const RECV_PACKET_LEN = 12;
	printf("***************\n");
	printf("***RECIEVING***\n");
	printf("***************\n");
  	char packet[RECV_PACKET_LEN];
      	ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, packet, RECV_PACKET_LEN);
      	if (ret != HID_RET_SUCCESS) {
        	fprintf(stderr, "hid_get_input_report failed with return code %d\n", ret);
      	}
      	// now use the RECV_PACKET_LEN bytes starting at *packet.
   
   

  	ret = hid_close(hid);
  	if (ret != HID_RET_SUCCESS) {
    		fprintf(stderr, "hid_close failed with return code %d\n", ret);
    		return 1;
  	}

  	hid_delete_HIDInterface(&hid);

  	ret = hid_cleanup();
  	if (ret != HID_RET_SUCCESS) {
    		fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);
    		return 1;
  	}
  
  	return 0;
}
 

ewien-134:/home/ogu1234/test# ./librcv
Wert 1: 0-12
Wert 1: 0-12
Wert 1: 0-12
Wert 1: 0-12
Wert 1: ffffff84-12
  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 002...
  TRACE: hid_find_usb_device(): inspecting USB device 002/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(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x0000 of USB device 002/001[0] does not 
match 0x03eb.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 001...
  TRACE: hid_find_usb_device(): inspecting USB device 001/003[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(): match on vendor ID: 0x03eb.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): match on product ID: 0x0001.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): found a matching USB device 001/003[0].
  TRACE: hid_force_open(): claiming USB device 001/003[0].
 NOTICE: hid_force_open(): successfully claimed USB device 001/003[0].
  TRACE: hid_init_parser(): initialising the HID parser for USB Device 
001/003[0]...
  TRACE: hid_init_parser(): allocating space for HIDData structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDData strcture.
  TRACE: hid_init_parser(): allocating space for HIDParser structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDParser 
strcture.
 NOTICE: hid_init_parser(): successfully initialised the HID parser for USB 
Device 001/003[0].
  TRACE: hid_prepare_hid_descriptor(): initialising the HID descriptor for USB 
device 001/003[0]...
  TRACE: hid_prepare_hid_descriptor(): retrieving HID descriptor for USB device 
001/003[0]...
 NOTICE: hid_prepare_hid_descriptor(): successfully initialised HID descriptor 
for USB device 001/003[0].
  TRACE: hid_prepare_report_descriptor(): initialising the report descriptor 
for USB device 001/003[0]...
  TRACE: hid_prepare_report_descriptor(): retrieving report descriptor for USB 
device 001/003[0]...
 NOTICE: hid_prepare_report_descriptor(): successfully initialised report 
descriptor for USB device 001/003[0].
  TRACE: hid_prepare_parser(): setting up the HID parser for USB device 
001/003[0]...
  TRACE: hid_reset_parser(): resetting the HID parser for USB device 
001/003[0]...
  TRACE: hid_prepare_parser(): dumping the raw report descriptor
  TRACE: hid_prepare_parser(): 0x000: 0x06 0xa0 0xff 0x09 0x01 0xa1 0x01 0x09
  TRACE: hid_prepare_parser(): 0x008: 0x02 0xa1 0x00 0x06 0xa1 0xff 0x09 0x03
  TRACE: hid_prepare_parser(): 0x010: 0x09 0x04 0x15 0x00 0x25 0xff 0x35 0x00
  TRACE: hid_prepare_parser(): 0x018: 0x45 0xff 0x75 0x08 0x95 0x0b 0x81 0x02
  TRACE: hid_prepare_parser(): 0x020: 0x09 0x05 0x09 0x06 0x15 0x00 0x25 0xff
  TRACE: hid_prepare_parser(): 0x028: 0x35 0x00 0x45 0xff 0x75 0x08 0x95 0x05
  TRACE: hid_prepare_parser(): 0x030: 0x91 0x02 0xc0 0xc0
  TRACE: hid_prepare_parser(): parsing the HID tree of USB device 001/003[0]...
 NOTICE: hid_prepare_parser(): successfully set up the HID parser for USB 
device 001/003[0].
 NOTICE: hid_force_open(): successfully opened USB device 001/003[0].
device identification of HIDInterface 001/003[0]:
  dev_handle:    0x0804b0b8
  device:        0x08050148
  location:      001/003
  manufacturer:  MOELLER
  product:       MOELLER USB Gateway
  serial number: 1.0.0
  TRACE: hid_reset_parser(): resetting the HID parser for USB device 
001/003[0]...
  TRACE: hid_dump_tree(): iterating the parse tree for USB device 001/003[0]...
parse tree of HIDInterface 001/003[0]:
  path: 0xffa00001.0xffa00002.0xffa10003; type: 0x80
  path: 0xffa00001.0xffa00002.0xffa10004; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00002.0xffa10005; type: 0x90
  path: 0xffa00001.0xffa00002.0xffa10006; type: 0x90
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x90
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x90
  path: 0xffa00001.0xffa00002.0x00000000; type: 0x90
  TRACE: hid_reset_parser(): resetting the HID parser for USB device 
001/003[0]...
  TRACE: hid_set_output_report(): sending report to USB device 001/003[0]...
  TRACE: hid_prepare_parse_path(): preparing search path of depth 3 for parse 
tree of USB device 001/003[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for parse tree of USB 
device 001/003[0].
 NOTICE: hid_find_object(): found requested item.
 NOTICE: hid_set_output_report(): successfully sent report to USB device 
001/003[0].
***************
***RECIEVING***
***************
  TRACE: hid_get_input_report(): retrieving report from USB device 001/003[0]...
  TRACE: hid_prepare_parse_path(): preparing search path of depth 3 for parse 
tree of USB device 001/003[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for parse tree of USB 
device 001/003[0].
 NOTICE: hid_find_object(): found requested item.
WARNING: hid_get_input_report(): failed to retrieve complete report from USB 
device 001/003[0]; requested: 12 bytes, got: 1 bytes.
hid_get_input_report failed with return code 20
  TRACE: hid_close(): closing USB device 001/003[0]...
  TRACE: hid_close(): closing handle of USB device 001/003[0]...
 NOTICE: hid_close(): successfully closed USB device 001/003[0].
  TRACE: hid_reset_parser(): resetting the HID parser for USB device 
001/003[0]...
  TRACE: hid_close(): freeing memory allocated for HID parser...
  TRACE: hid_close(): resetting HIDInterface...
 NOTICE: hid_cleanup(): successfully deinitialised HID library.

Reply via email to