plc读写加日志,测试,断线恢复后写入正常读取不正常的情况原因.云平台msg

zw
CZ 5 months ago
parent b90ef960dd
commit 3e41d874fa

@ -60,6 +60,26 @@ public class CloudConst
public static readonly string chargeDevDataInfo = "chargeDevDataInfo";
public static readonly string chargeDevDataInfoRes = "chargeDevDataInfoRes";
public static readonly string batDataInfo = "batDataInfo";
public static readonly string batDataInfoRes = "batDataInfoRes";
public static readonly string batteryTotalRes = "batteryTotalRes";
public static readonly string meterDayEnergyValRes = "meterDayEnergyValRes";
public static readonly string meterEnergyKwhRes = "meterEnergyKwhRes";
public static readonly string powerTotalRes = "powerTotalRes";
public static readonly string staChargingTotalRes = "staChargingTotalRes";
public static readonly string staDayEnergyValRes = "staDayEnergyValRes";
public static readonly string staDayOpeEnergyValRes = "staDayOpeEnergyValRes";
public static readonly string staHourAmountValRes = "staHourAmountValRes";
public static readonly string staHourEnergyValRes = "staHourEnergyValRes";
public static readonly string batteryTotal = "batteryTotal";
public static readonly string chargingTotalDis = "chargingTotalDis";
public static readonly string meterDayEnergyVal = "meterDayEnergyVal";
public static readonly string staHourEnergyVal = "staHourEnergyVal";
public static readonly string staHourAmountVal = "staHourAmountVal";
public static readonly string staDayEnergyVal = "staDayEnergyVal";
public static readonly string staChargingTotal = "staChargingTotal";
public static readonly string meterEnergyKwh = "meterEnergyKwh";
public static readonly string powerTotal = "powerTotal";
public static readonly string staDayOpeEnergyVal = "staDayOpeEnergyVal";
/// <summary>
/// 站外

@ -1,6 +1,8 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
public class BatDataInfoRes
namespace Service.Cloud.Msg.Cloud.Resp;
public class BatDataInfoRes : ICmd
{
/// <summary>
/// 应答结果
@ -8,4 +10,9 @@ public class BatDataInfoRes
/// <see cref="Entity.Constant.CloudEnum.Result"/>
/// </summary>
public byte re { get; set; }
public string GetCmd()
{
return CloudConst.batDataInfoRes;
}
}

@ -1,6 +1,8 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
public class BatteryTotalRes
namespace Service.Cloud.Msg.Cloud.Resp;
public class BatteryTotalRes : ICmd
{
/// <summary>
/// 应答结果
@ -8,4 +10,8 @@ public class BatteryTotalRes
/// <see cref="Entity.Constant.CloudEnum.Result"/>
/// </summary>
public byte re { get; set; }
public string GetCmd()
{
return CloudConst.batteryTotalRes;
}
}

@ -10,7 +10,7 @@ namespace Service.Cloud.Msg.Cloud.Resp
/// <summary>
/// 4.2.10.2 云平台应答充电机的遥测数据上报
/// </summary>
public class ChargeDevDataInfoRes
public class ChargeDevDataInfoRes : ICmd
{
/// <summary>
/// 应答结果0成功1失败

@ -1,12 +1,19 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 5.2.4 后台服务器应答换电站充电电池电量分布统计信息
/// </summary>
public class ChargingTotalDisRes
public class ChargingTotalDisRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.chargeDevDataInfoRes;
}
}

@ -1,6 +1,8 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
public class EqmStateEndLogInfoRes
namespace Service.Cloud.Msg.Cloud.Resp;
public class EqmStateEndLogInfoRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
@ -11,4 +13,8 @@ public class EqmStateEndLogInfoRes
/// </summary>
public string rs {get;set;} //
public string GetCmd()
{
return CloudConst.eqmStateEndLogInfoRes;
}
}

@ -1,9 +1,16 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
public class MeterDayEnergyValRes
namespace Service.Cloud.Msg.Cloud.Resp;
public class MeterDayEnergyValRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.meterDayEnergyValRes;
}
}

@ -1,12 +1,19 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 0 后台服务器返回电能表小时能耗值信息
/// </summary>
public class MeterEnergyKwhRes
public class MeterEnergyKwhRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.meterEnergyKwhRes;
}
}

@ -1,12 +1,19 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 5.2.6 后台服务器应答电能表累计值信息
/// </summary>
public class PowerTotalRes
public class PowerTotalRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.powerTotalRes;
}
}

