Author Topic: WinUSB VB Code Questions  (Read 15188 times)

odsk

  • Member
  • ***
  • Posts: 4
WinUSB VB Code Questions
« on: January 29, 2017, 09:02:23 pm »
Hi
I am using your code Winusb VB version as a base for my application (thank you very very much for the sample program I have 2 questions that I am hoping to get help with.
1- Is there a way for the application to detect the arrival and removal without using a button for arrival? I know there is deviceNotificationsStart and stop but this seems to work only if first the button is clicked and the device was previously found. 

2- I am transferring 64bytes via bulk and receiving the same with no problem. to speed up the IN transfer you mentioned in another thread to increase the receive buffer (http://janaxelson.com/forum/index.php?topic=1528.0). I did that, the first transfer succeed but then fails afterward. Any recommendations? the endpoints are defined as 64B long for both in/out.

Thanks a lot.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUSB VB Code Questions
« Reply #1 on: January 29, 2017, 09:31:17 pm »
You can run the routine periodically to look for a device.

Also see my more recent C# HID example, which uses the System.Management class and Windows Management Instrumentation (WMI) to detect when device is attached or removed. I don't have a VB version, but there are some good code converters on the web.

A larger buffer may contain multiple reports so be sure to look for those. I don't know the details of your code, but possibly the buffer contains everything the endpoint has to send.

odsk

  • Member
  • ***
  • Posts: 4
Re: WinUSB VB Code Questions
« Reply #2 on: February 01, 2017, 02:15:15 pm »
Jan;
Thanks for the reply.
I finally was able to get the arrival and removal to work. The first time used to fail as _DeviceReady was false. I added a condition to check on this variable, if false I call also FindMyDevice.
I believe when you reference your example you wrote HID example, which I believe you meant C# Winusb example.

MY other question which I am still working on. If I call RequestToSendDataViaBulkTransfer(4096,buffername, byesRead, success) to request 4K of data at once.
For firmware I am using MikroC CDC library and I am just doing:
looping 64 times
{Fill 64 bytes buffer that points to USB RAM
USBDev_SendPacket(bulk in EP, the buffer, 64)
}

Is that the proper way to do it?

Thanks.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUSB VB Code Questions
« Reply #3 on: February 02, 2017, 11:10:05 am »
I believe when you reference your example you wrote HID example, which I believe you meant C# Winusb example.

Correct, thanks.

Yes, you can only send max endpoint size in each transaction, so device firmware needs to keep refilling the endpoint's buffer when data goes out.

Typically, an interrupt indicates when data has been sent to let the firmware know it can refill the buffer if desired.

odsk

  • Member
  • ***
  • Posts: 4
Re: WinUSB VB Code Questions
« Reply #4 on: March 08, 2017, 11:32:52 am »
Hello;
still struggling with large transfers using bulk with WinUSB (using the VB version).
Using your code for "bulk only" transfer trying to achieve higher transfer rates than HID. I have only have 2 EB (In 64B, Out 64B). If using only 64B per transfer, it works. If I request to read big chunk of data i.e. 4096B (or even 128B) before calling read pipe function, I always end up with a stall error on the "In" Pipe usually after few successful reads of large data calls (i.e. about 2 to 3, 4096B successful "In" transactions) the USB tracer shows Unsuccessful (Stall PID).

On the firmware side, I'm using MikroC CDC routines and descriptor with Extended OS to eliminate driver installation.
I goggled and found a post that it is almost identical to the issue I have. I set ROW_IO to true as proposed in port #9 and set no timeout on the read. That didn't help much either.
http://www.microchip.com/forums/m638981.aspx?tree=true#false

Any help, please with this issue?
Thanks...

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUSB VB Code Questions
« Reply #5 on: March 08, 2017, 02:27:09 pm »
A Stall on a bulk endpoint means the endpoint is unable to send or receive data.

So the question is what is causing that condition?

In a large Read transfer, the host may send multiple IN token packets with little delay in between.

So immediately after sending data, the IN endpoint must be configured to return either NAK or more data. In other words, if the firmware needs a little time to get the next data chunk into the endpoint's buffer, be sure that the endpoint will return NAK in case the host requests data before it's ready to go out. Exactly how to do that varies with the chip architecture.