//相关命名空间
using System.IO.Ports;
using System.Management;
//相关全局变量
public static SerialPort Hcom = new SerialPort();
private uint HusbCount = 0;
private string HusbInfo = string.Empty;
//核心代码
if (!Hcom.IsOpen)
{
int portNum, HPortNum = 0,searcherNum=0;
string[] PortNames = SerialPort.GetPortNames();
string[] deviceName = new string[10];
string Hkey = "CP210X";
string HCom = null;
bool isContains = false;
Int32 numOfDevices = 0;
CP210x.GetNumDevices(ref numOfDevices);//CP210x连接数量
Console.WriteLine("GetNumDevices:" + numOfDevices);
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher
("select * from Win32_PnPEntity where Name like '%(COM%'"))
{
C# 识别USB设备,获取设备全称以及对应端口号 CP210X为例
最新推荐文章于 2024-03-29 17:39:25 发布