Author Topic: Send data to HID  (Read 1155 times)


  • Newbie
  • *
  • Posts: 1
    • View Profile
Send data to HID
« on: April 29, 2014, 08:44:47 am »
I have PIC (microcontroler) and VB (visual basic) program which reads incremented number all the time.

Code: [Select]
unsigned char OUTBuffer[65]; //Allocate a memory buffer equal to the OUT endpoint size + 1
unsigned char INBuffer[65]; //Allocate a memory buffer equal to the IN endpoint size + 1
DWORD BytesWritten = 0;
DWORD BytesRead = 0;

    if(AttachedState == TRUE){ //Do not try to use the read/write handles unless the USB device is attached and ready
//Get WORD value from the microcontroller.
OUTBuffer[0] = 0; //The first byte is the "Report ID" and does not get sent over the USB bus. Always set = 0.
OUTBuffer[1] = 0x37; //0x37 - read WORD
//Send command.
if(WriteFile(WriteHandleToUSBDevice, &OUTBuffer, 65, &BytesWritten, 0)){//Blocking function, unless an "overlapped" structure is used
INBuffer[0] = 0;
//Now get the response packet from the microcontroller.
if(ReadFile(ReadHandleToUSBDevice, &INBuffer, 65, &BytesRead, 0)){ //Blocking function, unless an "overlapped" structure is used
//INBuffer[0] is the report ID, which we don't care about.
//INBuffer[1] is an echo back of the command.
//INBuffer[2] and INBuffer[3] contains the WORD value. 
if(INBuffer[1] == 0x37){
VrednostWord = (INBuffer[3] << 8) + INBuffer[2]; //Reformating the data from two unsigned chars into one unsigned int.

Now I try to use HIDdemo program and I can't find out how to trigger the PIC to start send me data.
When I run both program VB demo and HID demo, the HID demo program receive correct values. Here is picture, where I have HID demo program, but request send to PIC is done with VB program.

The connection from HIDdemo to PIC is OK, on [3] it can be seen that number is incremented every line, but which values insert into Data field to trigger the PIC to return the data?
Number 37 in HEX or ASCII doesn't work.

Best regards,
« Last Edit: April 29, 2014, 09:05:47 am by Matija »