private void ReadPV_Thread() { try { while (_Running) { Thread.Sleep(AppSettings.Current.RealInterval); if (HartDevice != null && HartDevice.IsConnected) { DeviceVariable pv = HartDevice.ReadPV(false); if (pv != null && _Running) { this.Invoke((Action)(() => { _PV = pv; txtReal.Text = pv.Value.ToString(); } )); } } } } catch (ThreadAbortException) { } catch (Exception) { } finally { _ReadPV = null; } }
private void button2_Click(object sender, EventArgs e) { DeviceVariable pv = HartDevice.ReadPV(false); if (pv != null) { txtUpper.Text = pv.Value.ToString(); } }
public void Destroy() { #if DEBUG if (Index == _badDispose) { Debugger.Break(); } #endif if (!_disposed) { DeviceVariable.Dispose(); _disposed = true; } #if DEBUG GC.SuppressFinalize(this); #endif }
private void ReadPV_Thread() { try { while (_Running) { if (HartDevice == null || !HartDevice.IsConnected) { this.Invoke((Action)(() => { btnRealTime.Text = "实时采集"; })); _ReadPV = null; return; } DeviceVariable pv = HartDevice.ReadPV(false); CurrentInfo ci = HartDevice.ReadCurrent(false); Action a = delegate() { if (pv != null) { lblPVUnit.Text = pv != null?UnitCodeDescr.GetDescr(pv.UnitCode) : null; txtPV.Text = pv != null?pv.Value.ToString() : string.Empty; } if (ci != null) { txtCurrent.Text = ci != null?ci.Current.ToString() : string.Empty; txtPercentOfRange.Text = ci != null?ci.PercentOfRange.ToString() : string.Empty; } }; this.Invoke(a); } } catch (ThreadAbortException) { } catch (Exception) { } finally { _ReadPV = null; } }