I am talking to a custom made lab-device (little hardware thingy) through a USB-connection. How do I acquire data from the lab-device at maximum speed?
The host is a Windows XP machine, running c-code using libsub-win32 in Visual Studio. The little hardware thingy collects data, lots of data. The host can request this data and then read it. Everything is working just fine. What bothers me is the speed, a rough estimate is 1Mbit/s, which is far from the 480 Mbit/s USB2 supports. The device should be able to send me data at at least that speed. I have little to no experience with neither USB nor libusb-win32, but I have tried to read about them. Though I don't see where and how to change any USB-communcation settings. In the spec there seems to be something called micro-frames on high speed buses. How can I use them?
I don't necessarily have to use the libusb-win32 library. Do you have any other recommendations?
Details about the current implementation: As mentioned above I use libusb-win32 for communication. All initialization is copied from a small example included in the download.
usb_init();
...
usb_op开发者_StackOverflow中文版en();
usb_set_configuration(...);
usb_claim_interface(...);
Then I talk (using usb_bulk_write(...) and usb_bulk_read(...)) to the lab-device and convince it to share its data with me, which it does. It gives me data in chunks of 512 bytes. Each such chunk is read using usb_bulk_read(...).
Edit April 27th 2011: It looks like I am using Full Speed, but not High Speed. How do I get high-speed? Did I get some parameter wrong in the usb descriptor file? (Yes, I'm using USB2.0, and the device should support high-speed.)
Edit May 17th 2011: I have now implemeted the communication using winUSB (wrote an .inf file and c++-program). The benefit of using WinUSB is that it can tell me if it is trying to use high speed or not. And it is, but I still don't get more than around 11+-2 Mbit/s. Why?
According to the USB2.0 protocol the computer should be sending a Start of frame marker (sent each ms), which I think it is doing - thus the 11Mbit/s. But when using hi-speed it says "high speed uses the 'Microframe' which is 125us long (8 Microframes per millisecond). The correspondence with the 1ms frame numbering is maintained in the high speed SOF packets by repeating each frame number in 8 successive Microframes." I don't really understand this, but not sending the micro-frames often enough could be the problem? Could someone who understands the protocol please enlighten me! I want to understand how the thing worksregardless of if I can get it working on my computer or not.
Edit June 15th
Problem solved: No alterations on the computer side can make the communication faster than it wants to be (if you don't change the number of endpoints and you really have a USB2.0 connection). The problem here was in the processor code which used its memory areas in a very time-consuming way. This makes this question a non-question sort of. Thanks for all the pointers and information. I've learnt a great deal about USB!
Try to use WinUSB the official Microsoft driver, I think it will help. Also you can find examples about how to use it Jan Axelson's website, in particular this page deals with WinUSB. As a supplementary argument even LibUSB is relying on WinUSB.
I would like to ask you what type of device is it your lab device: HID, CDC, etc? because it depends also about your backend device. It it is a HID (mouse, keybord) you cannot expect superspeeds.
You really need to check in which mode your USB device runs.To do this, open Device Manager, then navigate: View-> Devices by connection.
Now you have to fold up the device tree to your USB Device. It will be behind one of the "Standard XYZ USB Host Controller".
With the XYZ you can tell whether its high speed or full/low: If XYZ is "Enhanced PCI to USB" then the device runs indeed at High speed 480 MBit/s. But if the upper level Host controller is "OpenHCD USB" or something else (likely something with UHCI, I don't have an Intel board here) the device runs at Full speed - 12 MBit/s maximum. Many "USB 2.0" microcontrollers only support Full speed and not High speed.
Update
A device runs at full speed in the following cases:
- There is a USB 1.1 Hub in between, one that can not speak high speed
- The device can only talk at full speed itself.
How do you calculate the data transfer speed?
- Either the data transfer speed calculation MAY notbe correct or
- The number of threads that are handling data transfer is less; and consequently the speed is less.
I have not used libusb-win32 library nor have worked in-depth in USB, but these points may help you find the real root cause or issue, if there is one.
精彩评论