Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I have to control a hardware device that is physically connected to usb and programmatically controlled via COM-Ports (by the help of usbser.sys).

I recognized some problems while communication, on some pc’s (XP) on other not. Seems that from time to time some characters will be lost. I do not know what exactly the problem is(handshaking problem? driver versions? sleeping usbser.sys...no idea). Furthermore I do not have a real unit to test.

So my idea is, to write a program (c# - preferred or c++) that does simulate this unit and to let me make stress tests and hopefully find the situation which causes the problem.

[My Software]<------“COM API”------->[USB Device] (this one I like to simulate)


My problem:
I do not have any idea how to simulate a USB unit by software. All what seems clear to me (I hope at least this is right) is, that I need something like a cross over usb cable to connect my future simulated USB device.

N.B: I searched a lot in google without success.

Thanks for help.
Regards
Posted
Updated 5-Jun-12 8:43am
v2

There are a number of places the error might be occurring, and I suspect that a "USB Device simulation" won't actually help you find them.

Here's my candidates for the problem source (most likely first):

1. The device you are controlling has a bug in it's software/firmware that is timing dependent. Something like a buffer overflowwhen commands come faster then it can process them. You won't find that with a simulation.

You can test for it by slowing down your commands to the device, but that's never conclusive since it may just make the problem less likely to happen.


2. The usbser.sys driver is out-of-date on the specific XP pc's that exhibit the problem. (I recently solved a similar problem that I traced to out-of-date winusb.sys files on Vista machines that were not updated because they aren't connected to the net.)

[One would assume that the usbser.sys is relatively bug free if it has been updated.]

If the problem is an out-of-date driver you can test it by updating the driver.

If the driver is up-to-date, it could still be a problem with the driver. It would probably be an issue with the way the driver handshakes with the device and determines if the device is ready. This is both a timing dependent issue specific to the device and potentially an issue with the specific (possibly wrong) way the device implements the USB protocol. You won't see the problem if you simulate the device.

3. The problem is in your code -- in which case you can write a simulator at a level above the USB device level.

The best way to debug the problem is to get your hands on a PC and a device that shows the problem and get USB analyzer on it.

You can't solve the problem without having access to a real device and a host that exhibits the problem.

How will you know it's fixed otherwise?



That said, there is no such thing as a "USB cross-over cable".

I'm assuming you are talking about USB 1.1 or 2.0 (and not 3.0).

Those USB cables consist of one pair of differential wires. The same pair of wires transmits data from the host to the device and from the device to the host. The host controls all the timing and (simplistically) the device only transmits on the pair of wires when it is responding to a command from the host.

The easiest way to do what you are asking would be to get two USB to serial adapters (https://www.google.com/search?q=usb+to+serial+adapter[^]) and connect them with a serial cross-over cable (https://www.google.com/search?q=null+modem[^]).

Then you just need to write something that sits on the other USB port and simulates the device.
 
Share this answer
 
Comments
enhzflep 5-Jun-12 17:52pm    
Great answer. +5!
[no name] 6-Jun-12 2:29am    
Hello TRK3Thank you very much for your great and detailed answer.Regards, Bruno

It seems you have big experience with communication things.
Maybe you have the answer for my problem if I describe it.

After successfully control this USB unit for a while it comes to a point where the unit stops to answer on commands (just say 0.5 seconds before, everything was ok). Simply unplug and plug the USB device does reestablish the connection.

Thanks for any idea.
[no name] 6-Jun-12 11:12am    
See also my "answer" I posted. I think I found now the reason for my problem.
Hello all
FYI:
I searched now again on google and found a very interesting link which does describe a very bad behavior of usbser.sys:
http://www.microchip.com/forums/m538194.aspx[^]

I think that is the problem I'm facing...

Regards
 
Share this answer
 
v2
Comments
TRK3 6-Jun-12 13:39pm    
Yeah, that sounds a lot like the problem I was seeing with the out-of-date winusb.sys. (At first glance I thought the site said the problem was fixed in Vista/Win7 -- but apparently it isn't.)

Also, it appears that the usbser.sys that ships with XP SP3 may have more problems than the version with XP SP2 -- figure out if all the failing XP systems have the same version. If so, try replacing it with the other version (SP3 or SP2 which ever one they aren't using).

You might consider using the winusb driver instead (the updated version seems to work fine on XP). That will require you writing a layer in your code to tarnslate the serial API into explicit BULK IN and BULK OUT reads/writes via winusb, but thats a pretty simple layer.
[no name] 6-Jun-12 16:15pm    
Thank you for your comment and your big help. But using winusb is maybe for you a simple thing. I'm personally start sweating to go one layer down :)
Regards, Bruno
TRK3 6-Jun-12 19:01pm    
Actually, for me it is simple since I've used winusb.sys to interface to 4 different devices now.

One of the devices has a simple serial interface over USB (using an Atmel USB to serial bridge). I even think the original test software for that used usbser.sys -- but I replaced it with a winusb.sys version since I was using that for all the other devices and I didn't want to have to deal with the idiosyncracies of multiple drivers.

Is your application level interface just a simple character stream in/out? If so, I could probably dig up sample code that implements that over winusb for you if you want to go that route.
[no name] 7-Jun-12 2:16am    
Yes it is simple character stream in/out (sending a command, reading the answer). Sample code would be great :)
Thank you very much. Regards, Bruno

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900