什么是检测在Windows上所有可用的串行端口正确方法? [英] What is proper way to detect all available serial ports on Windows?

查看:121
本文介绍了什么是检测在Windows上所有可用的串行端口正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几种方法可以列出Windows下串行端口,但我不知道什么是正确的方式。这并检测所有可用的串行端口的方式。

There are several ways to list serial ports under Windows but I'm not sure what is the proper way: the way that does detect all serial ports that are available.

一个很好的code例子是 http://www.naughter.com/enumser.html - 那里有枚举串行设备的9(!9份)的方式

One good code example is http://www.naughter.com/enumser.html - where there are 9 (nine!) ways of enumerating serial devices.

现在的问题是:什么是做它的最佳方式。

The question is: what is the optimal way of doing it.

要求:


  • 要为了不开放的端口,以检查它们是否可用。

  • 要能够检测不同名称的端口号大于的COMx

  • 要在Windows XP SP2或更高版本
  • 工作

推荐答案

串口是非常简单的设备,从计算机硬件的石器时代约会。它们不支持随插即放;玩,有没有办法告诉,有人在一个设备插入。你能做的唯一的事情就是发现哪些端口是可用,SerialPort.GetPortNames()返回列表中。一些USB仿真器可以生成一个描述性的名称去与端口名称,你会发现那些WMI,Win32_SerialPort类。

Serial ports are very simple devices, dating from the stone age of computing hardware. They don't support Plug & Play, there is no way to tell that somebody plugged in a device. The only thing you can do is discover what ports are available, the SerialPort.GetPortNames() returns the list. Some USB emulators can generate a descriptive name to go with the port name, you can discover those with WMI, Win32_SerialPort class.

这没有帮助你发现什么COM端口连接到特定的设备。只有人知道,她身体上的连接器插入电缆。你需要提供一个配置用户界面,让用户选择的端口号。组合框能够完成任务。保存设置在你的配置数据,它的非常的可能设备仍然连接到你的程序下次启动时相同的端口。

None of which helps you discover what COM port is connected to a particular device. Only a human knows, she physically plugged the cable in the connector. You'll need to provide a config UI that lets the user select the port number. A combo box gets the job done. Save the selection in your config data, it is very likely that the device is still connected to the same port the next time your program starts.

这篇关于什么是检测在Windows上所有可用的串行端口正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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