/// 更新点表, 用于读取返回. bool UpdateFunctionTableByZone(Zone _z) { // 更新 区域信息. // 0x01 0~6 通讯故障 // 更新 主控. int totalOpened = 0, totalCnt = 0, errorCnt = 0; foreach (Zone z in _zones) { totalOpened += z.OpenCnt; totalCnt += z.TotalCnt; errorCnt += z.HasException? 1:0; } bool isTotalOpen = totalOpened >= totalCnt / 2; // 全区域异常: _ptable.SetValueAt(REG_SUMMARY, 0, errorCnt > 0); // 当前区域异常. _ptable.SetValueAt(REG_SUMMARY, _z.Reg.ZoneCoil, _z.HasException); // 当前区域状态 _ptable.SetValueAt(REG_ZONE_SUMMARY, _z.Reg.ZoneCoil, _z.IsZoneOpen()); // 全区域开? _ptable.SetValueAt(REG_ZONE_SUMMARY, 6, isTotalOpen); return isTotalOpen; }
private void _OnZoneStateChanged(Zone _z, bool allOn) { bool isTotalOpen = UpdateFunctionTableByZone(_z); // 设置 中控 输出. lock (_ccs) { try { JDQRequest req1 = new JDQRequest(1, JDQRequestType.SetOutput); // Read FAS/IBP req1.SetOutput(_z.Reg.ZoneCoil, _z.IsZoneOpen()); req1.SetOutput(6, isTotalOpen); // 全区域. SocketError err; byte[] recv = _ccs.SSend(req1.Encode(), out err, 500); } catch (Exception) { } } if (this.OnZoneStateChanged != null) { OnZoneStateChanged.Invoke(_z, isTotalOpen); // 发出通知. } }
// 区域状态变化回调 private void OnZoneStateChanged(Zone z, bool totalOn) { DataGridViewRow zi = _zoneRows[z.Name]; if (zi != null) { UpdateRowImg(zi, Properties.Resources.green_24); UpdateRowText(zi, ViewColumns.NAME, z.Name + "(" + z.Statistics + ")"); Label li; if (z.Reg.ZoneCoil == 0) li = lb_z1; else if (z.Reg.ZoneCoil == 1) li = lb_z2; else if (z.Reg.ZoneCoil == 2) li = lb_z3; else if (z.Reg.ZoneCoil == 3) li = lb_z4; else if (z.Reg.ZoneCoil == 4) li = lb_z5; else li = lb_z6; this.UpdateLabelImg(li, z.IsZoneOpen() ? OnOff.ON : OnOff.OFF); this.UpdateLabelImg(lb_z_all, totalOn ? OnOff.ON : OnOff.OFF); } }