usb.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Management;
  6. using System.Text.RegularExpressions;
  7. using System.Windows.Forms;
  8. namespace HXX.Scanner.Biz
  9. {
  10. /// <summary>
  11. /// 即插即用设备信息结构
  12. /// </summary>
  13. public struct PnPEntityInfo
  14. {
  15. public String PNPDeviceID; // 设备ID
  16. public String Name; // 设备名称
  17. public String Description; // 设备描述
  18. public String Service; // 服务
  19. public String Status; // 设备状态
  20. public UInt16 VendorID; // 供应商标识
  21. public UInt16 ProductID; // 产品编号
  22. public Guid ClassGuid; // 设备安装类GUID
  23. }
  24. /// <summary>
  25. /// 基于WMI获取USB设备信息
  26. /// </summary>
  27. public partial class USB
  28. {
  29. #region UsbDevice
  30. /// <summary>
  31. /// 获取所有的USB设备实体(过滤没有VID和PID的设备)
  32. /// </summary>
  33. public static PnPEntityInfo[] AllUsbDevices
  34. {
  35. get
  36. {
  37. return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, Guid.Empty);
  38. }
  39. }
  40. /// <summary>
  41. /// 查询USB设备实体(设备要求有VID和PID)
  42. /// </summary>
  43. /// <param name="VendorID">供应商标识,MinValue忽视</param>
  44. /// <param name="ProductID">产品编号,MinValue忽视</param>
  45. /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
  46. /// <returns>设备列表</returns>
  47. public static int numb;//统计usb设备数量
  48. public static PnPEntityInfo[] WhoUsbDevice(UInt16 VendorID, UInt16 ProductID, Guid ClassGuid)
  49. {
  50. numb = 0;
  51. List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();
  52. // 获取USB控制器及其相关联的设备实体
  53. ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
  54. if (USBControllerDeviceCollection != null)
  55. {
  56. foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
  57. { // 获取设备实体的DeviceID
  58. String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];
  59. // 过滤掉没有VID和PID的USB设备
  60. Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  61. if (match.Success)
  62. {
  63. UInt16 theVendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  64. if (VendorID != UInt16.MinValue && VendorID != theVendorID) continue;
  65. UInt16 theProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
  66. if (ProductID != UInt16.MinValue && ProductID != theProductID) continue;
  67. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
  68. if (PnPEntityCollection != null)
  69. {
  70. foreach (ManagementObject Entity in PnPEntityCollection)
  71. {
  72. //Guid theClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  73. //if (ClassGuid != Guid.Empty && ClassGuid != theClassGuid) continue;
  74. PnPEntityInfo Element;
  75. Element.PNPDeviceID = Entity["PNPDeviceID"] as String; // 设备ID
  76. Element.Name = Entity["Name"] as String; // 设备名称
  77. Element.Description = Entity["Description"] as String; // 设备描述
  78. Element.Service = Entity["Service"] as String; // 服务
  79. Element.Status = Entity["Status"] as String; // 设备状态
  80. Element.VendorID = theVendorID; // 供应商标识
  81. Element.ProductID = theProductID; // 产品编号
  82. Element.ClassGuid = Guid.Empty;//theClassGuid; // 设备安装类GUID
  83. UsbDevices.Add(Element);
  84. numb = numb + 1;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. if (UsbDevices.Count == 0) return null; else return UsbDevices.ToArray();
  91. }
  92. //检测USB设备是否存在
  93. public static bool USB_Is_On(string usb_name, UInt16 usb_vid, UInt16 usb_pid)
  94. {
  95. UInt16 VendorID = 0;
  96. UInt16 ProductID = 0;
  97. Guid ClassGuid = Guid.Empty;
  98. bool Result = false;
  99. // 获取USB控制器及其相关联的设备实体
  100. ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
  101. if (USBControllerDeviceCollection != null)
  102. {
  103. foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
  104. { // 获取设备实体的DeviceID
  105. String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];
  106. // 过滤掉没有VID和PID的USB设备
  107. Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  108. if (match.Success)
  109. {
  110. UInt16 theVendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  111. if (VendorID != UInt16.MinValue && VendorID != theVendorID) continue;
  112. UInt16 theProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
  113. if (ProductID != UInt16.MinValue && ProductID != theProductID) continue;
  114. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
  115. if (PnPEntityCollection != null)
  116. {
  117. foreach (ManagementObject Entity in PnPEntityCollection)
  118. {
  119. //Guid theClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  120. //if (ClassGuid != Guid.Empty && ClassGuid != theClassGuid) continue;
  121. PnPEntityInfo Element;
  122. //Element.PNPDeviceID = Entity["PNPDeviceID"] as String; // 设备ID
  123. Element.Name = Entity["Name"] as String; // 设备名称
  124. //Element.Description = Entity["Description"] as String; // 设备描述
  125. //Element.Service = Entity["Service"] as String; // 服务
  126. //Element.Status = Entity["Status"] as String; // 设备状态
  127. Element.VendorID = theVendorID; // 供应商标识
  128. Element.ProductID = theProductID; // 产品编号
  129. //Element.ClassGuid = theClassGuid; // 设备安装类GUID
  130. if ((Element.Name == usb_name) && (Element.VendorID == usb_vid) && (Element.ProductID == usb_pid))
  131. {
  132. Result = true;
  133. return Result;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. return Result;
  141. }
  142. /// <summary>
  143. /// 查询USB设备实体(设备要求有VID和PID)
  144. /// </summary>
  145. /// <param name="VendorID">供应商标识,MinValue忽视</param>
  146. /// <param name="ProductID">产品编号,MinValue忽视</param>
  147. /// <returns>设备列表</returns>
  148. public static PnPEntityInfo[] WhoUsbDevice(UInt16 VendorID, UInt16 ProductID)
  149. {
  150. return WhoUsbDevice(VendorID, ProductID, Guid.Empty);
  151. }
  152. /// <summary>
  153. /// 查询USB设备实体(设备要求有VID和PID)
  154. /// </summary>
  155. /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
  156. /// <returns>设备列表</returns>
  157. public static PnPEntityInfo[] WhoUsbDevice(Guid ClassGuid)
  158. {
  159. return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, ClassGuid);
  160. }
  161. /// <summary>
  162. /// 查询USB设备实体(设备要求有VID和PID)
  163. /// </summary>
  164. /// <param name="PNPDeviceID">设备ID,可以是不完整信息</param>
  165. /// <returns>设备列表</returns>
  166. public static PnPEntityInfo[] WhoUsbDevice(String PNPDeviceID)
  167. {
  168. List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();
  169. // 获取USB控制器及其相关联的设备实体
  170. ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
  171. if (USBControllerDeviceCollection != null)
  172. {
  173. foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
  174. { // 获取设备实体的DeviceID
  175. String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];
  176. if (!String.IsNullOrEmpty(PNPDeviceID))
  177. { // 注意:忽视大小写
  178. if (Dependent.IndexOf(PNPDeviceID, 1, PNPDeviceID.Length - 2, StringComparison.OrdinalIgnoreCase) == -1) continue;
  179. }
  180. // 过滤掉没有VID和PID的USB设备
  181. Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  182. if (match.Success)
  183. {
  184. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
  185. if (PnPEntityCollection != null)
  186. {
  187. foreach (ManagementObject Entity in PnPEntityCollection)
  188. {
  189. PnPEntityInfo Element;
  190. Element.PNPDeviceID = Entity["PNPDeviceID"] as String; // 设备ID
  191. Element.Name = Entity["Name"] as String; // 设备名称
  192. Element.Description = Entity["Description"] as String; // 设备描述
  193. Element.Service = Entity["Service"] as String; // 服务
  194. Element.Status = Entity["Status"] as String; // 设备状态
  195. Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  196. Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号 // 产品编号
  197. Element.ClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  198. UsbDevices.Add(Element);
  199. }
  200. }
  201. }
  202. }
  203. }
  204. if (UsbDevices.Count == 0) return null; else return UsbDevices.ToArray();
  205. }
  206. /// <summary>
  207. /// 根据服务定位USB设备
  208. /// </summary>
  209. /// <param name="ServiceCollection">要查询的服务集合</param>
  210. /// <returns>设备列表</returns>
  211. public static PnPEntityInfo[] WhoUsbDevice(String[] ServiceCollection)
  212. {
  213. if (ServiceCollection == null || ServiceCollection.Length == 0)
  214. return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, Guid.Empty);
  215. List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();
  216. // 获取USB控制器及其相关联的设备实体
  217. ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();
  218. if (USBControllerDeviceCollection != null)
  219. {
  220. foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)
  221. { // 获取设备实体的DeviceID
  222. String Dependent = (USBControllerDevice["Dependent"] as String).Split(new Char[] { '=' })[1];
  223. // 过滤掉没有VID和PID的USB设备
  224. Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  225. if (match.Success)
  226. {
  227. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();
  228. if (PnPEntityCollection != null)
  229. {
  230. foreach (ManagementObject Entity in PnPEntityCollection)
  231. {
  232. String theService = Entity["Service"] as String; // 服务
  233. if (String.IsNullOrEmpty(theService)) continue;
  234. foreach (String Service in ServiceCollection)
  235. { // 注意:忽视大小写
  236. if (String.Compare(theService, Service, true) != 0) continue;
  237. PnPEntityInfo Element;
  238. Element.PNPDeviceID = Entity["PNPDeviceID"] as String; // 设备ID
  239. Element.Name = Entity["Name"] as String; // 设备名称
  240. Element.Description = Entity["Description"] as String; // 设备描述
  241. Element.Service = theService; // 服务
  242. Element.Status = Entity["Status"] as String; // 设备状态
  243. Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  244. Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
  245. Element.ClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  246. UsbDevices.Add(Element);
  247. break;
  248. }
  249. }
  250. }
  251. }
  252. }
  253. }
  254. if (UsbDevices.Count == 0) return null; else return UsbDevices.ToArray();
  255. }
  256. #endregion
  257. #region PnPEntity
  258. /// <summary>
  259. /// 所有即插即用设备实体(过滤没有VID和PID的设备)
  260. /// </summary>
  261. public static PnPEntityInfo[] AllPnPEntities
  262. {
  263. get
  264. {
  265. return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, Guid.Empty);
  266. }
  267. }
  268. /// <summary>
  269. /// 根据VID和PID及设备安装类GUID定位即插即用设备实体
  270. /// </summary>
  271. /// <param name="VendorID">供应商标识,MinValue忽视</param>
  272. /// <param name="ProductID">产品编号,MinValue忽视</param>
  273. /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
  274. /// <returns>设备列表</returns>
  275. /// <remarks>
  276. /// HID:{745a17a0-74d3-11d0-b6fe-00a0c90f57da}
  277. /// Imaging Device:{6bdd1fc6-810f-11d0-bec7-08002be2092f}
  278. /// Keyboard:{4d36e96b-e325-11ce-bfc1-08002be10318}
  279. /// Mouse:{4d36e96f-e325-11ce-bfc1-08002be10318}
  280. /// Network Adapter:{4d36e972-e325-11ce-bfc1-08002be10318}
  281. /// USB:{36fc9e60-c465-11cf-8056-444553540000}
  282. /// </remarks>
  283. public static PnPEntityInfo[] WhoPnPEntity(UInt16 VendorID, UInt16 ProductID, Guid ClassGuid)
  284. {
  285. List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();
  286. // 枚举即插即用设备实体
  287. String VIDPID;
  288. if (VendorID == UInt16.MinValue)
  289. {
  290. if (ProductID == UInt16.MinValue)
  291. VIDPID = "'%VID[_]____&PID[_]____%'";
  292. else
  293. VIDPID = "'%VID[_]____&PID[_]" + ProductID.ToString("X4") + "%'";
  294. }
  295. else
  296. {
  297. if (ProductID == UInt16.MinValue)
  298. VIDPID = "'%VID[_]" + VendorID.ToString("X4") + "&PID[_]____%'";
  299. else
  300. VIDPID = "'%VID[_]" + VendorID.ToString("X4") + "&PID[_]" + ProductID.ToString("X4") + "%'";
  301. }
  302. String QueryString;
  303. if (ClassGuid == Guid.Empty)
  304. QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE" + VIDPID;
  305. else
  306. QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE" + VIDPID + " AND ClassGuid='" + ClassGuid.ToString("B") + "'";
  307. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();
  308. if (PnPEntityCollection != null)
  309. {
  310. foreach (ManagementObject Entity in PnPEntityCollection)
  311. {
  312. try
  313. {
  314. String PNPDeviceID = Entity["PNPDeviceID"] as String;
  315. Match match = Regex.Match(PNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  316. if (match.Success)
  317. {
  318. PnPEntityInfo Element;
  319. Element.PNPDeviceID = PNPDeviceID; // 设备ID
  320. Element.Name = Entity["Name"] as String; // 设备名称
  321. Element.Description = Entity["Description"] as String; // 设备描述
  322. Element.Service = Entity["Service"] as String; // 服务
  323. Element.Status = Entity["Status"] as String; // 设备状态
  324. Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  325. Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
  326. Element.ClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  327. PnPEntities.Add(Element);
  328. }
  329. }
  330. catch { }
  331. }
  332. }
  333. if (PnPEntities.Count == 0) return null; else return PnPEntities.ToArray();
  334. }
  335. /// <summary>
  336. /// 根据VID和PID定位即插即用设备实体
  337. /// </summary>
  338. /// <param name="VendorID">供应商标识,MinValue忽视</param>
  339. /// <param name="ProductID">产品编号,MinValue忽视</param>
  340. /// <returns>设备列表</returns>
  341. public static PnPEntityInfo[] WhoPnPEntity(UInt16 VendorID, UInt16 ProductID)
  342. {
  343. return WhoPnPEntity(VendorID, ProductID, Guid.Empty);
  344. }
  345. /// <summary>
  346. /// 根据设备安装类GUID定位即插即用设备实体
  347. /// </summary>
  348. /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>
  349. /// <returns>设备列表</returns>
  350. public static PnPEntityInfo[] WhoPnPEntity(Guid ClassGuid)
  351. {
  352. return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, ClassGuid);
  353. }
  354. /// <summary>
  355. /// 根据设备ID定位设备
  356. /// </summary>
  357. /// <param name="PNPDeviceID">设备ID,可以是不完整信息</param>
  358. /// <returns>设备列表</returns>
  359. /// <remarks>
  360. /// 注意:对于下划线,需要写成“[_]”,否则视为任意字符
  361. /// </remarks>
  362. public static PnPEntityInfo[] WhoPnPEntity(String PNPDeviceID)
  363. {
  364. List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();
  365. // 枚举即插即用设备实体
  366. String QueryString;
  367. if (String.IsNullOrEmpty(PNPDeviceID))
  368. {
  369. QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%VID[_]____&PID[_]____%'";
  370. }
  371. else
  372. { // LIKE子句中有反斜杠字符将会引发WQL查询异常
  373. QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%" + PNPDeviceID.Replace('\\', '_') + "%'";
  374. }
  375. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();
  376. if (PnPEntityCollection != null)
  377. {
  378. foreach (ManagementObject Entity in PnPEntityCollection)
  379. {
  380. String thePNPDeviceID = Entity["PNPDeviceID"] as String;
  381. Match match = Regex.Match(thePNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  382. if (match.Success)
  383. {
  384. PnPEntityInfo Element;
  385. Element.PNPDeviceID = thePNPDeviceID; // 设备ID
  386. Element.Name = Entity["Name"] as String; // 设备名称
  387. Element.Description = Entity["Description"] as String; // 设备描述
  388. Element.Service = Entity["Service"] as String; // 服务
  389. Element.Status = Entity["Status"] as String; // 设备状态
  390. Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  391. Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
  392. Element.ClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  393. PnPEntities.Add(Element);
  394. }
  395. }
  396. }
  397. if (PnPEntities.Count == 0) return null; else return PnPEntities.ToArray();
  398. }
  399. /// <summary>
  400. /// 根据服务定位设备
  401. /// </summary>
  402. /// <param name="ServiceCollection">要查询的服务集合,null忽视</param>
  403. /// <returns>设备列表</returns>
  404. /// <remarks>
  405. /// 跟服务相关的类:
  406. /// Win32_SystemDriverPNPEntity
  407. /// Win32_SystemDriver
  408. /// </remarks>
  409. public static PnPEntityInfo[] WhoPnPEntity(String[] ServiceCollection)
  410. {
  411. if (ServiceCollection == null || ServiceCollection.Length == 0)
  412. return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, Guid.Empty);
  413. List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();
  414. // 枚举即插即用设备实体
  415. String QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%VID[_]____&PID[_]____%'";
  416. ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();
  417. if (PnPEntityCollection != null)
  418. {
  419. foreach (ManagementObject Entity in PnPEntityCollection)
  420. {
  421. String PNPDeviceID = Entity["PNPDeviceID"] as String;
  422. Match match = Regex.Match(PNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");
  423. if (match.Success)
  424. {
  425. String theService = Entity["Service"] as String; // 服务
  426. if (String.IsNullOrEmpty(theService)) continue;
  427. foreach (String Service in ServiceCollection)
  428. { // 注意:忽视大小写
  429. if (String.Compare(theService, Service, true) != 0) continue;
  430. PnPEntityInfo Element;
  431. Element.PNPDeviceID = PNPDeviceID; // 设备ID
  432. Element.Name = Entity["Name"] as String; // 设备名称
  433. Element.Description = Entity["Description"] as String; // 设备描述
  434. Element.Service = theService; // 服务
  435. Element.Status = Entity["Status"] as String; // 设备状态
  436. Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16); // 供应商标识
  437. Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号
  438. Element.ClassGuid = new Guid(Entity["ClassGuid"] as String); // 设备安装类GUID
  439. PnPEntities.Add(Element);
  440. break;
  441. }
  442. }
  443. }
  444. }
  445. if (PnPEntities.Count == 0) return null; else return PnPEntities.ToArray();
  446. }
  447. #endregion
  448. }
  449. }