private void InitUsbScaleList() { var scales = new List <ScaleDevice>(); scales.Add(new ScaleDevice { Description = "<Not configured>" }); foreach (var device in HidDevices.Enumerate()) { scales.Add(new ScaleDevice { Description = device.Description, VendorId = device.Attributes.VendorId, ProductId = device.Attributes.ProductId }); } var currentDevice = scales.FirstOrDefault(s => s.VendorId == Properties.Settings.Default.ScaleDeviceVendorId && s.ProductId == Properties.Settings.Default.ScaleDeviceProductId); if (currentDevice == null) { currentDevice = new ScaleDevice { Description = String.Format(Strings.UnknownDeviceDescription, Properties.Settings.Default.ScaleDeviceVendorId, Properties.Settings.Default.ScaleDeviceProductId), VendorId = Properties.Settings.Default.ScaleDeviceVendorId, ProductId = Properties.Settings.Default.ScaleDeviceProductId }; scales.Add(currentDevice); } scalesDropDown.DisplayMember = "Description"; scalesDropDown.DataSource = scales; scalesDropDown.SelectedItem = currentDevice; }
private void InitUsbScaleList() { const short scaleDataReport = 32; var scales = new List <ScaleDevice>(); scales.Add(new ScaleDevice { Description = "<Not configured>" }); foreach (var device in HidDevices.Enumerate()) { // Keep only devices supporting Scale Data Report if (showAllDevicesCheckBox.Checked || device.Capabilities.Usage.Equals(scaleDataReport) || (device.Attributes.VendorId.Equals(Properties.Settings.Default.ScaleDeviceVendorId) && device.Attributes.ProductId.Equals(Properties.Settings.Default.ScaleDeviceProductId))) { scales.Add(new ScaleDevice { Description = GetDeviceDescriptionFromDeviceDriver(device), VendorId = device.Attributes.VendorId, ProductId = device.Attributes.ProductId }); } } var currentDevice = scales.FirstOrDefault(s => s.VendorId == Properties.Settings.Default.ScaleDeviceVendorId && s.ProductId == Properties.Settings.Default.ScaleDeviceProductId); if (currentDevice == null) { int vendorId = Properties.Settings.Default.ScaleDeviceVendorId; int productId = Properties.Settings.Default.ScaleDeviceProductId; string description = GetDeviceDescriptionFromStaticList(vendorId, productId); currentDevice = new ScaleDevice { Description = description != null ? description : String.Format(Strings.UnknownDeviceDescription, vendorId, productId), VendorId = Properties.Settings.Default.ScaleDeviceVendorId, ProductId = Properties.Settings.Default.ScaleDeviceProductId }; scales.Add(currentDevice); } scalesDropDown.DisplayMember = "Description"; scalesDropDown.DataSource = scales; scalesDropDown.SelectedItem = currentDevice; }