<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/8113" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2012-12-29T16:13:36+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/8113</id>

		<entry>
		<author><name><![CDATA[declan smith]]></name></author>
		<updated>2012-12-29T16:13:36+02:00</updated>

		<published>2012-12-29T16:13:36+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24382#p24382</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24382#p24382"/>
		<title type="html"><![CDATA[Re: v-usb + hidapi]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24382#p24382"><![CDATA[
Try to change:<br />unsigned char buf[9];<br /> <br />to:<br />unsigned char buf[8];<br /><br /><span style="text-decoration: underline">Editted</span>:<br /><br />because you &quot; return 8 &quot; in the device side while  ' res = hid_read(handle, buf, sizeof(buf))'   will return &quot; sizeof(buf) &quot;  which is also 8, so the &quot; res &quot; will return negatif value as I knew.<br /><br />Add your code to show the return value with the printf, so you can be sure what value was returned. <br /><br />Hope it's right.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=7773">declan smith</a> — Sat Dec 29, 2012 4:13 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[SpulN]]></name></author>
		<updated>2012-12-29T07:32:02+02:00</updated>

		<published>2012-12-29T07:32:02+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24368#p24368</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24368#p24368"/>
		<title type="html"><![CDATA[Re: v-usb + hidapi]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24368#p24368"><![CDATA[
May be same thing wrong with HIDAPI hid_read() function? Why it did't receve data from device?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=18473">SpulN</a> — Sat Dec 29, 2012 7:32 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[declan smith]]></name></author>
		<updated>2012-12-29T05:17:56+02:00</updated>

		<published>2012-12-29T05:17:56+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24366#p24366</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24366#p24366"/>
		<title type="html"><![CDATA[Re: v-usb + hidapi]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24366#p24366"><![CDATA[
There's nothing wrong with your code as I tested it.<br /><br />Here's your code with little mod for my test ( you set the report out but you didn't use it ? ) :<br /><br /><div class="codebox"><p>Code: </p><pre><code>/* Name: main.c<br /> * Project: hid-data, example how to use HID for data transfer<br /> * Author: Christian Starkjohann<br /> * Creation Date: 2008-04-11<br /> * Tabsize: 4<br /> * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH<br /> * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)<br /> */<br /><br />/*<br />This example should run on most AVRs with only little changes. No special<br />hardware resources except INT0 are used. You may have to change usbconfig.h for<br />different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or<br />at least be connected to INT0 as well.<br />*/<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/interrupt.h&gt;  /* for sei() */<br />#include &lt;util/delay.h&gt;     /* for _delay_ms() */<br />#include &lt;avr/eeprom.h&gt;<br /><br />#include &lt;avr/pgmspace.h&gt;   /* required by usbdrv.h */<br />#include &quot;usbdrv.h&quot;<br />#include &quot;oddebug.h&quot;        /* This is also an example for using debug macros */<br /><br />static uint8_t buffer&#91;16&#93;;<br /><br />/* ------------------------------------------------------------------------- */<br />/* ----------------------------- USB interface ----------------------------- */<br />/* ------------------------------------------------------------------------- */<br /><br />PROGMEM const char usbHidReportDescriptor&#91;32&#93; = {    /* USB report descriptor */<br />        0x06, 0x9c, 0xff,     /* Usage Page (Vendor Defined)                     */<br />        0x09, 0x01,           /* Usage (Vendor Defined)                          */<br />        0xa1, 0x01,           /* Collection (Vendor Defined)                     */<br />        0x09, 0x02,           /*   Usage (Vendor Defined)                        */<br />        0x75, 0x08,           /*   Report Size (8)                               */<br />        0x95, 0x08,           /*   Report Count (8)       */<br />        0x15, 0x80,           /*   Logical Minimum (-128)                        */<br />        0x25, 0x7F,           /*   Logical Maximum (127)                         */<br />        0x81, 0x02,           /*   Input (Data, Variable, Absolute)              */<br />        0x09, 0x03,           /*   Usage (Vendor Defined)                        */<br />        0x75, 0x08,           /*   Report Size (8)                               */<br />        0x95, 0x08,           /*   Report Count (8)       */<br />        0x15, 0x00,           /*   Logical Minimum (0)                           */<br />        0x25, 0xff,           /*   Logical Maximum (255)                         */<br />        0x91, 0x02,           /*   Output (Data, Variable, Absolute)             */<br />        0xc0                  /* End Collection                                  */<br /><br />};<br />/* Since we define only one feature report, we don't use report-IDs (which<br /> * would be the first byte of the report). The entire report consists of 128<br /> * opaque data bytes.<br /> */<br /><br /><br />/* ------------------------------------------------------------------------- */<br /><br />/* usbFunctionRead() is called when the host requests a chunk of data from<br /> * the device. For more information see the documentation in usbdrv/usbdrv.h.<br /> */<br />uchar   usbFunctionRead(uchar *data, uchar len)<br />{<br />    uint8_t i;<br /><br />   for (i=0;i&lt;len;++i) data&#91;i&#93;=buffer&#91;i&#93;;<br /><br />   return len;<br />}<br /><br />/* usbFunctionWrite() is called when the host sends a chunk of data to the<br /> * device. For more information see the documentation in usbdrv/usbdrv.h.<br /> */<br />uchar   usbFunctionWrite(uchar *data, uchar len)<br />{<br />    uint8_t i;<br /><br />   for (i=0;i&lt;len;++i) buffer&#91;i&#93;=data&#91;i&#93;;<br />      <br />   return 1;               /* end of transfer */<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br />usbMsgLen_t usbFunctionSetup(uchar data&#91;8&#93;)<br />{<br />usbRequest_t    *rq = (void *)data;<br /><br />    if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* HID class request */<br />        if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */<br />            /* since we have only one report type, we can ignore the report-ID */<br />            return USB_NO_MSG;  /* use usbFunctionRead() to obtain data */<br />        }else if(rq-&gt;bRequest == USBRQ_HID_SET_REPORT){<br />            /* since we have only one report type, we can ignore the report-ID */<br />            return USB_NO_MSG;  /* use usbFunctionWrite() to receive data from host */<br />        }<br />    }else{<br />        /* ignore vendor type requests, we don't use any */<br />    }<br />    return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br />int main(void)<br />{<br />uchar   i;<br /><br />    wdt_enable(WDTO_1S);<br />    /* Even if you don't use the watchdog, turn it off here. On newer devices,<br />     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!<br />     */<br />    /* RESET status: all port bits are inputs without pull-up.<br />     * That's the way we need D+ and D-. Therefore we don't need any<br />     * additional hardware initialization.<br />     */<br />    odDebugInit();<br />    DBG1(0x00, 0, 0);       /* debug output: main starts */<br />    usbInit();<br />    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />    usbDeviceConnect();<br />    sei();<br />    DBG1(0x01, 0, 0);       /* debug output: main loop starts */<br />    for(;;){                /* main event loop */<br />        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */<br />        wdt_reset();<br />        usbPoll();<br />    }<br />    return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /></code></pre></div><br /><br />And here's my test result:<br />The first read was when the device attach for the first time, so it read all zero,<br />the second read was from the data bytes inputted randomly,<br />the last read was data bytes send from static buffer.<br />So I tought your code was alright ( not sure about your usbconfig ). Maybe the host side ?<br /><br /><img src="http://i476.photobucket.com/albums/rr124/jfet_ping/Microcontroller/v-usbhost003_zps27b0e7e4.jpg" class="postimage" alt="Image" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=7773">declan smith</a> — Sat Dec 29, 2012 5:17 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[SpulN]]></name></author>
		<updated>2012-12-28T20:18:46+02:00</updated>

		<published>2012-12-28T20:18:46+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24356#p24356</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24356#p24356"/>
		<title type="html"><![CDATA[v-usb + hidapi]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8113&amp;p=24356#p24356"><![CDATA[
Hi, all! Sorry for my english!<br />I have a problem. I can't read input report from hid device. I take hid-test example project as a base. This is a code for PC (hidapi library, hidtest.cpp)<br /><div class="codebox"><p>Code: </p><pre><code>/*******************************************************<br /> Windows HID simplification<br /><br /> Alan Ott<br /> Signal 11 Software<br /><br /> 8/22/2009<br /><br /> Copyright 2009, All Rights Reserved.<br /> <br /> This contents of this file may be used by anyone<br /> for any reason without any conditions and may be<br /> used as a starting point for your own applications<br /> which use HIDAPI.<br />********************************************************/<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;wchar.h&gt;<br />#include &lt;string.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &quot;hidapi.h&quot;<br />#include &lt;windows.h&gt;<br /><br />int main(int argc, char* argv&#91;&#93;)<br />{<br />   int res;<br />   unsigned char buf&#91;9&#93;;<br />   hid_device *handle;<br />   int i;<br /><br />#ifdef WIN32<br />   UNREFERENCED_PARAMETER(argc);<br />   UNREFERENCED_PARAMETER(argv);<br />#endif<br /><br />   handle = hid_open(0x16c0, 0x05df, NULL);<br />   if (!handle) {<br />      printf(&quot;unable to open device\n&quot;);<br />       return 1;<br />   }<br /><br />   hid_set_nonblocking(handle, 1);<br />   <br />   res = 0;<br />   while (res == 0) {<br />      res = hid_read(handle, buf, sizeof(buf));<br />      if (res == 0)<br />         printf(&quot;waiting...\n&quot;);<br />      if (res &lt; 0)<br />         printf(&quot;Unable to read()\n&quot;);<br />      Sleep(1000);<br />   }<br /><br />   printf(&quot;Data read:\n   &quot;);<br />   // Print out the returned buffer.<br />   for (i = 0; i &lt; res; i++)<br />      printf(&quot;%02hhx &quot;, buf&#91;i&#93;);<br />   printf(&quot;\n&quot;);<br /><br />   hid_close(handle);<br /><br />   /* Free static HIDAPI objects. */<br />   hid_exit();<br /><br />   system(&quot;pause&quot;);<br />   return 0;<br />}<br /></code></pre></div><br />this is code for avr (mega8)<br /><div class="codebox"><p>Code: </p><pre><code>/* Name: main.c<br /> * Project: hid-data, example how to use HID for data transfer<br /> * Author: Christian Starkjohann<br /> * Creation Date: 2008-04-11<br /> * Tabsize: 4<br /> * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH<br /> * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)<br /> */<br /><br />/*<br />This example should run on most AVRs with only little changes. No special<br />hardware resources except INT0 are used. You may have to change usbconfig.h for<br />different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or<br />at least be connected to INT0 as well.<br />*/<br /><br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/interrupt.h&gt;  /* for sei() */<br />#include &lt;util/delay.h&gt;     /* for _delay_ms() */<br />#include &lt;avr/eeprom.h&gt;<br /><br />#include &lt;avr/pgmspace.h&gt;   /* required by usbdrv.h */<br />#include &quot;usbdrv.h&quot;<br />#include &quot;oddebug.h&quot;        /* This is also an example for using debug macros */<br /><br />/* ------------------------------------------------------------------------- */<br />/* ----------------------------- USB interface ----------------------------- */<br />/* ------------------------------------------------------------------------- */<br /><br />PROGMEM const char usbHidReportDescriptor&#91;32&#93; = {    /* USB report descriptor */<br />        0x06, 0x9c, 0xff,     /* Usage Page (Vendor Defined)                     */<br />        0x09, 0x01,           /* Usage (Vendor Defined)                          */<br />        0xa1, 0x01,           /* Collection (Vendor Defined)                     */<br />        0x09, 0x02,           /*   Usage (Vendor Defined)                        */<br />        0x75, 0x08,           /*   Report Size (8)                               */<br />        0x95, 0x08,           /*   Report Count (8)       */<br />        0x15, 0x80,           /*   Logical Minimum (-128)                        */<br />        0x25, 0x7F,           /*   Logical Maximum (127)                         */<br />        0x81, 0x02,           /*   Input (Data, Variable, Absolute)              */<br />        0x09, 0x03,           /*   Usage (Vendor Defined)                        */<br />        0x75, 0x08,           /*   Report Size (8)                               */<br />        0x95, 0x08,           /*   Report Count (8)       */<br />        0x15, 0x00,           /*   Logical Minimum (0)                           */<br />        0x25, 0xff,           /*   Logical Maximum (255)                         */<br />        0x91, 0x02,           /*   Output (Data, Variable, Absolute)             */<br />        0xc0                  /* End Collection                                  */<br /><br />};<br />/* Since we define only one feature report, we don't use report-IDs (which<br /> * would be the first byte of the report). The entire report consists of 128<br /> * opaque data bytes.<br /> */<br /><br /><br />/* ------------------------------------------------------------------------- */<br /><br />/* usbFunctionRead() is called when the host requests a chunk of data from<br /> * the device. For more information see the documentation in usbdrv/usbdrv.h.<br /> */<br />uchar   usbFunctionRead(uchar *data, uchar len)<br />{<br />    data&#91;1&#93; = 0x01;<br />    data&#91;2&#93; = 0x02;<br />    data&#91;3&#93; = 0x03;<br />    data&#91;4&#93; = 0x04;<br />    return 8;<br />}<br /><br />/* usbFunctionWrite() is called when the host sends a chunk of data to the<br /> * device. For more information see the documentation in usbdrv/usbdrv.h.<br /> */<br />uchar   usbFunctionWrite(uchar *data, uchar len)<br />{<br />    return 1;               /* end of transfer */<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br />usbMsgLen_t usbFunctionSetup(uchar data&#91;8&#93;)<br />{<br />usbRequest_t    *rq = (void *)data;<br /><br />    if((rq-&gt;bmRequestType &amp; USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* HID class request */<br />        if(rq-&gt;bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */<br />            /* since we have only one report type, we can ignore the report-ID */<br />            return USB_NO_MSG;  /* use usbFunctionRead() to obtain data */<br />        }else if(rq-&gt;bRequest == USBRQ_HID_SET_REPORT){<br />            /* since we have only one report type, we can ignore the report-ID */<br />            return USB_NO_MSG;  /* use usbFunctionWrite() to receive data from host */<br />        }<br />    }else{<br />        /* ignore vendor type requests, we don't use any */<br />    }<br />    return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br />int main(void)<br />{<br />uchar   i;<br /><br />    wdt_enable(WDTO_1S);<br />    /* Even if you don't use the watchdog, turn it off here. On newer devices,<br />     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!<br />     */<br />    /* RESET status: all port bits are inputs without pull-up.<br />     * That's the way we need D+ and D-. Therefore we don't need any<br />     * additional hardware initialization.<br />     */<br />    odDebugInit();<br />    DBG1(0x00, 0, 0);       /* debug output: main starts */<br />    usbInit();<br />    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />    usbDeviceConnect();<br />    sei();<br />    DBG1(0x01, 0, 0);       /* debug output: main loop starts */<br />    for(;;){                /* main event loop */<br />        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */<br />        wdt_reset();<br />        usbPoll();<br />    }<br />    return 0;<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /></code></pre></div><br />but when I run program from PC, the program write in console: waiting..., no data read from devace.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=18473">SpulN</a> — Fri Dec 28, 2012 8:18 pm</p><hr />
]]></content>
	</entry>
	</feed>
