Reputation: 37
I am trying to get the availability status from a PnP device I have read through this article: Win32_PnPEntity , and it seems like I should be able to get the value; however it always comes up null and I can't figure out why. Other properties like "Name", "Caption", "ClassGUID", etc are returning good values.
Here is some code showing what I'm trying to do...
using System.Management;
using var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE Description LIKE '%USB%'");
ManagementObjectCollection collection = searcher.Get();
Console.WriteLine("Waiting for CmdPort to be available...");
foreach (var device in collection)
{
var availableTimeout = 50;
var name = device["Name"];
Console.WriteLine($"Checking availability for: {name}");
while (availableTimeout > 0)
{
var availability = device["Availability"] ?? -1;
if ((int)availability == 3)
{
Console.WriteLine($"Device [{name}] is available");
break;
}
Console.WriteLine($"Availability = {availability} (timeout = {availableTimeout})");
availableTimeout--;
Thread.Sleep(100);
}
}
I'm expecting availability to come back with a uint16 between 1 and 21
Upvotes: 0
Views: 828