@ -1,12 +1,19 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 后台服务器应答电能表变化值信息
/// </summary>
public class StaChargingTotalRes
public class StaChargingTotalRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.staChargingTotalRes;
}
}

@ -1,9 +1,16 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
public class StaDayEnergyValRes
namespace Service.Cloud.Msg.Cloud.Resp;
public class StaDayEnergyValRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.staDayEnergyValRes;
}
}

@ -1,12 +1,18 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 5.2.18 后台服务器换电站日运行统计结果信息
/// </summary>
public class StaDayOpeEnergyValRes
public class StaDayOpeEnergyValRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.staDayOpeEnergyValRes;
}
}

@ -1,12 +1,18 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 5.2.20 后台应答服务器换电站分时用电统计信息
/// </summary>
public class StaHourAmountValRes
public class StaHourAmountValRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.staHourAmountValRes;
}
}

@ -1,12 +1,18 @@
namespace Service.Cloud.Msg.Cloud.Resp;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Cloud.Resp;
/// <summary>
/// 4 后台服务器换电站分时用电统计信息
/// </summary>
public class StaHourEnergyValRes
public class StaHourEnergyValRes : ICmd
{
/// <summary>
/// 接收结果 0:成功 1失败
/// </summary>
public byte re {get;set;}
public string GetCmd()
{
return CloudConst.staHourEnergyValRes;
}
}

