示例#1
0
        public static List <USBDeviceInfo> QueryConnectedArduinoDevices()
        {
            //Create a list to hold information from USB devices
            List <USBDeviceInfo> devices = new List <USBDeviceInfo>();

            //Query all connected devices
            var searcher   = new ManagementObjectSearcher(@"SELECT * FROM WIN32_SerialPort");
            var collection = searcher.Get();

            //Grab the information we need
            foreach (var device in collection)
            {
                string        id   = (string)device.GetPropertyValue("DeviceID");
                string        desc = (string)device.GetPropertyValue("Description");
                USBDeviceInfo d    = new USBDeviceInfo(desc, id, false);

                //Check to see if the available serial port is a connected Arduino device
                if (d.Description.Contains("Arduino"))
                {
                    //If so, add the Arduino to our list of devices
                    devices.Add(d);
                }
            }

            //Dispose of the collection of queried devices
            collection.Dispose();

            //Return the list of devices that were found
            return(devices);
        }
示例#2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="model"></param>
 public USBDeviceViewModel(USBDeviceInfo model)
 {
     _model = model;
 }