/// <summary>Update the values loaded from OS with saved parameters for that device</summary> /// <param name="index">The configuration index</param> /// <param name="item">The OS loaded device info to be updated</param> private void UpdateSerialFromCfg(List <IIndexItem <SerialIndexExtraInfo> > index, SerialDeviceInfo item) { var ndx = index.FirstOrDefault((i) => (i.ExtraInfoObj.PortName == item.PortName) && (i.ExtraInfoObj.USBProductId == item.USB_ProductId) && (i.ExtraInfoObj.USBVendorId == item.USB_VendorId)); if (ndx != null) { this.RetrieveSerialCfg(ndx, (cfg) => { item.Baud = cfg.Baud; item.DataBits = cfg.DataBits; item.StopBits = cfg.StopBits; item.Parity = cfg.Parity; item.FlowHandshake = cfg.FlowHandshake; item.ReadTimeout = cfg.ReadTimeout; item.WriteTimeout = cfg.WriteTimeout; item.HasCfg = true; }, (err) => { }); } }
public SerialIndexExtraInfo(SerialDeviceInfo info) { this.Update(info); }
private void PreSaveOps(SerialDeviceInfo data, IIndexItem <SerialIndexExtraInfo> idx) { this.Validate5msReadWrite(data, data); idx.ExtraInfoObj.Update(data); }
private void Validate5msReadWrite(SerialDeviceInfo target, SerialDeviceInfo source) { target.ReadTimeout = this.ForceTo5msIf0(source.ReadTimeout); target.WriteTimeout = this.ForceTo5msIf0(source.WriteTimeout); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { SerialDeviceInfo info = this.lbUsb.SelectedItem as SerialDeviceInfo; DI.Wrapper.DeleteSerialCfg(info, this.DeleteDecision, this.ReloadList, App.ShowMsg); }
public void CreateNewSerialCfg(string display, SerialDeviceInfo data, Action <IIndexItem <SerialIndexExtraInfo> > onSuccess, OnErr onError) { this.Validate5msReadWrite(data, data); this.Create(display, data, this.serialStorage, onSuccess, onError, new SerialIndexExtraInfo(data)); }
private void Wrapper_OnSerialConfigRequestHandler(object sender, SerialDeviceInfo e) { this.Dispatcher.Invoke(() => { DeviceEdit_USB.ShowBox(this, e); }); }
private void OnConnectError(string err) { this.ui.IsBusy = false; App.ShowMsg(err); this.selectedSerial = null; }
private void OnUiDisconnect(object sender, EventArgs e) { DI.Wrapper.SerialUsbDisconnect(); this.selectedSerial = null; }
public static void ShowBox(Window parent, SerialDeviceInfo info) { DeviceInfo_USB win = new DeviceInfo_USB(parent, info); win.ShowDialog(); }
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()); } }); }