如何解锁COM端口
我有一个应用程序必须在另一个应用程序之后才能运行。 第二个应用程序有一个错误,导致 COM 端口在特定情况下无法关闭。
我想在我的应用程序中以编程方式关闭所有 COM 端口,以确保不会报告有关关闭端口的错误。 如果我不拥有打开 COM 端口的对象,是否可以?
我需要 .NET Framework、C# 的解决方案。
I've a application that must work after another application. This second application has a bug that causes COM ports not to be closed in specific circumstances.
I would like to close all COM ports programmatically in my application to ensure, that there will be no bugs about close ports reported. Is it possible if I do not own objects that opened COM ports?
I need a solution on .NET Framework, C# .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有好的、简单的方法:
There is no good, easy way:
我最近遇到了这个问题,需要补充一点...大多数 COM 端口驱动程序在设备管理器中启用和禁用设备时“解锁”端口。 这意味着解决方案中描述了完成此任务的 (C#) 方法:
Win32 API 函数以编程方式启用/禁用设备
使用该 COM 端口解决方案需要了解的信息是:
由于您说您想要重置所有端口,因此您需要修改该示例中的库以循环所有端口端口更改
为:
I came across this recently and have a little bit to add... Most COM port drivers "unlock" the port when the device is enabled and disabled in the device manager. This means that the (C#) way to accomplish this task is described in the solution:
Win32 API function to programmatically enable/disable device
The information that you need to know to use that solution for COM ports is:
Since you say that you want to reset all the ports, you would want to modify the library in that example to loop over all the ports by changing:
to something like this: