/// <summary> /// Create a new powermeter. /// Check if the powermeter has a valid IP. If no IP is set, launch the settings menu, else start the connection. /// Once the connection is available check if the sensors are connected /// </summary> private void CreateMeter() { #region withoutThread #endregion withoutThread //bool b =await awaitablecommando(....); //await Task.Run(mijnmethodedieikopeenanderethreadwiluitvoeren); System.Threading.ThreadPool.QueueUserWorkItem( o => { DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Debug(_logTarget + "Creating new PowerMeter"); }); Pwr = new PowerMeterModel(); Pwr.Ip = SetIP(); Pwr.TimeOut = SetTimeout(); //Launch settings window if no IP is available if (Pwr.VisaAddress == null) { DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Warn(_logTarget + "IP for PowerMeter not set!"); }); Messenger.Default.Send(new NotificationMessage(Messages.Messages.SETTINGSIP_LAUNCH)); } //Start connection if IP is available else { try { Pwr.StartConnection(); DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Debug(_logTarget + "Connection successful"); }); } catch (Exception ex) { DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Error(_logTarget + "Connection failed: {0}" + ex.Message, ex); }); return; } } //are sensors connected try { Pwr.GetChannelStatusDescription(); } catch (Exception ex) { DispatcherHelper.CheckBeginInvokeOnUI(() => { _log.Error(_logTarget + "GetChannelStatus failed: " + ex.Message, ex); }); } } ); }
/// <summary> /// Reset the meter, and close the connection with the device /// </summary> private void CloseMeter() { if (Pwr != null) { Pwr.CloseConnestion(); Pwr = null; } }