强制关闭 COM 端口

Force a COM port to close(强制关闭 COM 端口)
本文介绍了强制关闭 COM 端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 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 端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)