private void connectToReader() { try { if (!TagDataProvider.IsConnected) { Logging.Logger.Log("INFO", "READER NOT CONNECTED"); if (ReaderStatus == "CONNECTED") { Logging.Logger.Log("INFO", "READER CHANGE FROM CONNECTED TO DISCONNECTED"); } using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { var setting = dp.SettingsRepository.GetSettingWithDefault(BridgeSettingKeys.READER_HOST_NAME, "169.254.1.1"); TagDataProvider.SetHostName(setting); TagDataProvider.Connect(); //System.Threading.Thread.Sleep(1000); } } if (!TagDataProvider.IsConnected) { ReaderStatus = "DISCONNECTED"; } else { if (ReaderStatus == "DISCONNECTED") { Logging.Logger.Log("INFO", "READER RE-CONNECTED"); } ReaderStatus = "CONNECTED"; if (!readerTimeSet) { readerTimeSet = true; TagDataProvider.Stop(); TagDataProvider.SyncReaderTime(); //TagDataProvider.Disconnect(); } } if (TagDataProvider.IsConnected && !TagDataProvider.IsSingulating()) { System.Threading.Thread.Sleep(500); TagDataProvider.Start(0); if (!TagDataProvider.IsSingulating()) { TagDataProvider.Stop(); TagDataProvider.Disconnect(); } } } catch (Exception readerExc) { ReaderStatus = "ERROR"; Logging.Logger.Log(readerExc); } }
private void initialize() { if (vm == null) { vm = SimpleIoc.Default.GetInstance <NavViewModel>(); DataContext = vm; unlockSettingsControl.DataContext = vm; passwordModalControl.DataContext = vm; busyModal.DataContext = vm; } this.Visibility = Visibility.Visible; //check for gps offsett setting using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { var repo = dp.SettingsRepository; var offsetSetting = repo.FindSingle(s => s.Key == TruckClientSettingKeys.GPS_OFFSET_FEET); if (offsetSetting == null) { repo.UpsertSetting(TruckClientSettingKeys.GPS_OFFSET_FEET, "45"); GPSDataProvider.SetGpsOffsetFeet(45.0); } else { GPSDataProvider.SetGpsOffsetFeet(double.Parse(offsetSetting.Value)); } } if (!vm.HasCloudSettings) { MessageBox.Show("Data sync settings have not been configured. Please configure then restart the application."); navTabControl.SelectedIndex = 2; } else { Task.Run(() => { try { try { if (!TagDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Looking for RFID reader..." }); //System.Threading.Thread.Sleep(35000); int tryNumber = 1; do { //todo fix error hangs when no reader on rugged pc TagDataProvider.Connect(); tryNumber++; System.Threading.Thread.Sleep(3000); } while (tryNumber < 10 && !TagDataProvider.IsConnected); //Messenger.Default.Send<BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Connecting to RFID reader..." }); //TagDataProvider.Connect(); //System.Threading.Thread.Sleep(1400); } if (!TagDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Not connected to RFID Reader." }); System.Threading.Thread.Sleep(1200); } else { TagDataProvider.Stop(); Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "RFID Reader found." }); TagDataProvider.SyncReaderTime(); System.Threading.Thread.Sleep(1200); } } catch (Exception readerExc) { Logging.Logger.Log(readerExc); } Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Initializing shaft sensor..." }); QuadratureEncoderDataProvider.StartEvents(); System.Threading.Thread.Sleep(1000); if (!QuadratureEncoderDataProvider.IsStarted) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Shaft Sensor not found." }); System.Threading.Thread.Sleep(1200); } if (!GPSDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Connecting to GPS receiver..." }); Task.Run(() => { GPSDataProvider.Connect(); }); int waitCount = 0; while (waitCount < 60 && !GPSDataProvider.IsConnected) { System.Threading.Thread.Sleep(500); waitCount++; } if (GPSDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "GPS connected." }); System.Threading.Thread.Sleep(1000); } else { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "GPS not connected." }); System.Threading.Thread.Sleep(2000); } } Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = false, Message = "" }); TagDataProvider.Initialize(); AggregateDataProvider.Initialize(); CottonDBMS.TruckApp.Tasks.TruckPullFromCloudTask.Init(); readerSettingsControl.Initialize(); } catch (Exception exc) { CottonDBMS.Logging.Logger.Log(exc); } }); } navTabControl.Height = canvasLayout.ActualHeight; navTabControl.Width = canvasLayout.ActualWidth; modalBG.Height = canvasLayout.ActualHeight; modalBG.Width = canvasLayout.ActualWidth; }
private async void ExecuteSave() { Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = true, Message = "Validating settings..." }); if (!await ValidateForm()) { Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = false, Message = "" }); return; } Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = true, Message = "Saving..." }); await Task.Run(() => { try { Settings settings = TagDataProvider.GetDefaultSettings(); if (settings != null) { settings.Antennas.TxPowerMax = false; settings.Antennas.RxSensitivityMax = false; settings.HoldReportsOnDisconnect = false; settings.Report.Mode = ReportMode.Individual; settings.SearchMode = SearchMode.DualTarget; settings.ReaderMode = ReaderMode.AutoSetStaticDRM; settings.Report.IncludeFirstSeenTime = true; settings.Report.IncludeLastSeenTime = true; settings.Report.IncludeSeenCount = true; settings.Keepalives.Enabled = true; settings.Report.IncludePeakRssi = true; settings.Report.IncludePhaseAngle = true; settings.Report.IncludeAntennaPortNumber = true; settings.Keepalives.EnableLinkMonitorMode = true; settings.Keepalives.LinkDownThreshold = 5; settings.Keepalives.PeriodInMs = 3000; settings.Antennas.GetAntenna(1).RxSensitivityInDbm = (double)_antenna1ReceivePower; settings.Antennas.GetAntenna(1).TxPowerInDbm = (double)_antenna1TransmitPower; settings.Antennas.GetAntenna(2).RxSensitivityInDbm = (double)_antenna2ReceivePower; settings.Antennas.GetAntenna(2).TxPowerInDbm = (double)_antenna2TransmitPower; settings.Antennas.GetAntenna(3).RxSensitivityInDbm = (double)_antenna3ReceivePower; settings.Antennas.GetAntenna(3).TxPowerInDbm = (double)_antenna3TransmitPower; settings.Antennas.GetAntenna(4).RxSensitivityInDbm = (double)_antenna4ReceivePower; settings.Antennas.GetAntenna(4).TxPowerInDbm = (double)_antenna4TransmitPower; TagDataProvider.ApplySettings(settings); Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = true, Message = "Settings saved." }); System.Threading.Thread.Sleep(3000); } else { Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = true, Message = "Unable to save reader settings. Reader disconnected?" }); System.Threading.Thread.Sleep(3000); } using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { if (PortName == "NONE") { PortName = ""; } if (BarcodePortName == "NONE") { BarcodePortName = ""; } dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.SCALE_COM_PORT, PortName); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.BARCODE_COM_PORT, BarcodePortName); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.BRIDGE_ID, BridgeID); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.GIN_NAME, ScreenTitle); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.DOCUMENTDB_ENDPOINT, DocumentDbEndpoint); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.DOCUMENT_DB_KEY, DocumentDbConnection); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.LATITUDE, Latitude); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.LONGITUDE, Longitude); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.TARGET_STATUS, TargetStatus); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.DATA_SYNC_INTERVAL, DataSyncInterval.ToString()); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.WEIGH_IN_TIMEOUT, WeighInTimeout.ToString()); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.STABLE_WEIGHT_SECONDS, StableWeightSeconds.ToString()); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.WEIGHT_AUTO_SAVE_TIMEOUT, WeightAutoSaveTimeout.ToString()); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.UNATTENDED_MODE, UnattendedMode.ToString()); bool needsReaderDisconnect = false; if (_originalHost != ReaderHostname) { needsReaderDisconnect = true; dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.READER_HOST_NAME, ReaderHostname); } dp.SaveChanges(); if (needsReaderDisconnect) { Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = true, Message = "Reconnecting to " + ReaderHostname }); System.Threading.Thread.Sleep(1000); TagDataProvider.Disconnect(); TagDataProvider.SetHostName(ReaderHostname); TagDataProvider.Connect(); Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = false, Message = "Reader connected to " + ReaderHostname }); //shell should start the reader back up in 15-30 seconds } } /*if (portChanged) * { * System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => * { * System.Windows.MessageBox.Show("Please close and restart the application for new scale setting to take effect"); * })); * }*/ } catch (Exception exc) { System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { System.Windows.MessageBox.Show("An error occurred saving settings. " + exc.Message); })); Logging.Logger.Log(exc); } finally { Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = false, Message = "" }); Messenger.Default.Send <SettingsSavedMessage>(new SettingsSavedMessage { GinName = ScreenTitle, IsFirstLaunch = IsFirstLaunch }); } }); }