USB设备仿真C#,C ++ [英] USB Device simulation c#, c++

查看:153
本文介绍了USB设备仿真C#,C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我必须控制物理连接到USB并通过COM端口以编程方式控制(通过usbser.sys的帮助)的硬件设备.

我在交流时发现了一些问题,在某些PC(XP)上却没有.似乎有时会丢失一些字符.我不知道到底是什么问题(握手问题?驱动程序版本?正在休眠usbser.sys ...不知道).此外,我没有实际的测试单元.

所以我的想法是,编写一个可以模拟此单元的程序(c#-首选程序或c ++),并让我进行压力测试并希望找到引起该问题的情况.

[我的软件]< ------"COM API" -------> [USB Device](我喜欢模拟的那个)


我的问题:
我不知道如何通过软件模拟USB单元.对我来说似乎很清楚(我希望至少这是对的),我需要类似usb的交叉电缆来连接我将来的模拟USB设备.

N.B:我在Google上搜索了很多内容,但都没有成功.

感谢您的帮助.
关于

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

推荐答案

可能在很多地方发生错误,并且我怀疑"USB Device Simulation"实际上无法帮助您找到它们.

这是问题源的我的候选人(很可能是第一个):

1.您所控制的设备的软件/固件中存在与时间相关的错误.当命令来得更快时,缓冲区就溢出了,然后它就可以处理它们了.您不会通过模拟找到它.

您可以通过放慢对设备的命令来进行测试,但这从来没有定论,因为这只会使问题的发生可能性降低.


2.在出现问题的特定XP PC上,usbser.sys驱动程序已过期. (我最近解决了类似的问题,我跟踪到Vista计算机上的过时winusb.sys文件,这些文件由于未连接到网络而未更新.)

[有人假设usbser.sys如果已更新,则相对来说没有错误.]

如果问题是过时的驱动程序,则可以通过更新驱动程序进行测试.

如果驱动程序是最新的,则驱动程序仍然可能有问题.驱动程序与设备握手并确定设备是否准备就绪的方式可能是一个问题.这既是设备特定于时序的问题,又可能是设备实现USB协议的特定方式(可能是错误的)的问题.如果模拟设备,您将看不到问题.

3.问题出在您的代码中-在这种情况下,您可以在USB设备级别之上的级别编写模拟器.

调试问题的最佳方法是动手使用PC和显示问题的设备,然后安装USB分析仪.

您无法访问实际设备和出现问题的主机,就无法解决问题.

你怎么会知道它是固定的?



也就是说,没有"USB交叉电缆"之类的东西.

我假设您正在谈论的是USB 1.1或2.0(而不是3.0).

这些USB电缆由一对差分线组成.同一对电线将数据从主机传输到设备以及从设备传输到主机.主机控制所有时序,并且(简单地)设备仅在响应来自主机的命令时才通过一对电线进行传输.

执行您要的操作的最简单方法是获得两个USB到串行适配器( https://www.google.com/search?q=usb+to+serial+adapter [ ^ ]),然后使用串行交叉电缆( ^ ]).

然后,您只需要编写另一个USB端口上的内容并模拟设备即可.
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.


大家好
仅供参考:
我现在再次在Google上进行搜索,发现了一个非常有趣的链接,该链接的确描述了usbser.sys的非常不良的行为:
http://www.microchip.com/forums/m538194.aspx [
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


这篇关于USB设备仿真C#,C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