<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67629/how-do-i-know-the-length-of-receive-data-on-the-usb-hid</link><description>Hi, 
 
 I am trying to receive data using USB Custom HID. 
 Data reception is normal using &amp;quot;app_usbd_hid_generic_out_report_get&amp;quot;, but the data size is always 64 bytes. 
 Is there any way to know the size of the received data? 
 
 Use SDK version : 17</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Oct 2020 10:20:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67629/how-do-i-know-the-length-of-receive-data-on-the-usb-hid" /><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/277570?ContentTypeID=1</link><pubDate>Thu, 29 Oct 2020 10:20:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa548714-876b-4b33-bf25-97a5b37a94d9</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;As your input data doesn&amp;#39;t match the format of report descriptor, other side&amp;nbsp;can choose whether do reject it, or pad it with zeroes up to 64 bytes - your PC chose second option.&lt;/p&gt;
[quote userid="83275" url="~/f/nordic-q-a/67629/how-do-i-know-the-length-of-receive-data-on-the-usb-hid/277567#277567"]Can I know the exact length of the received data?[/quote]
&lt;p&gt;For example, you can use first byte or your message as a length field - to send two bytes, fill buffer with [2,byte1,byte2].&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/277567?ContentTypeID=1</link><pubDate>Thu, 29 Oct 2020 10:14:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee44e5e9-c9da-49ce-9f67-6b96b7dee6fc</guid><dc:creator>moon.kim</dc:creator><description>&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;I have one more question.&lt;/p&gt;
&lt;p&gt;Why is the received data size different?&lt;/p&gt;
&lt;div class="ccvoYb"&gt;
&lt;div class="AxqVh"&gt;
&lt;div class="OPPzxe"&gt;
&lt;div class="dePhmb"&gt;
&lt;div class="eyKpYb"&gt;
&lt;div class="J0lOec"&gt;&lt;span class="VIiyi" lang="en"&gt;&lt;span class="JLqJ4b ChMk0b"&gt;&lt;span&gt;I sent 2 bytes from the PC to the device.&lt;/span&gt;&lt;/span&gt; &lt;span class="JLqJ4b ChMk0b"&gt;&lt;span&gt;However, the size of the received data is 64 bytes.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="zEswK"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="UdTY9 Yb6eTe"&gt;
&lt;div class="kO6q6e"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="kGmWO"&gt;Can I know the exact length of the received data?&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; recv_buf = (uint8_t *)app_usbd_hid_generic_out_report_get(&amp;amp;m_app_hid_generic,&amp;amp;recv_size);

NRF_LOG_INFO(&amp;quot;received data length:%d&amp;quot;, recv_size);
NRF_LOG_HEXDUMP_INFO(recv_buf, recv_size);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/277558?ContentTypeID=1</link><pubDate>Thu, 29 Oct 2020 09:59:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8203e831-6eba-4ab5-8011-69ba23fa46c0</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Yes, you should send an exact number of bytes as configured in report descriptor (read &lt;a href="https://www.microchip.com/forums/m466923.aspx"&gt;this thread&lt;/a&gt; for more information).&lt;/p&gt;
&lt;p&gt;You can configure several report descriptors of different sizes with different IDs, but&amp;nbsp;this would complicate things a lot - it&amp;#39;s much easier to just send 64 bytes of data everytime, no matter how many bytes are used actually.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/277497?ContentTypeID=1</link><pubDate>Thu, 29 Oct 2020 01:39:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55eee107-d976-40b6-a8ea-9d5d1eb1d9dc</guid><dc:creator>moon.kim</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;When I transmit 2 bytes, if abSize is set to 2, data is not transmitted.&lt;/p&gt;
&lt;p&gt;However, if it is set to 64, 2 bytes are transmitted and the remaining 62 bytes are transmitted as &amp;lt;NUL&amp;gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/277375?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 12:09:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a89c5e48-1bb9-47f4-98c2-a7d3b682c69a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What do you mean the abSize parameter has to be set to 64?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you get an error message if you set it to something else?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/276990?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2020 23:53:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb21f357-1114-46b5-a597-6f40a1601322</guid><dc:creator>moon.kim</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry. I can&amp;#39;t understand.&lt;/p&gt;
&lt;p&gt;I use&amp;#39;app_usbd_hid_generic_out_report_get&amp;#39; and&amp;#39;app_usbd_hid_generic_in_report_set&amp;#39; to send and receive data.&lt;/p&gt;
&lt;p&gt;When receiving data, the data size (recv_size) is always 64.&amp;nbsp;I want to know the size of the data actually received.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;recv_buf = (uint8_t *)app_usbd_hid_generic_out_report_get(&amp;amp;m_app_hid_generic,&amp;amp;recv_size);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And when data is transmitted, data size(abSize) must be set to 64 for transmission.&amp;nbsp;Can&amp;#39;t I set the length of the data I want to send?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret = app_usbd_hid_generic_in_report_set(
        &amp;amp;m_app_hid_generic,
        (uint8_t *)apvData,
        abSize);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know the length of receive data on the USB HID?</title><link>https://devzone.nordicsemi.com/thread/276838?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2020 11:25:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e34ecbc2-e9a1-458d-88a1-ede6a61e269e</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;report length is always the same size&amp;nbsp; - the one found in report descriptor (in your case, there is a single report of Report Count * Report Size bits). You can fill only part of report buffer and store the real size, for example, in the first byte of your message.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>