private PeakHelper(PcanHelper pcan) { this.hasData = false; this.AllValue = new double[51]; this.pcanhelper = pcan; try { pcan.initialize(); TPCANStatus result = pcan.setValue(); } catch (Exception ex) { MessageBox.Show("控制器初始化出错" + ex.Message); } //后台每隔一段时间读取一次数据 this.readTimer = new System.Threading.Timer(_ => { try { ReadAllReadableValues(); } catch (Exception ex) { readTimer.Change(Timeout.Infinite, Timeout.Infinite); hasData = false; System.Windows.Forms.MessageBox.Show("PEAKHelper读数据出错"); } }, null, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// 初始化peakhelper,使用 pcanhelper /// </summary> /// <param name="pcan"></param> /// <returns></returns> public static PeakHelper Initialize(PcanHelper pcan) { if (instance != null) { throw new Exception("peakHelper重复初始化报错"); } instance = new PeakHelper(pcan); return(instance); }
/// <summary> /// 公有方法获取单例 /// </summary> /// <returns></returns> public static PcanHelper GetInstance() { if (instance == null) { lock (syncRoot) { if (syncRoot == null) { instance = new PcanHelper(); } } } return(instance); }