static List <USBDeviceInfo> GetSTM32F4USBDevices(STM32_USB_Interface_type type) { lock (crit_sec_lock) { List <USBDeviceInfo> devices = new List <USBDeviceInfo>(); ManagementObjectSearcher searcher = (ManagementObjectSearcher)null; if (type == STM32_USB_Interface_type.VCP) { searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort"); } else { searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"); } foreach (var device in searcher.Get()) { try { USBDeviceInfo devInfo = new USBDeviceInfo( (string)device.GetPropertyValue("DeviceID"), (string)device.GetPropertyValue("PNPDeviceID"), (string)device.GetPropertyValue("Description"), (string)device.GetPropertyValue("Name"), (string)device.GetPropertyValue("Caption") ); if (type == STM32_USB_Interface_type.VCP) { if (devInfo.PnpDeviceID.Contains("VID_0483") && /* ST Microelectronics */ devInfo.PnpDeviceID.Contains("PID_5740") /* STM32F407 */ ) { devices.Add(devInfo); } } if (type == STM32_USB_Interface_type.DFU) { if (devInfo.PnpDeviceID.Contains("VID_0483") && /* ST Microelectronics */ devInfo.PnpDeviceID.Contains("PID_DF11") /* STM Device in DFU Mode */ ) { devices.Add(devInfo); } } } catch (Exception ex) { string s = ex.Message; } } return(devices); } }
static List<USBDeviceInfo> GetSTM32F4USBDevices(STM32_USB_Interface_type type) { lock (crit_sec_lock) { List<USBDeviceInfo> devices = new List<USBDeviceInfo>(); ManagementObjectSearcher searcher = (ManagementObjectSearcher)null; if (type == STM32_USB_Interface_type.VCP) { searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort"); } else { searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"); } foreach (var device in searcher.Get()) { try { USBDeviceInfo devInfo = new USBDeviceInfo( (string)device.GetPropertyValue("DeviceID"), (string)device.GetPropertyValue("PNPDeviceID"), (string)device.GetPropertyValue("Description"), (string)device.GetPropertyValue("Name"), (string)device.GetPropertyValue("Caption") ); if (type == STM32_USB_Interface_type.VCP) { if (devInfo.PnpDeviceID.Contains("VID_0483") && /* ST Microelectronics */ devInfo.PnpDeviceID.Contains("PID_5740") /* STM32F407 */ ) { devices.Add(devInfo); } } if (type == STM32_USB_Interface_type.DFU) { if (devInfo.PnpDeviceID.Contains("VID_0483") && /* ST Microelectronics */ devInfo.PnpDeviceID.Contains("PID_DF11") /* STM Device in DFU Mode */ ) { devices.Add(devInfo); } } } catch (Exception ex) { string s = ex.Message; } } return devices; } }