public static Dictionary <string, NetPropertyDataModel> CreatePropertiesDictionary(this DeviceInformation info) { if (info != null) { return(NetPropertyHelpers.CreatePropertiesDictionary(info.Properties)); } return(new Dictionary <string, NetPropertyDataModel>()); }
public static NetPropertiesUpdateDataModel CreatePropertiesUpdateData(this DeviceInformationUpdate updateInfo) { NetPropertiesUpdateDataModel dm = new NetPropertiesUpdateDataModel() { Id = updateInfo.Id, ServiceProperties = NetPropertyHelpers.CreatePropertiesDictionary(updateInfo.Properties), }; return(dm); }
public void DiscoverSerialDevicesAsync() { Task.Run(async() => { try { DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(this.AQSForUSB); Stopwatch sw = new Stopwatch(); sw.Start(); List <SerialDeviceInfo> devices = new List <SerialDeviceInfo>(); // TODO - SerialDevice.FromIdAsync(deviceId). Except do not know if same ID as from DeviceInformation foreach (DeviceInformation info in infos) { this.DumpSerialDeviceInfo(info); try { // Device picks up Baud, Parity, Data and Stop bits when // set in the Arduino (see code sample). When left to // default in Arduino it does not show using (SerialDevice dev = await SerialDevice.FromIdAsync(info.Id)) { if (dev != null) { UsbDisplay display = new UsbDisplay(dev.UsbVendorId, dev.UsbProductId); SerialDeviceInfo device = new SerialDeviceInfo() { Id = info.Id, IsDefault = info.IsDefault, IsEnabled = info.IsEnabled, Display = info.Name, Properties = NetPropertyHelpers.CreatePropertiesDictionary(info.Properties), // Ignore pairing // Ignore enclosure location // Ignore Kind PortName = dev.PortName, Baud = dev.BaudRate, DataBits = dev.DataBits, StopBits = dev.StopBits.Convert(), Parity = dev.Parity.Convert(), ReadTimeout = dev.ReadTimeout, WriteTimeout = dev.WriteTimeout, DSR_DataSetReadyState = dev.DataSetReadyState, BytesReceivedOnLastInput = dev.BytesReceived, TX_BreakSignalEnabled = dev.BreakSignalState, CTS_IsClearToSendEnabled = dev.ClearToSendState, DTR_IsDataTerminalReady = dev.IsDataTerminalReadyEnabled, CD_CarrierDetectLineState = dev.CarrierDetectState, CTS_ClearToSendLineState = dev.ClearToSendState, USB_VendorId = dev.UsbVendorId, USB_ProductId = dev.UsbProductId, USB_VendorIdDisplay = display.Vendor, USB_ProductIdDisplay = display.Product, //USB_ProductIdDisplay = string.Format("0x{0:X}", dev.UsbProductId), //USB_VendorIdDisplay = string.Format("0x{0:X}", dev.UsbVendorId), RTS_IsRequesttoSendEnabled = dev.IsRequestToSendEnabled, FlowHandshake = dev.Handshake.Convert(), }; this.DumpSerialDevice(dev); #region USB code does not seem to work //// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/how-to-connect-to-a-usb-device--uwp-app- ////UsbDevice u = await UsbDevice.FromIdAsync(info.Id); ////string uaqs = UsbDevice.GetDeviceSelector(dev.UsbVendorId, dev.UsbProductId); ////string uaqs = UsbDevice.GetDeviceSelector(0x2341, 0x43); //UInt32 ven = 0x2341; //UInt32 prod = 0x43; //string uaqs = UsbDevice.GetDeviceSelector(ven, prod); //this.log.Error(7, () => string.Format("AQS:{0}", uaqs)); //var uDevs = await DeviceInformation.FindAllAsync(uaqs); //if (uDevs.Count > 0) { // this.log.Error(7, () => string.Format("USB ID:{0}", uDevs[0].Id)); // UsbDevice u = await UsbDevice.FromIdAsync(uDevs[0].Id); // this.DumpUsbDevice(u); //} //else { // this.log.Error(88, "NO USB DEVICE"); //} #endregion // Only bother to add if no exception on connection for more info devices.Add(device); } else { this.log.Error(9999, () => string.Format("Failed to retrieve :{0}", info.Name)); } }; } catch (Exception e) { this.log.Exception(2222, "", e); } } // For each sw.Stop(); this.log.Info("DoDiscovery", () => string.Format("**** Number Devices {0} *****", infos.Count)); this.log.Info("DoDiscovery", () => string.Format("**** Elapsed MS {0} *****", sw.ElapsedMilliseconds)); this.DiscoveredDevices?.Invoke(this, devices); } catch (Exception e) { this.log.Exception(1111, "", e); // TODO Add fields this.OnError.Invoke(this, new SerialUsbError()); } }); }