public static async Task <bool> ReadCoil(int modbusAddress, ushort startAddress, ModbusRtuOverTcp client , Action <bool> ReadSuccess, RedisClient redisClient, ControlRequest par , IotDataOilwellDHMeasure lLJ, LogIotModbusPoll logIotModbusPoll, string message) { $"{message}开始: ---------------".Info(); lock (ClientInfo.locker) { ClientInfo.RequestTime = DateTime.Now; ClientInfo.ExpectedType = 0x01; ClientInfo.ExpectedDataLen = 1; } var readCoil = await client.ReadCoilAsync($"s={modbusAddress};x=1;{startAddress}", 1); if (readCoil.IsSuccess) { ReadSuccess?.Invoke(readCoil.Content[0]); return(true); } else { FailLog.Write(redisClient, par, lLJ, logIotModbusPoll, "Get_LLJ", $"读取{message}异常!"); return(false); } }
public static async Task <bool> SetGJL(RedisClient redisClient, ModbusRtuOverTcp client, int modbusAddress, ushort startAddress, IotDataOilOmeter tankmeasure, LogIotModbusPoll logIotModbusPoll, ControlRequest par, int tryReadTimes = 3) { //获取采集时间 var address = startAddress + 1; var isSuccess = await GetDateTime(client, modbusAddress, tankmeasure, (ushort)address, 3, tryReadTimes); if (!isSuccess) { FailLog.Write(redisClient, par, tankmeasure, logIotModbusPoll, "Get_LYQH_GJL_Tankmeasure", "读取液位罐计量时间数据异常!"); return(false); } isSuccess = await GetGJL(client, modbusAddress, tankmeasure, startAddress, 1, tryReadTimes); if (!isSuccess) { FailLog.Write(redisClient, par, tankmeasure, logIotModbusPoll, "Get_LYQH_GJL_Tankmeasure", "读取液位罐计量数据异常!"); return(false); } return(true); }
public static async Task <bool> SetPressure(RedisClient redisClient, ModbusRtuOverTcp client, int modbusAddress, IotDataOilWellPressure pressure, LogIotModbusPoll logIotModbusPoll, ControlRequest par, int tryReadTimes = 3) { //获取采集时间 var failed = await GetDateTime(client, modbusAddress, pressure, (ushort)1, 3, tryReadTimes); if (failed) { FailLog.Write(redisClient, par, pressure, logIotModbusPoll, "Get_LYQH_GJL_Pressure", "读取油井压力数据异常!"); return(false); } failed = await GetOilPress(client, modbusAddress, pressure, (ushort)0, 1, tryReadTimes); if (failed) { FailLog.Write(redisClient, par, pressure, logIotModbusPoll, "Get_LYQH_GJL_Pressure", "读取油井压力数据异常!"); return(false); } return(true); }
public static void Write(RedisClient redisClient, ControlRequest par, dynamic table, LogIotModbusPoll logIotModbusPoll, string method, string message) { string errorMsg = table.AlarmMsg; string msg = $"{par.DeviceName}-{par.DeviceId}-{par.ModbusAddress}"; table.AlarmCode = -1; table.AlarmMsg = "数据异常"; if (errorMsg == "正常") { errorMsg = table.AlarmMsg; } table.Mock = par.UseMockData; logIotModbusPoll.Type = method; logIotModbusPoll.DateTime = DateTime.Now; logIotModbusPoll.State = -1; logIotModbusPoll.Result = $"{msg}:{message}[{errorMsg}]"; logIotModbusPoll.Result.Info(); redisClient.AddItemToList("YCIOT:Log_IOT_Modbus_Poll", logIotModbusPoll.ToJson().IndentJson()); }
public static async Task <bool> SetIndicatorDiagram(RedisClient redisClient, ModbusRtuOverTcp client, int modbusAddress, IotDataOilWellIndicatorDiagram indicatorDiagram, LogIotModbusPoll logIotModbusPoll, ControlRequest par, int slotId, int tryReadTimes = 3) { var startAddress = (ushort)((slotId * 0x3000) + 256); //时间 var isSuccess = await GetDateTime(client, modbusAddress, indicatorDiagram, startAddress, 3, tryReadTimes); if (!isSuccess) { FailLog.Write(redisClient, par, indicatorDiagram, logIotModbusPoll, "Get_LYQH_WG_IndicatorDiagram", "读取采样时间数据异常!"); return(false); } startAddress = (ushort)((slotId * 0x3000) + 260); //采样点数 isSuccess = await GetCount(client, modbusAddress, indicatorDiagram, startAddress, 1, tryReadTimes); if (!isSuccess) { FailLog.Write(redisClient, par, indicatorDiagram, logIotModbusPoll, "Get_LYQH_WG_IndicatorDiagram", "读取采样点数数据异常!"); return(false); } startAddress = (ushort)((slotId * 0x3000) + 263); //读取冲次 isSuccess = await GetStroke(client, modbusAddress, indicatorDiagram, startAddress, 1, tryReadTimes); if (!isSuccess) { FailLog.Write(redisClient, par, indicatorDiagram, logIotModbusPoll, "Get_LYQH_WG_IndicatorDiagram", "读取冲次异常!"); return(false); } ushort step = 100; if (indicatorDiagram.Count <= 250 && indicatorDiagram.Count >= step) { var regAddress = (ushort)((slotId * 0x3000) + 606); //读取载荷数据 for (ushort i = 0; i < indicatorDiagram.Count; i += step) { var itemCount = (i + step > indicatorDiagram.Count) ? (ushort)(indicatorDiagram.Count - i) : step; Logger.Info($"{i}:{itemCount}:{(ushort)(regAddress + i)}"); //读取载荷 isSuccess = await GetLData(client, modbusAddress, indicatorDiagram, (ushort)(regAddress + i), itemCount, tryReadTimes); if (!isSuccess) { var message = "从 " + (regAddress + i).ToString() + " 个开始,读取 " + itemCount.ToString() + " 个载荷数据异常!"; FailLog.Write(redisClient, par, indicatorDiagram, logIotModbusPoll, "Get_LYQH_WG_IndicatorDiagram", message); return(false); } Thread.Sleep(100); } regAddress = (ushort)((slotId * 0x3000) + 356); //读取位移数据 for (var i = 0; i < indicatorDiagram.Count; i += step) { var itemCount = (i + step > indicatorDiagram.Count) ? (ushort)(indicatorDiagram.Count - i) : step; Logger.Info($"{i}:{itemCount}:{(ushort)(regAddress + i)}"); //读取位移 isSuccess = await GetDData(client, modbusAddress, indicatorDiagram, (ushort)(regAddress + i), itemCount, tryReadTimes); if (!isSuccess) { var message = "从 " + (regAddress + i).ToString() + " 个开始,读取 " + itemCount.ToString() + " 个有线功图位移数据异常!"; FailLog.Write(redisClient, par, indicatorDiagram, logIotModbusPoll, "Get_LYQH_WG_IndicatorDiagram", message); return(false); } Thread.Sleep(100); } var maxDis = indicatorDiagram.D.Max(); var minDis = indicatorDiagram.D.Min(); for (var i = 0; i < indicatorDiagram.D.Count; i++) { if (Math.Abs(maxDis - minDis) > 0.1) { indicatorDiagram.D[i] = Math.Round(((indicatorDiagram.D[i] - minDis) / (maxDis - minDis) * (double)indicatorDiagram.Displacement), 2); } } if (indicatorDiagram.D.Count > 0) { indicatorDiagram.MaxLoad = Math.Round(indicatorDiagram.L.Max(), 2); //最大载荷 indicatorDiagram.MinLoad = Math.Round(indicatorDiagram.L.Min(), 2); //最小载荷 indicatorDiagram.AvgLoad = Math.Round(indicatorDiagram.L.Average(), 2); //平均载荷 indicatorDiagram.D.Add(indicatorDiagram.D[0]); indicatorDiagram.L.Add(indicatorDiagram.L[0]); } } else { return(false); } return(true); }
public static async Task <bool> SetdytDiagram(RedisClient redisClient, ModbusRtuOverTcp client, int modbusAddress, IotDataOilWellMovefluidlevel dytDiagram, LogIotModbusPoll logIotModbusPoll, ControlRequest par, int slotId, int tryReadTimes = 3) { var regAddress = (ushort)((slotId * 0x3000) + 1536); //读取位移数据 var isSuccess = await GetAll(client, modbusAddress, dytDiagram, regAddress, 6, tryReadTimes); if (!isSuccess) { FailLog.Write(redisClient, par, dytDiagram, logIotModbusPoll, "Get_LYQH_DYM_Movefluidlevel", "读取动液面异常!"); return(false); } ushort step = 100; //读取序列数据 if (dytDiagram.Count <= 6000 && dytDiagram.Count >= step) { regAddress = (ushort)((slotId * 0x3000) + 1636); //读取序列数据 for (var i = 0; i < dytDiagram.Count; i += step) { var itemCount = (i + step > dytDiagram.Count) ? (ushort)(dytDiagram.Count - i) : step; Logger.Info($"{i}:{itemCount}:{(ushort)(regAddress + i)}"); //读取序列 isSuccess = await GetDData(client, modbusAddress, dytDiagram, (ushort)(regAddress + i), itemCount, tryReadTimes); if (!isSuccess) { var message = "从 " + (regAddress + i).ToString() + " 个开始,读取 " + itemCount.ToString() + " 个动液面位移数据异常!"; FailLog.Write(redisClient, par, dytDiagram, logIotModbusPoll, "Get_LYQH_DYM_Movefluidlevel", message); return(false); } Thread.Sleep(100); } } else { return(false); } return(true); }