重新启动串行端口 [英] Restarting a serial port

查看:218
本文介绍了重新启动串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用USB串口。除了一些不经常的情况外,.net串口读/写操作运行良好。如果我停止串行读取操作 - 就像调试器中断操作一样 - 串口似乎挂断了。即使我重新启动.exe,串口也不再读取数据。



我可以通过以下两种方式之一重新启动它:1)拔出并重新插入USB串行电缆或2)手动进入设备管理器并执行禁用,然后启用。在任何一种情况下,串行端口都会再次开始正确读取数据。这似乎表明问题不在于串行数据发送器。



我知道我可以使用DevCon在软件中执行禁用/启用操作。然而,这似乎是Klutzy解决这个问题的方法。



任何想法都赞赏。



我尝试了什么:



我试图清除端口的InBuffer和OutBuffer,但这没有效果。

I am using a USB serial port in C#. The .net serial port read/write operations work well except in some infrequent cases. If I halt the serial read operations -- as in the case of a debugger break operation -- the serial port seems to hang up. Even if I restart the .exe, the serial port no longer reads data.

I can get it restarted in one of two ways: 1) unplugging and re-plugging the USB serial cable or 2) manually going in to the Device Manager and doing a "disable" and then "enable". In either cases, the serial port begins to read the data properly again. This seems to suggest the problem is not at the serial data transmitter.

I am aware that I can use DevCon to do the disable/enable operations in software. However, this seems a Klutzy way of solving this problem.

Any ideas appreciated.

What I have tried:

I have tried to clear the InBuffer and OutBuffer for the port but this has no effect.

推荐答案

Usbser.sys似乎仍然是错误的。调试的解决方法是,通过USB集线器连接您的设备。

另请参见此处的讨论:检查usbser.sys是否仍在工作/轮询COM端口/ CDC设备 [ ^ ]
Usbser.sys still seems to be buggy. A workaround for debugging can be, to connect your device via a usb hub.
See also the discussion here: Checking whether usbser.sys is still working/polling a COM port/CDC device[^]


经过一番进一步的实验,我找到了一个纯粹的软件解决方案来重新启动卡住的USB串口。解决方案1)在设备管理器中手动执行禁用/启用和2)手动拔出/重新插入USB电缆不适合操作使用 - 我需要一个纯粹的软件解决方案,无需用户干预。我尝试使用DevCon来执行禁用/启用 - 但是,在我的计算机上,结果是devcon禁用步骤需要重新启动才能完成。这也被认为不适合操作,因为有时间重新启动计算机



最后,我尝试使用devcon的重启程序。这似乎可以解决问题。所以现在我在检测到串口设备的存在后总是重新启动。这花费的时间可以忽略不计 - 但似乎总是开始卡住USB串口。



有没有人知道这里到底发生了什么?
After a bit of further experimenting, I found a purely software solution to re-starting the stuck USB serial port. The solution of 1) manually doing a disable/enable in the Device Manager and 2) manually unplugginh/replugging the USB cable was not suitable for operational use -- I need a purely software solution w/o user interventiion. I attempted to use the DevCon to do the disable/enable -- however, on my computer, the results were that the devcon disable step required a reboot in order to finish. This was also deemed not suitable for operations because of the time to do the computer reboot

Finally, I attempted to use devcon's restart procedure. This seems to do the trick. So now I always do a restart after I detect the presence of the serial port device. This takes a negligible amount of time - but always seems to start a stuck USB serial port.

Does anyone have any idea as to what is actually going on here?


这篇关于重新启动串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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