@ -27,4 +27,93 @@ namespace Service.Cloud.Msg.Host.Req
return CloudConst.batDataInfo;
}
}
public class SingleBatInfo
{
/// <summary>
/// 电池序列号
/// </summary>
public string bn { get; set; }
/// <summary>
/// 充电架 ID 按电池架的编号 A1A2…
/// </summary>
public string sd { get; set; }
/// <summary>
/// 所在充电机序号 从 1 开始递增
/// </summary>
public int cno { get; set; }
/// <summary>
/// 是否在充电 0未知 1正在充电 2未电池
/// </summary>
public int hc { get; set; }
/// <summary>
/// 电接头连接状态 0未知 1已经连接 2未连接
/// </summary>
public int el { get; set; }
/// <summary>
/// 剩余能量 单位 0.1 kwh
/// </summary>
public float soe { get; set; }
/// <summary>
/// 当前 SOC 0-100 单位 0.1 ,没有充电填 0
/// </summary>
public float soc { get; set; }
/// <summary>
/// 当前 SOH 0-100 单位 0.1 ,没有充电填 0
/// </summary>
public float soh { get; set; }
/// <summary>
/// 最低单体电压 单位 0.01V
/// </summary>
public float lsv { get; set; }
/// <summary>
/// 最高单体电压 单位 0.01V
/// </summary>
public float hsv { get; set; }
/// <summary>
/// 最低单体温度 单位 0.1℃
/// </summary>
public float lst { get; set; }
/// <summary>
/// 最高单体温度 单位 0.1℃
/// </summary>
public float hst { get; set; }
/// <summary>
/// 更新时间 格式 ”yyyy-MM-dd HH:mm:ss ”
/// </summary>
public DateTime bt { get; set; }
public List<SglInfo> sgl_info = new List<SglInfo>();
}
public class SglInfo
{
/// <summary>
/// 单体电池号 从 1 开始递增
/// </summary>
public int sl { get; set; }
/// <summary>
/// 单体电压 每一节电芯的单体电压 单位 0.1V 如果没有该节电芯的数据填65535.0 无效值
/// </summary>
public float sv { get; set; }
/// <summary>
/// 单体温度 每一节电芯的单体温度 单位 0.1℃ ,如果没有该节电芯的数据填65535.0 无效值
/// </summary>
public float st { get; set; }
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.1 换电站上报电池状态分布统计信息
/// </summary>
public class BatteryTotal
public class BatteryTotal : ICmd
{
/// <summary>
/// 换电站编码 换电站唯一码,区域码+类型码+流水号
@ -41,5 +43,8 @@ public class BatteryTotal
/// 更新时间 格式” yyyy-MM-dd HH:mm:ss”
/// </summary>
public DateTime ut { get; set; }
public string GetCmd()
{
return CloudConst.batteryTotal;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.3 换电站充电电池电量分布统计信息
/// </summary>
public class ChargingTotalDis
public class ChargingTotalDis : ICmd
{
/// <summary>
/// 换电站编码 换电站唯一码,区域码+ 类型码+流水号
@ -29,4 +31,8 @@ public class ChargingTotalDis
/// 低电量电池数量 0%--80%(同型号)
/// </summary>
public int lc { get; set; }
public string GetCmd()
{
return CloudConst.chargingTotalDis;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
///
/// </summary>
public class EqmStateEndLogInfo
public class EqmStateEndLogInfo : ICmd
{
/// <summary>
/// 设备编号 无辅助设备(场站码+00000)
@ -33,4 +35,8 @@ public class EqmStateEndLogInfo
/// 采集模式 1 自动2人工录入
/// </summary>
public int cm {get;set;} //
public string GetCmd()
{
return CloudConst.eqmStateEndLogInfo;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.11 电能表每天能耗值信息
/// </summary>
public class MeterDayEnergyVal
public class MeterDayEnergyVal : ICmd
{
/// <summary>
/// 换电站编码
@ -33,4 +35,8 @@ public class MeterDayEnergyVal
/// 结束时间 精确到天。格式” yyyy-MM-dd ”
/// </summary>
public DateTime et { get; set; }
public string GetCmd()
{
return CloudConst.meterDayEnergyVal;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.9 电能表小时能耗值信息
/// </summary>
public class MeterEnergyKwh
public class MeterEnergyKwh : ICmd
{
/// <summary>
/// 换电站编码
@ -33,4 +35,8 @@ public class MeterEnergyKwh
/// 结束时间 格式” yyyy-MM-dd HH:mm:ss ”
/// </summary>
public DateTime et { get; set; }
public string GetCmd()
{
return CloudConst.meterEnergyKwh;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.5 电能表累计值信息
/// </summary>
public class PowerTotal
public class PowerTotal : ICmd
{
/// <summary>
/// 换电站编码
@ -25,4 +27,8 @@ public class PowerTotal
/// 累积值 单位:kWh,保留两位 小数
/// </summary>
public float mk { get; set; }
public string GetCmd()
{
return CloudConst.powerTotal;
}
}

@ -1,4 +1,4 @@
using Service.Cloud.Common;
 using Service.Cloud.Common;
using System;
using System.Collections.Generic;
using System.Linq;

@ -1,84 +1,91 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
public class SingleBatInfo
{
/// <summary>
/// 电池序列号
/// </summary>
public string bn { get; set; }
/// <summary>
/// 充电架 ID 按电池架的编号 A1A2…
/// </summary>
public string sd { get; set; }
/// <summary>
/// 所在充电机序号 从 1 开始递增
/// </summary>
public int cno { get; set; }
/// <summary>
/// 是否在充电 0未知 1正在充电 2未电池
/// </summary>
public int hc { get; set; }
/// <summary>
/// 电接头连接状态 0未知 1已经连接 2未连接
/// </summary>
public int el { get; set; }
/// <summary>
/// 剩余能量 单位 0.1 kwh
/// </summary>
public float soe { get; set; }
/// <summary>
/// 当前 SOC 0-100 单位 0.1 ,没有充电填 0
/// </summary>
public float soc { get; set; }
/// <summary>
/// 当前 SOH 0-100 单位 0.1 ,没有充电填 0
/// </summary>
public float soh { get; set; }
/// <summary>
/// 最低单体电压 单位 0.01V
/// </summary>
public float lsv { get; set; }
/// <summary>
/// 最高单体电压 单位 0.01V
/// </summary>
public float hsv { get; set; }
/// <summary>
/// 最低单体温度 单位 0.1℃
/// </summary>
public float lst { get; set; }
/// <summary>
/// 最高单体温度 单位 0.1℃
/// </summary>
public float hst { get; set; }
/// <summary>
/// 单体电池号 从 1 开始递增
/// </summary>
public int sl { get; set; }
/// <summary>
/// 单体电压 每一节电芯的单体电压 单位 0.1V 如果没有该节电芯的数据填65535.0 无效值
/// </summary>
public float sv { get; set; }
/// <summary>
/// 单体温度 每一节电芯的单体温度 单位 0.1℃ ,如果没有该节电芯的数据填65535.0 无效值
/// </summary>
public float st { get; set; }
/// <summary>
/// 更新时间 格式 ”yyyy-MM-dd HH:mm:ss ”
/// </summary>
public DateTime bt { get; set; }
}
/// 电池序列号
/// </summary>
public string bn { get; set; }
/// <summary>
/// 充电架 ID 按电池架的编号 A1A2…
/// </summary>
public string sd { get; set; }
/// <summary>
/// 所在充电机序号 从 1 开始递增
/// </summary>
public int cno { get; set; }
/// <summary>
/// 是否在充电 0未知 1正在充电 2未电池
/// </summary>
public int hc { get; set; }
/// <summary>
/// 电接头连接状态 0未知 1已经连接 2未连接
/// </summary>
public int el { get; set; }
/// <summary>
/// 剩余能量 单位 0.1 kwh
/// </summary>
public float soe { get; set; }
/// <summary>
/// 当前 SOC 0-100 单位 0.1 ,没有充电填 0
/// </summary>
public float soc { get; set; }
/// <summary>
/// 当前 SOH 0-100 单位 0.1 ,没有充电填 0
/// </summary>
public float soh { get; set; }
/// <summary>
/// 最低单体电压 单位 0.01V
/// </summary>
public float lsv { get; set; }
/// <summary>
/// 最高单体电压 单位 0.01V
/// </summary>
public float hsv { get; set; }
/// <summary>
/// 最低单体温度 单位 0.1℃
/// </summary>
public float lst { get; set; }
/// <summary>
/// 最高单体温度 单位 0.1℃
/// </summary>
public float hst { get; set; }
/// <summary>
/// 单体电池号 从 1 开始递增
/// </summary>
public int sl { get; set; }
/// <summary>
/// 单体电压 每一节电芯的单体电压 单位 0.1V 如果没有该节电芯的数据填65535.0 无效值
/// </summary>
public float sv { get; set; }
/// <summary>
/// 单体温度 每一节电芯的单体温度 单位 0.1℃ ,如果没有该节电芯的数据填65535.0 无效值
/// </summary>
public float st { get; set; }
/// <summary>
/// 更新时间 格式 ”yyyy-MM-dd HH:mm:ss ”
/// </summary>
public DateTime bt { get; set; }
public string GetCmd()
{
return CloudConst.batDataInfo;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.7 换电站电能表变化值信息
/// </summary>
public class StaChargingTotal
public class StaChargingTotal : ICmd
{
/// <summary>
/// 换电站编码
@ -33,4 +35,8 @@ public class StaChargingTotal
/// 结束时间 格式” yyyy-MM-dd HH:mm:ss ”
/// </summary>
public DateTime et { get; set; }
public string GetCmd()
{
return CloudConst.staChargingTotal;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.15 换电站每天用电统计信息
/// </summary>
public class StaDayEnergyVal
public class StaDayEnergyVal : ICmd
{
/// <summary>
/// 换电站编码
@ -33,4 +35,8 @@ public class StaDayEnergyVal
/// 结束时间 精确到天。格式”yyyy-MM-dd”如2020-11-21)
/// </summary>
public DateTime et { get; set; }
public string GetCmd()
{
return CloudConst.staDayEnergyVal;
}
}

@ -1,4 +1,6 @@
namespace Service.Cloud.Msg.Host;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host;
/// <summary>
/// 5.2.17 换电站日运行统计结果信息
@ -61,4 +63,10 @@ public class StaDayOpeEnergyVal
/// 换电日期 精确到 日。格式 ” yyyy-MM-dd”如2020-11-20)
/// </summary>
public DateTime dt { get; set; }
public string GetCmd()
{
return CloudConst.staDayOpeEnergyVal;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.19 换电站分时用电计费信息
/// </summary>
public class StaHourAmountVal
public class StaHourAmountVal : ICmd
{
/// <summary>
/// 换电站编码
@ -33,4 +35,8 @@ public class StaHourAmountVal
/// 结束时间 精确到小时。格式 ”yyyy-MM-dd HH:mm:ss”如 2020-11-20 19:00:00)
/// </summary>
public DateTime et { get; set; }
public string GetCmd()
{
return CloudConst.staHourAmountVal;
}
}

@ -1,9 +1,11 @@
namespace Service.Cloud.Msg.Host.Req;
using Service.Cloud.Common;
namespace Service.Cloud.Msg.Host.Req;
/// <summary>
/// 5.2.13 换电站分时用电统计信息
/// </summary>
public class StaHourEnergyVal
public class StaHourEnergyVal : ICmd
{
/// <summary>
/// 换电站编码
@ -33,4 +35,8 @@ public class StaHourEnergyVal
/// 结束时间 精确到小时。格式”yyyy-MM-ddHH:mm:ss ”如2020/11/20 18:00:00)
/// </summary>
public DateTime et { get; set; }
public string GetCmd()
{
return CloudConst.staHourEnergyVal;
}
}

@ -30,8 +30,10 @@ public class PlcHeartTask: ITask
public void Handle()
{
Log.Info("Plc start write heart");
if (PlcMgr.PlcClient != null)
{
Log.Info("Plc write connect and satrt set value");
heart = !heart;
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.ProtocolVersion1.Value = 2;
@ -73,7 +75,11 @@ public class PlcHeartTask: ITask
bool writeCharge7 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus07);
bool writeCharge8 = PlcMgr.PlcClient.WriteValue(writeHostToPlc.ChargingStatus08);
Log.Info("Plc write finish");
}
else
{
Log.Info("Plc write not connect");
}
}

@ -15,10 +15,9 @@ namespace Service.Plc.Client;
[Scope]
public class PlcClient : ModbusTcpMaster
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient));
private long TaskNo=0;
private long TaskNo = 0;
public BinInfoRepository BinInfoRepository { get; set; }
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
@ -40,8 +39,7 @@ public class PlcClient : ModbusTcpMaster
//读取当前任务
public long ReadTaskNo()
{
return Interlocked.Read( ref TaskNo);
return Interlocked.Read(ref TaskNo);
}
public PlcClient()
@ -52,65 +50,140 @@ public class PlcClient : ModbusTcpMaster
Duration = 1000;
AutoReConnect = true;
ByteSeq = EndingConst.ByteSeq.BA;
WordSeq= EndingConst.WordSeq.CD;
WordSeq = EndingConst.WordSeq.CD;
}
private void BatchRead(ModbusTcpMaster master)
{
var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
try
{
PlcMgr.DataValidityTime = DateTime.Now;
Log.Info("Plc read satrt");
if (master != null)
{
var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
{
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
}
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
}
var bytes02 = master.BatchReadHolderRegister(201, 222);
if (bytes02 != null)
{
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
UpdateBinInfoCache(PlcMgr.PlcToHostData.MaterialDetec01.Value, "1");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec02.Value, "2");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec03.Value, "3");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec04.Value, "4");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec05.Value, "5");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec06.Value, "6");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec07.Value, "7");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec08.Value, "8");
var bytes02 = master.BatchReadHolderRegister(201, 222);
if (bytes02 != null)
{
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
UpdateBinInfoCache(PlcMgr.PlcToHostData.MaterialDetec01.Value, "1");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec02.Value, "2");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec03.Value, "3");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec04.Value, "4");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec05.Value, "5");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec06.Value, "6");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec07.Value, "7");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec08.Value, "8");
}
}
var bytes03 = master.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
{
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.CD);
List<string> alarm = new List<string>()
{
PlcMgr.PlcFaultData.ErrorCode01.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode02.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode03.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode04.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode05.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode06.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode07.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode08.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode09.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode10.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode11.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode12.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode13.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode14.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode15.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode16.Value.ToString(),
};
SaveAlarmInfo(alarm);
}
Log.Info("Plc read finish");
}
else if(PlcMgr.PlcClient!=null)
{
Log.Info("Plc use plcClient read");
var bytes01 = PlcMgr.PlcClient.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
{
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
}
var bytes03 = master.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
var bytes02 = PlcMgr.PlcClient.BatchReadHolderRegister(201, 222);
if (bytes02 != null)
{
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
UpdateBinInfoCache(PlcMgr.PlcToHostData.MaterialDetec01.Value, "1");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec02.Value, "2");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec03.Value, "3");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec04.Value, "4");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec05.Value, "5");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec06.Value, "6");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec07.Value, "7");
UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec08.Value, "8");
}
var bytes03 = PlcMgr.PlcClient.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
{
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.CD);
List<string> alarm = new List<string>()
{
PlcMgr.PlcFaultData.ErrorCode01.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode02.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode03.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode04.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode05.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode06.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode07.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode08.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode09.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode10.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode11.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode12.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode13.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode14.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode15.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode16.Value.ToString(),
};
SaveAlarmInfo(alarm);
}
Log.Info("Plc read finish");
}
}
catch (Exception e)
{
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.CD);
List<string> alarm = new List<string>()
{
PlcMgr.PlcFaultData.ErrorCode01.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode02.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode03.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode04.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode05.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode06.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode07.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode08.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode09.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode10.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode11.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode12.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode13.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode14.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode15.Value.ToString(),
PlcMgr.PlcFaultData.ErrorCode16.Value.ToString(),
};
SaveAlarmInfo(alarm);
Log.Info($"Plc read error:{e}");
throw;
}
}
@ -161,8 +234,8 @@ public class PlcClient : ModbusTcpMaster
{
#region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
var lstEquipAlarmRecord=EquipAlarmRecordRepository.QueryListByClause(i => i.EquipTypeCode == 3);
var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList();
var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipTypeCode == 3);
var sqllstAlarm = lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList();
// 找出实时报警中存在但数据库中不存在的元素
List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
@ -171,10 +244,13 @@ public class PlcClient : ModbusTcpMaster
List<string> uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList();
if (uniqueToList1.Count > 0)
{//这里要添加新的报警数据
{
//这里要添加新的报警数据
foreach (var errorCode in uniqueToList1)
{
EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode);
EquipAlarmDefine? alarmDefine =
EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc,
errorCode);
if (alarmDefine != null)
{
EquipAlarmRecord record = new EquipAlarmRecord()
@ -185,7 +261,7 @@ public class PlcClient : ModbusTcpMaster
ErrorLevel = alarmDefine.ErrorLevel,
ErrorMsg = alarmDefine.ErrorMsg,
ProcessMethod = alarmDefine.ProcessMethod,
StartTime= DateTime.Now
StartTime = DateTime.Now
};
EquipAlarmRecordRepository.Insert(record);
}
@ -193,7 +269,8 @@ public class PlcClient : ModbusTcpMaster
}
if (uniqueToList2.Count > 0)
{//这些是要清除实时报警,并且处理记录的。
{
//这些是要清除实时报警,并且处理记录的。
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord
.Where(obj => uniqueToList2.Contains(obj.ErrorCode))
@ -208,10 +285,11 @@ public class PlcClient : ModbusTcpMaster
EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg;
EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod;
EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime;
EquipAlarmProcessRecord.ProcessTime=DateTime.Now;
EquipAlarmProcessRecord.ProcessTime = DateTime.Now;
EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord);
}
EquipAlarmRecordRepository.Delete(filteredObjectList);
}
@ -221,7 +299,7 @@ public class PlcClient : ModbusTcpMaster
{
#region 没报警把已处理记录更新并删除实时报警
var lstEquipAlarmRecord=EquipAlarmRecordRepository.QueryListByClause(i=>i.EquipTypeCode==3);
var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipTypeCode == 3);
if (lstEquipAlarmRecord.Count > 0)
{
foreach (var VARIABLE in lstEquipAlarmRecord)
@ -234,16 +312,15 @@ public class PlcClient : ModbusTcpMaster
EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg;
EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod;
EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime;
EquipAlarmProcessRecord.ProcessTime=DateTime.Now;
EquipAlarmProcessRecord.ProcessTime = DateTime.Now;
EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord);
}
}
EquipAlarmRecordRepository.Delete(lstEquipAlarmRecord);
#endregion
}
}
@ -252,7 +329,8 @@ public class PlcClient : ModbusTcpMaster
if (exists == 0)
BinInfoRepository.Update(
it =>
new BinInfo(){
new BinInfo()
{
Exists = 0,
BatteryNo = "-1",
Soc = (decimal)-1,
@ -264,7 +342,6 @@ public class PlcClient : ModbusTcpMaster
BinInfoRepository.Update(it => it.Exists == 1,
it => it.No == binNo);
}
private void UpdateBinInfoCache(int exists, string binNo)
@ -272,15 +349,14 @@ public class PlcClient : ModbusTcpMaster
if (exists == 0)
BinInfoRepository.Update(
it =>
new BinInfo(){
new BinInfo()
{
Exists = 0,
},
it => it.No == binNo);
else
BinInfoRepository.Update(it => it.Exists == 1,
it => it.No == binNo);
}
}
}

@ -56,6 +56,7 @@
<ItemGroup>
<Compile Remove="FireControl\Msg\ReadMsg.cs" />
<Compile Remove="Cloud\Client\MyTask\UpBatDataInfoTask.cs" />
<Compile Remove="Cloud\Msg\Host\Req\ChargerDataReport.cs" />
</ItemGroup>
</Project>

Loading…
Cancel
Save