问题描述
我正在开发一个使用 COM 端口与外部控制器通信的应用程序.当我在连接了通信电缆的情况下重新启动 PC 时,Windows (7) 打开了端口,没有运行任何应用程序,因此我无法再访问它.我试图以编程方式关闭它,但它仍然被占用.
I'm working on an application that uses COM port for communication with external controller. When I reboot the PC with communication cable connected, Windows (7) opens the port, without any application running, so I can't access it any more. I tried to close it programatically, but it just stays taken.
任何人都知道如何强制关闭它,我可以在我的应用程序之前运行任何程序,或者无论如何以编程方式关闭它的方法?
Anyone got an idea how can I force it to close, any program I can run before my app, or a way to programatically close it no matter what?
推荐答案
我没有设法关闭端口,但是经过大量搜索和测试后,我发现了问题的根源.我正在发布解决方案以帮助遇到相同问题的任何人.
I didn't manage to close the port, but after a lot of searching and testing I found what was the source of my problems. I'm posting the solution to help anyone who has the same problem.
Windows 将连接到串行端口的具有恒定数据流的设备识别为串行鼠标(在此系统中为 Microsoft Serial Ballpoint),并尝试安装它们,在没有任何进程使用它的情况下接管对端口的控制.解决方案是等待 Windows 安装设备(检查鼠标和其他指针设备下的设备管理器),然后禁用它.如果你卸载设备,它会重新安装,问题又回来了.
Windows identifies devices with constant data stream connected to serial port as serial mouse (in this system it was Microsoft Serial Ballpoint), and tries to install them, taking over the control over the port without any process using it. The solution is to wait for Windows to install the device (check Device Manager under Mouses And Other Pointing Devices) and then DISABLING it. If you uninstall the device it will be installed again, and the problem is back.
感谢所有尝试提供帮助的人,我希望其他人会发现此解决方案有用.
Thanks to everyone who tried to help, and I hope others will find this solution useful.
这篇关于强制关闭 COM 端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!