Author Topic: USB and VB6  (Read 29884 times)

Fougeron

  • Member
  • ***
  • Posts: 10
USB and VB6
« on: April 10, 2013, 03:56:51 am »
Hi friends
does anybody can help me to implement a "good" working usb link between my PIC2550 device and my VB6 application
I try and use mcUSB.dll which really looks fine, but I have an issue I don not know how to solve :

1/ The answer of my device often spend seconds to be catched by the OnRead event.

2nd question, is it true I need to begind my datas with a 0x00 ?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #1 on: April 10, 2013, 09:11:43 am »
I have a VB6 "generic HID" application here:

http://www.lvr.com/hidpage.htm#MyExampleCode

If your device is HID class, and if it uses the default report ID of zero then yes, in the host application, the report buffers must begin with a zero byte. However, neither the host's HID driver or the device firmware sends the zero byte on the bus.

If the host isn't seeing received data quickly, use a protocol analyzer or whatever debugging tools you have to find out when the device is sending the data. Then you will know whether to look on the device or host PC side for the reason.

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #2 on: April 10, 2013, 11:09:33 am »
Thanks for your answer

If your device is HID class, and if it uses the default report ID of zero then yes, in the host application, the report buffers must begin with a zero byte. However, neither the host's HID driver or the device firmware sends the zero byte on the bus.
OK I have added a zero and now the hidWriteEx function return TRUE and the PIC receives the datas

If the host isn't seeing received data quickly, use a protocol analyzer or whatever debugging tools you have to find out when the device is sending the data. Then you will know whether to look on the device or host PC side for the reason.
The PIC spend less than 100µs to enter usb_put_packet routine.
One time on 5 or 10, VB receives quickly (I mean within some ms) the other times, it does not recevive at all !
But when I spy with USBTrace, the difference timestamp between OUT and IN is about 3 ms !

I work on a 64b PC, maybe mcHID.dll does not like it, nor WaitforsingleObject ?

Thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #3 on: April 10, 2013, 12:05:31 pm »
The HID driver on the PC ignores received data that doesn't match the size of a valid report.

So if the device is sending data on the bus but the PC application isn't seeing the data, check to be sure the device endpoint is sending the correct number of bytes.

In your case, that is the report size from the report descriptor with no initial report-ID byte.

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #4 on: April 11, 2013, 03:50:45 am »
Thanks Jan
I annex the export of USB Trace
You see on trace 1  that VB sends 2 times (and I do not understand why yet) a request (lines 9 and 10)
and the PIC answer is seen one time (line 13).
It tooks 100µs to the PIC to answer.

