Author Topic: WinUSB  (Read 18158 times)

lizhi0007

  • Member
  • ***
  • Posts: 16
WinUSB
« on: May 18, 2011, 12:33:32 am »
Hi everybody;
My function:
 
success = WinUsb_Initialize
                    ( myDevInfo.deviceHandle,
                    ref myDevInfo.winUsbHandle );

success=false althought myDevInfo.deviceHandle is OK.

My device doesn't follow WINUSB, does it???

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUSB
« Reply #1 on: May 18, 2011, 09:58:59 am »
Look in Windows Device Manager to find out if the host has assigned the WinUSB driver to the device.

Jan

lizhi0007

  • Member
  • ***
  • Posts: 16
Re: WinUSB
« Reply #2 on: May 22, 2011, 03:36:06 am »
Hi Sir,

I want to read data from RFID Card Reader. I use WINUSB functions. At GetReceivedBulkData function, after BeginInvoke and EndInvoke i find out it success = false. Why is it? (ar.complete=true).

I use your example for WINUSB for my device, according to you how do i receive data when have card appear? My device is Bulk transfer type (saw in USBViewer).

in function: UsbEndpointDirectionIn why did you "and" add with 0x80? I know in bulk transfer, endpoint address = 0x81.
Thanks for helping.
« Last Edit: May 22, 2011, 10:36:21 am by lizhi0007 »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUSB
« Reply #3 on: May 22, 2011, 07:12:15 pm »
The high bit of the endpoint address indicates direction (1 = in, 0 = out).

Use whatever debugging tools you have to isolate the problem. A protocol analyzer will tell you what data if any is traveling on the bus. Use breakpoints, watch variables, etc. to monitor what is happening in your application.

Jan


lizhi0007

  • Member
  • ***
  • Posts: 16
Re: WinUSB
« Reply #4 on: May 23, 2011, 01:27:09 pm »
ConnectionStatus: DeviceConnected
Current Config Value: 0x01
Device Bus Speed:     Full
Device Address:       0x01
Open Pipes:              2

Endpoint Descriptor:
bEndpointAddress:     0x01  OUT
Transfer Type:        Bulk
wMaxPacketSize:     0x0040 (64)
bInterval:            0x01

Endpoint Descriptor:
bEndpointAddress:     0x81  IN
Transfer Type:        Bulk
wMaxPacketSize:     0x0040 (64)
bInterval:            0x01

I checked again, and i found out boonlean success = false at BeginInvoke and EndInvoke. But error in listbox:

"The attempt to read bulk data has failed" at GetReceivedBulkData; and  (ar.Iscomplete = true).

I don't understand about BeginInvoke and EndInvoke.

I want my software C# receive data when have a card pass and kit send data. Don't press button as your application. How can i do?

I know i must to create a thread. But i don't know how to create. Where is in your winusb project? I don't use button for receive data, because kit can send data whenever. I just want to receive when data arrive. In COM, it has OnComm, so in usb how must i do?

I saw my device speed = Full in USBView, but in your project i receive speed = Low. What are errors?

WinUsb_QueryPipe
                                (myDevInfo.winUsbHandle,
                                0,
                                System.Convert.ToByte(i),
                                ref pipeInfo);

why was it used twice? i=0 and i=1. For pipeIN vĂ  pipeOut?


I just only read data when it arrive. And have some problems above.
I hope you will help me. Thank you very much.




« Last Edit: May 23, 2011, 09:05:59 pm by lizhi0007 »

lizhi0007

  • Member
  • ***
  • Posts: 16
Re: WinUSB
« Reply #5 on: May 25, 2011, 12:47:03 pm »
Hi Jan,

We have WM_DEVICECHANGE messages with DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE to  detect device attach or remove.

What is message or DBT_....... on WParam of messages that help receive data from pic? Don't use button. When data arrive, software auto call "ReadDataViaBulkTransfer()" function and receive data.

Please help me. That is need for my card and reader. Thanh you.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUSB
« Reply #6 on: May 25, 2011, 02:56:41 pm »
You can create a loop that calls WinUsb_ReadPipe continuously with a timeout if no data is available. Or create a thread that attempts to read data continuously and notifies the main thread when data is available.

Jan

lizhi0007

  • Member
  • ***
  • Posts: 16
Re: WinUSB
« Reply #7 on: May 25, 2011, 10:59:10 pm »
Thanks.

I used Timer for it.