/// <summary> /// 监控寄存器的值 /// </summary> /// <param name="timeout">查询的时间间隔 单位毫秒</param> public void MonitorRegister(int timeout) { SetAllSiteStatus(SiteStatus.Run); isMonitorRegister = true; while (isMonitorRegister) { foreach (var site in Sites) { foreach (var reg in site.Register) { if (comm.ReadReg(reg.Addr, 1, site.TcaAddr, site.Channel, site.ChipAddr) > 0) { NLogHelper.DebugLog($"ReadReg addr:{reg.Addr} TcaAddr:{site.TcaAddr} Channel:{site.Channel} ChipAddr:{site.ChipAddr}"); } } } Thread.Sleep(timeout); } }
private void RecvRegsHanlder(object sender, ToFReply msg) { foreach (var site in Sites) { if (site.TcaAddr == msg.TcaAddr && site.Channel == msg.TcaChannel && site.ChipAddr == msg.ChipAddr) { if (msg.Num == 0) { site.Status = SiteStatus.Lost; NLogHelper.DebugLog($"{site.TcaAddr} {site.Channel} {site.ChipAddr} Don't Recv Reg Success"); } else { foreach (var reg in site.Register) { foreach (var regRecv in msg.GetRegValue()) { if (regRecv.Key == reg.Addr) { reg.Val = regRecv.Value;//收到值之后需要对值进行校验 if (CheckRegister(reg.Val, reg.Checks)) { site.Status = SiteStatus.Run; } else { site.Status = SiteStatus.Error; NLogHelper.DebugLog($"{site.TcaAddr} {site.Channel} {site.ChipAddr} Recv Reg {reg.Val}"); } } } } } } } }