On trace 2, the Pic had also answered (seen on the oscilloscope, but USBTrace did not see it !

Both send and receive 64 bytes !

(I tried on a 32b windows and it it similar)

Thanks

[attachment deleted by admin]

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #5 on: April 11, 2013, 09:43:09 am »
In trace 1, #12 is labeled as [IN] yet uses OUT endpoint address 0x1 with TransferFlags USBD_TRANSFER_DIRECTION_OUT.

The same is true for trace 2, # 11 and 12.

Post your descriptors.

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #6 on: April 11, 2013, 10:06:01 am »
#11 also
and #14 [OUT] has USBD_TRANSFER_DIRECTION_IN !!

here is the descriptor

[attachment deleted by admin]

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #7 on: April 11, 2013, 10:49:26 am »
#11 and #12 are [IN] but use OUT endpoint 0x1 and flag USBD_TRANSFER_DIRECTION_OUT.

The descriptors look OK so I don't know why the host is trying to get IN data from an OUT endpoint address

I don't see a #14 in the files posted.

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #8 on: April 11, 2013, 12:39:34 pm »
In 1.txt

--------- Request # 14 ----[OUT]----

URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER

Length: 0x80
USBD Status: USBD_STATUS_SUCCESS (0x0)
EndpointAddress: 0x81
PipeHandle: 0xFFFFFA80064F8AE8
TransferFlags: 0x3 ( USBD_TRANSFER_DIRECTION_IN USBD_SHORT_TRANSFER_OK )
TransferBufferLength: 0x40
TransferBuffer: 0xFFFFFA8002777CA0
TransferBufferMDL: 0x0
UrbLink: 0x0

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #9 on: April 11, 2013, 03:26:06 pm »
What does the HID report descriptor look like?

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #10 on: April 12, 2013, 10:57:54 am »
What do you mean ?
Where do I find this info ?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #11 on: April 12, 2013, 11:05:04 am »
The firmware in your HID device contains a report descriptor that defines the contents of the data the keyboard sends to the host computer. During enumeration, the host computer requests the report descriptor from the device.

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #12 on: April 16, 2013, 03:10:29 am »
I have that :

Code: [Select]
const char USB_CLASS_SPECIFIC_DESC[] =
   {
      6, 0, 255,        // Usage Page = Vendor Defined
      9, 1,             // Usage = IO device
      0xa1, 1,          // Collection = Application
      0x19, 1,          // Usage minimum
      0x29, 8,          // Usage maximum

      0x15, 0x80,       // Logical minimum (-128)
      0x25, 0x7F,       // Logical maximum (127)

      0x75, 8,          // Report size = 8 (bits)
      0x95, USB_CONFIG_HID_TX_SIZE,        // Report count = 16 bits (2 bytes) USB_CONFIG_HID_TX_SIZE=64
      0x81, 2,          // Input (Data, Var, Abs)
      0x19, 1,          // Usage minimum
      0x29, 8,          // Usage maximum
      0x75, 8,          // Report size = 8 (bits)
      0x95, USB_CONFIG_HID_RX_SIZE,        // Report count = 16 bits (2 bytes) USB_CONFIG_HID_RX_SIZE=64
      0x91, 2,          // Output (Data, Var, Abs)
      0xc0              // End Collection
   };

and

Code: [Select]
const char USB_CONFIG_DESC[] = {
   //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
      //    config(s)
      //    interface(s)
      //    class(es)
      //    endpoint(s)

   //config_descriptor for config index 1
         USB_DESC_CONFIG_LEN, //length of descriptor size         
         USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02)     
         USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config      #DEFINE USB_TOTAL_CONFIG_LEN      41
         1, //number of interfaces this device supports       
         0x01, //identifier for this configuration.  (IF we had more than one configurations)     
         0x00, //index of string descriptor for this configuration     
        #if USB_CONFIG_BUS_POWER
         0x80, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1       
        #else
         0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1         
        #endif
         USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2)  (0x32 = 100mA) #define  USB_CONFIG_BUS_POWER 100

   //interface descriptor 1
         USB_DESC_INTERFACE_LEN, //length of descriptor     
         USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04)       
         0x00, //number defining this interface (IF we had more than one interface)   
         0x00, //alternate setting     
         2, //number of endpoins, except 0 (pic167xx has 3, but we dont have to use all).       
         0x03, //class code, 03 = HID     
         0x00, //subclass code //boot     
         0x00, //protocol code     
         0x00, //index of string descriptor for interface     

   //class descriptor 1  (HID)
         USB_DESC_CLASS_LEN, //length of descriptor   
         USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID)     
         0x00,0x01, //hid class release number (1.0)     
         0x00, //localized country code (0 = none)       
         0x01, //number of hid class descrptors that follow (1)     
         0x22, //report descriptor type (0x22 == HID)               
         USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, //length of report descriptor           

   //endpoint descriptor
         USB_DESC_ENDPOINT_LEN, //length of descriptor                   
         USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05)         
         0x81, //endpoint number and direction (0x81 = EP1 IN)       
         USB_EP1_TX_ENABLE, //transfer type supported (0x03 is interrupt)         #define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT
         USB_EP1_TX_SIZE,0x00, //maximum packet size supported                 #define USB_EP1_TX_SIZE    64
         USB_CONFIG_HID_TX_POLL,  //polling interval, in ms.  (cant be smaller than 10 for slow speed)      #define USB_CONFIG_HID_TX_POLL   10

   //endpoint descriptor
         USB_DESC_ENDPOINT_LEN, //length of descriptor                   
         USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05)         
         0x01, //endpoint number and direction (0x01 = EP1 OUT)     
         USB_EP1_RX_ENABLE, //transfer type supported (0x03 is interrupt)         #define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT
         USB_EP1_RX_SIZE,0x00, //maximum packet size supported                 #define USB_EP1_RX_SIZE    64
         USB_CONFIG_HID_RX_SIZE//polling interval, in ms.  (cant be smaller than 10 for slow speed)     #DEFINE USB_CONFIG_HID_RX_SIZE 10
   };

Many thanks for your analysis

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB and VB6
« Reply #13 on: April 16, 2013, 12:19:00 pm »
According to the report descriptor, the Input and Output reports are each 2 bytes.

Yet in 1.txt, Requests 10 and 13 show 8-byte reports. 

Fougeron

  • Member
  • ***
  • Posts: 10
Re: USB and VB6
« Reply #14 on: April 17, 2013, 02:59:25 am »
According to the report descriptor, the Input and Output reports are each 2 bytes.

Is that ?
Code: [Select]
0x81, 2,          // Input (Data, Var, Abs)
0x91, 2,          // Output (Data, Var, Abs)
What effect have these values ? Are they the number of bytes each transaction send ?

Yet in 1.txt, Requests 10 and 13 show 8-byte reports. 

So what have I to do ? These files are supplied by CSS !