private void InitCmbBus() { List <DeviceBus> buses = new DeviceBusBLL(AppSettings.Current.ConnStr).GetItems(null).QueryObjects; if (buses != null && buses.Count > 0) { cmbBus.DataSource = buses; cmbBus.DisplayMember = "Name"; } }
private void InitCmbBus() { List<DeviceBus> buses = new DeviceBusBLL(AppSettings.Current.ConnStr).GetItems(null).QueryObjects; if (buses != null && buses.Count > 0) { cmbBus.DataSource = buses; cmbBus.DisplayMember = "Name"; } }
private void ReadValue_Thread() { try { bool hasRead = false; while (true) { DateTime dt = DateTime.Now; if (dt.Hour == 23) { if (!hasRead) { hasRead = true; var _Buses = new DeviceBusBLL(AppSettings.Current.ConnStr).GetItems(null).QueryObjects; var _Devices = (new DeviceBLL(AppSettings.Current.ConnStr)).GetItems(null).QueryObjects; if (_Buses == null || _Buses.Count == 0) { continue; } if (_Devices == null || _Devices.Count == 0) { continue; } foreach (var d in _Devices) { var bus = _Buses.SingleOrDefault(it => it.ID == d.Bus); if (bus != null) { decimal value = 0; var ret = DeviceBusService.Instance.ReadValue((byte)bus.Comport, d.Address, out value); if (ret == BusResult.Success) { new DeviceBLL(AppSettings.Current.ConnStr).AddReadLog(d.ID, DateTime.Now, value); } } } this.Invoke((Action)(() => { foreach (Form frm in _openedForms) //如果主页已经打开,刷新主页 { if (frm is FrmHome) { (frm as FrmHome).FreshData(); break; } } })); } } else { hasRead = false; } Thread.Sleep(60000); } } catch (ThreadAbortException) { } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } finally { _ReadValueThread = null; } }