diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index e14af51..20ecf3a 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -21,15 +21,18 @@ public class PlcClient : ModbusTcpMaster Duration = 2000; AutoReConnect = true; _binInfoRepository = binInfoRepository; + DataFormat = HslCommunication.Core.DataFormat.DCBA; } private void BatchRead(ModbusTcpMaster master) { + PlcMgr.SendHear(); var bytes01 = master.BatchReadHolderRegister(1, 115); if (bytes01 != null) { PlcMgr.DataValidityTime = DateTime.Now; - ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); + + ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); } var bytes02 = master.BatchReadHolderRegister(201, 222); diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs index 43ecd78..c35375e 100644 --- a/Service/Plc/Client/PlcMgr.cs +++ b/Service/Plc/Client/PlcMgr.cs @@ -161,6 +161,29 @@ public class PlcMgr return false; } + public static bool SendHear() + { + if (PlcClient != null) + { + HostToPlc writeHostToPlc = new HostToPlc(); + writeHostToPlc.Years.Value = (ushort)DateTime.Now.Year; + writeHostToPlc.Month.Value = (ushort)DateTime.Now.Month; + writeHostToPlc.Day.Value = (ushort)DateTime.Now.Day; + writeHostToPlc.Hour.Value = (ushort)DateTime.Now.Hour; + writeHostToPlc.Points.Value = (ushort)DateTime.Now.Minute; + writeHostToPlc.Seconds.Value = (ushort)DateTime.Now.Second; + + bool write1 = PlcClient.WriteValue(writeHostToPlc.Years); + bool write2 = PlcClient.WriteValue(writeHostToPlc.Month); + bool write3 = PlcClient.WriteValue(writeHostToPlc.Day); + bool write4 = PlcClient.WriteValue(writeHostToPlc.Hour); + bool write5 = PlcClient.WriteValue(writeHostToPlc.Points); + bool write6 = PlcClient.WriteValue(writeHostToPlc.Seconds); + return write1 && write2&& write3 && write4&& write5 && write6; + } + return true; + } + /// /// 查看拍照状态 /// diff --git a/Service/Plc/Msg/HostToPlc.cs b/Service/Plc/Msg/HostToPlc.cs index c116148..82388a1 100644 --- a/Service/Plc/Msg/HostToPlc.cs +++ b/Service/Plc/Msg/HostToPlc.cs @@ -71,7 +71,7 @@ namespace Service.Plc.Msg /// 对时时钟:年 /// public ModbusProperty Years { get; set; } = new(40016); - public ModbusProperty Standby3 { get; set; } = new(40017, length: 4); // 备用3 + //public ModbusProperty Standby3 { get; set; } = new(40017, length: 4); // 备用36 //public ModbusProperty ChargingStatus { get; set; } = new(40021, length: 40); // 仓位充电状态 /// /// 仓位充电状态 @@ -340,7 +340,7 @@ namespace Service.Plc.Msg /// 电池包锁止异常,暂停命令 0:无命令;1000:暂停使能 /// public ModbusProperty StopCommand { get; set; } = new(40105); - public ModbusProperty Standby4 { get; set; } = new(40106, length: 5); // 备用4 + //public ModbusProperty Standby4 { get; set; } = new(40106, length: 5); // 备用4 /// /// 任务类型 /// 0.无任务 diff --git a/Service/Plc/Msg/PlcFault.cs b/Service/Plc/Msg/PlcFault.cs index 599cec9..ade3939 100644 --- a/Service/Plc/Msg/PlcFault.cs +++ b/Service/Plc/Msg/PlcFault.cs @@ -4,15 +4,10 @@ namespace Service.Plc.Msg { public class PlcFault { - public ModbusProperty ErrorCode01 { get; set; } = new(40701); // 错误码 - public ModbusProperty ErrorCode02 { get; set; } = new(40702); // 错误码 - public ModbusProperty ErrorCode03 { get; set; } = new(40703); // 错误码 - public ModbusProperty ErrorCode04 { get; set; } = new(40704); // 错误码 - public ModbusProperty ErrorCode05 { get; set; } = new(40705); // 错误码 - public ModbusProperty ErrorCode06 { get; set; } = new(40706); // 错误码 - public ModbusProperty ErrorCode07 { get; set; } = new(40707); // 错误码 - public ModbusProperty ErrorCode08 { get; set; } = new(40708); // 错误码 - public ModbusProperty ErrorCode09 { get; set; } = new(40709); // 错误码 - public ModbusProperty ErrorCode10 { get; set; } = new(40710); // 错误码 + public ModbusProperty ErrorCode01 { get; set; } = new(40701,length :2); // 错误码 + public ModbusProperty ErrorCode03 { get; set; } = new(40703,length :2); // 错误码 + public ModbusProperty ErrorCode05 { get; set; } = new(40705,length :2); // 错误码 + public ModbusProperty ErrorCode07 { get; set; } = new(40707,length :2); // 错误码 + public ModbusProperty ErrorCode09 { get; set; } = new(40709, length: 2); // 错误码 } } diff --git a/Service/Plc/Msg/PlcToHost.cs b/Service/Plc/Msg/PlcToHost.cs index 826973f..e183a93 100644 --- a/Service/Plc/Msg/PlcToHost.cs +++ b/Service/Plc/Msg/PlcToHost.cs @@ -65,31 +65,31 @@ namespace Service.Plc.Msg /// /// 备用 /// - public ModbusProperty value09 { get; set; } = new(40211, length: 30); + //public ModbusProperty<1> value09 { get; set; } = new(40211, length: 30); #region 舱位状态 bit0:有料检测 Bit1:有料检测开关故障 - public ModbusProperty MaterialDetec01 { get; set; } = new(40241,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec02 { get; set; } = new(40242,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec03 { get; set; } = new(40243,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec04 { get; set; } = new(40244,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec05 { get; set; } = new(40245,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec06 { get; set; } = new(40246,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec07 { get; set; } = new(40247,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec08 { get; set; } = new(40248,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec09 { get; set; } = new(40249,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec10 { get; set; } = new(40250,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec11 { get; set; } = new(40251,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec12 { get; set; } = new(40252,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec13 { get; set; } = new(40253,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec14 { get; set; } = new(40254,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec15 { get; set; } = new(40255,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec16 { get; set; } = new(40256,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec17 { get; set; } = new(40257,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec18 { get; set; } = new(40258,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec19 { get; set; } = new(40259,0,2,ModbusDataType.Bit); - public ModbusProperty MaterialDetec20 { get; set; } = new(40260,0,2,ModbusDataType.Bit); + public ModbusProperty MaterialDetec01 { get; set; } = new(40241); + public ModbusProperty MaterialDetec02 { get; set; } = new(40242); + public ModbusProperty MaterialDetec03 { get; set; } = new(40243); + public ModbusProperty MaterialDetec04 { get; set; } = new(40244); + public ModbusProperty MaterialDetec05 { get; set; } = new(40245); + public ModbusProperty MaterialDetec06 { get; set; } = new(40246); + public ModbusProperty MaterialDetec07 { get; set; } = new(40247); + public ModbusProperty MaterialDetec08 { get; set; } = new(40248); + public ModbusProperty MaterialDetec09 { get; set; } = new(40249); + public ModbusProperty MaterialDetec10 { get; set; } = new(40250); + public ModbusProperty MaterialDetec11 { get; set; } = new(40251); + public ModbusProperty MaterialDetec12 { get; set; } = new(40252); + public ModbusProperty MaterialDetec13 { get; set; } = new(40253); + public ModbusProperty MaterialDetec14 { get; set; } = new(40254); + public ModbusProperty MaterialDetec15 { get; set; } = new(40255); + public ModbusProperty MaterialDetec16 { get; set; } = new(40256); + public ModbusProperty MaterialDetec17 { get; set; } = new(40257); + public ModbusProperty MaterialDetec18 { get; set; } = new(40258); + public ModbusProperty MaterialDetec19 { get; set; } = new(40259); + public ModbusProperty MaterialDetec20 { get; set; } = new(40260); #endregion 舱位状态 @@ -127,7 +127,7 @@ namespace Service.Plc.Msg /// z轴扭矩百分比 /// public ModbusProperty PercentageTorqueZ { get; set; } = new(40308); - public ModbusProperty value20 { get; set; } = new(40309, length: 92); // 备用 + //public ModbusProperty value20 { get; set; } = new(40309, length: 92); // 备用 /// /// 入口雷达状态 /// 0:未触发 @@ -229,7 +229,7 @@ namespace Service.Plc.Msg /// z偏差 /// public ModbusProperty DeviationZ { get; set; } = new(40413); - public ModbusProperty value44 { get; set; } = new(40414, length: 7); // 备用 + //public ModbusProperty value44 { get; set; } = new(40414, length: 7); // 备用