View previous topic :: View next topic |
Author |
Message |
mikrosurfer
Joined: 03 Mar 2009 Posts: 1
|
USB HID, how send/receive more than 2 bytes? |
Posted: Tue Mar 03, 2009 10:34 pm |
|
|
Hello, I am studying the example ex_usb_hid.c, the example works fine, The problem is that only two bytes transmitted every time, the comment above says:
Quote: |
//// The first byte sent by the PIC is the ADC reading ////
//// on channel 0 (AN0), the second byte is the status of the ////
//// pushbutton. The two bytes sent by the PC are LED on/off ////
//// toggle status. If you want to change the protocol to ////
//// send/receive more than 2 bytes you must change the HID report ////
//// descriptor. ////
|
as is done to change the number of bytes sent.
Thanks for your help. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
|
JimmyZ Guest
|
|
Posted: Sun Dec 13, 2009 10:52 am |
|
|
How to send this to my USB device:
char SomeText = 'This is some text';
int SomeNum = 10;
Jim |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 13, 2009 11:17 am |
|
|
A HID report is just a block of data, you have to define it's usage for your application. You define that the first one or
two bytes are used as a type ID, or another location as a length code. Using this arrangement on both sides
(host and device) you get an unequivocal assignment of each data item sent through USB. |
|
|
JimmyZ Guest
|
|
Posted: Sun Dec 13, 2009 11:39 am |
|
|
I'm sorry but I don't understand you.
I understand the transfer but have no clue how to make this.
In my PIC program I have those variables and I send the same ones from my PC application. This is all I have.
If I get this OK , then I should make this
Code: | usb_get_packet(1,SomeText); |
Problems in my understanding are how to get this data.
I can not write.
Code: | usb_get_packet(1,SomeText);
usb_get_packet(1,SomeNUm);
usb_get_packet(1,SomeThingElse);
.... |
I search the whole forum for this.
Jim |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 13, 2009 2:02 pm |
|
|
Code: | unsigned int16 usb_get_packet(int8 endpoint, int8 * ptr, unsigned int16 max) |
The first point is to understand the data types involved with usb_get_packet, the second to understand
what the HID protocol expects in this case.
By function definition, the data object must evaluate to an int8 pointer, this would work with a string of text,
but not with a numerical variable. Also a value for the max packet length parameter must be supplied.
HID is working with "report" packets of fixed or variable length. As long as you don't know in advance, what
kind of data comes in, it's most simple to receive it to a buffer structure and copy it to the respective data
items, or, to declare the buffer as a union of different data items.
The HID protocol also defines a report ID as optional element, but if you don't need to be compatible to a standard
HID device, you can define a packet structure freely. |
|
|
|