// This is called when NurApi is fully connected to device and ready to communicate private async void Api_ConnectedEvent(object sender, NurApi.NurEventArgs e) { System.Diagnostics.Debug.WriteLine("Api_ConnectedEvent"); NurApi connApi = sender as NurApi; App.NurApi = connApi; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { NurDeviceWatcherInfo knownDev = connApi.UserData as NurDeviceWatcherInfo; // Save connect spec to settings //mLocalSettings.Values["devicespec"] = DeviceSpecStr; mLocalSettings.Values["devicespec"] = knownDev.SpecStr; // Update listview entry knownDev.ConnState = NurApiTransport.State.Connected; knownDev.UpdateInfo(); if (knownDev == SelectedDev) { ConnButtonText = "Disconnect"; } }); // Update reader info await Task.Run(async() => { try { NurApi.ReaderInfo rdrInfo = App.NurApi.GetReaderInfo(); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ConnInfo = string.Format("Connected {0} | Serial {1} | FW {2}", rdrInfo.name, rdrInfo.serial, rdrInfo.GetVersionString()); }); } catch (Exception ex) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { ConnInfo = "Error"; await App.ShowException(ex); }); } }); }
private async void Api_ConnectedEvent(object sender, NurApi.NurEventArgs e) { NurApi.AccessoryFWInfo?accFwInfo = null; string connInfo = ""; try { // Get accessory device info await Task.Run(() => { accFwInfo = App.NurApi.AccGetFwInfo(); connInfo = App.NurApi.AccGetConnectionInfo(); }); } catch (Exception ex) { if (ex is NurApiException && (ex as NurApiException).error == NurApiErrors.NUR_ERROR_INVALID_COMMAND) { // This is not accessory device accFwInfo = null; } else { await App.ShowException(ex); return; } } // Update UI await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ButtonState = true; if (accFwInfo != null) { AccInfo = string.Format("Accessory FW version: {0}; Connection info: {1}", accFwInfo?.FullAppVersion, connInfo); } else { AccInfo = "Connected device does not support accessory device commands"; } }); }