windows 如何分配COM端口号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8169901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:56:47  来源:igfitidea点击:

How to assign a COM port number?

windowsserial-port

提问by Mr. T.

We are using a USB-to-Serial converter. Windows assigns a COM port number to the serial device. For testing purposes, we need to control the COM port number assigned by Windows. For example, we would like to tell Windows to assign COM 255 to a device rather than have Windows decide what the number is. Is there any way to do this?

我们正在使用 USB 到串行转换器。Windows 为串行设备分配一个 COM 端口号。出于测试目的,我们需要控制 Windows 分配的 COM 端口号。例如,我们想告诉 Windows 将 COM 255 分配给设备,而不是让 Windows 决定数字是多少。有没有办法做到这一点?

回答by Mr. T.

I do not have to do this programmatically, so Nacereddine is right. My Computer -> Manage -> Device Manager -> Ports -> Communications Port -> Port Settings -> Advanced -> COM Port Number

我不必以编程方式执行此操作,因此 Nacereddine 是正确的。我的电脑 -> 管理 -> 设备管理器 -> 端口 -> 通信端口 -> 端口设置 -> 高级 -> COM 端口号

回答by Shane Wealti

This normally depends on the driver. Some drivers allow you to edit the COM port number assigned by going into the device properties in device manager and using one of the properties pages to specify the COM port number. If the model you are currently using doesn't support this I suggest finding a model that does.

这通常取决于驱动程序。某些驱动程序允许您通过进入设备管理器中的设备属性并使用属性页面之一指定 COM 端口号来编辑分配的 COM 端口号。如果您当前使用的模型不支持这一点,我建议您找一个支持的模型。

回答by ChrisBD

No, but if you know what device id it reports to the OS then its possible that you could find it programmatically in the device manager.

不,但如果您知道它向操作系统报告的设备 ID,那么您可以在设备管理器中以编程方式找到它。

Here's a link to a code project that may give you some ideas.

这是一个代码项目的链接,它可能会给你一些想法。