From c0ac4821ffa705553dbbe9433473de491df36ad3 Mon Sep 17 00:00:00 2001 From: pengliangyang <1406009520@qq.com> Date: Fri, 14 Oct 2022 15:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/GVL_SmallStation.cs | 3 + .../Model/ProcessControl.cs | 90 ++++++++++++------- .../Model/RawMaterial/DeviceCurrentStatus.cs | 4 +- .../Model/RawMaterial/DeviceInquire.cs | 23 +++-- .../View/HardwareStatusView.xaml | 40 +++++++-- BPASmartClient.Modbus/ModbusTcp.cs | 9 +- BPASmartClient.S7Net/SiemensHelper.cs | 7 +- DosingSystem/Model/DeviceInquire.cs | 2 +- 8 files changed, 126 insertions(+), 52 deletions(-) diff --git a/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs b/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs index a79cb1c9..e93643bf 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/GVL_SmallStation.cs @@ -37,6 +37,9 @@ namespace BPASmartClient.JXJFoodSmallStation.Model /// Tray2的柔性味魔方配料标志 /// public bool DosingTray2 { get; set; } = true; + + public int DosingTray1Loc { get; set; } = 0; + public int DosingTray2Loc { get; set; } = 0; /// /// 配方下发状态 =0:配方未下发 ,1:配方下发给plc ,2:plc成功接收配方 /// diff --git a/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs b/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs index dd6c403d..294ebadb 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/ProcessControl.cs @@ -691,6 +691,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false); } GVL_SmallStation.GetInstance.DosingTray1 = true; + GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成"); } } @@ -709,6 +710,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.1", false); } GVL_SmallStation.GetInstance.DosingTray1 = true; + GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成"); } } @@ -727,6 +729,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.2", false); } GVL_SmallStation.GetInstance.DosingTray1 = true; + GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成"); } } @@ -745,30 +748,34 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.3", false); } GVL_SmallStation.GetInstance.DosingTray1 = true; + GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成"); } } - if (GVL_SmallStation.GetInstance.DosingTray1) + if (GVL_SmallStation.GetInstance.DosingTray1 && GVL_SmallStation.GetInstance.DosingTray1Loc > 0 && GVL_SmallStation.GetInstance.DosingTray1Loc < 16) { - for (int i = 1; i < 16; i++) + int i = GVL_SmallStation.GetInstance.DosingTray1Loc; + if (RTrig.GetInstance("Tray1StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)) { - if (RTrig.GetInstance("Tray1StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)) + MessageLog.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成"); + int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i); + RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback; + string info = DeviceInquire.GetInstance.GetDevice(i).StatusReset(); + MessageLog.GetInstance.ShowRunLog(info); + if (i >= 1 && i <= 8) { - MessageLog.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成"); - int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i); - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback; - DeviceInquire.GetInstance.GetDevice(i).StatusReset(); - if (i >= 1 && i <= 8) - { - HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true); - } - else if (i >= 9 && i <= 15) - { - HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true); - } - GVL_SmallStation.GetInstance.DosingTray1 = false; + string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true); + MessageLog.GetInstance.ShowRunLog(commInfo); } + else if (i >= 9 && i <= 15) + { + string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true); + MessageLog.GetInstance.ShowRunLog(commInfo1); + } + GVL_SmallStation.GetInstance.DosingTray1 = false; + GVL_SmallStation.GetInstance.DosingTray1Loc = 0; } + } if (RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX1.1")) && (GVL_SmallStation.GetInstance.WindSendDosingFinish || !GVL_SmallStation.GetInstance.IsUseWindSend)) { @@ -847,6 +854,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false); } GVL_SmallStation.GetInstance.DosingTray2 = true; + GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成"); } } @@ -865,6 +873,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.5", false); } GVL_SmallStation.GetInstance.DosingTray2 = true; + GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成"); } } @@ -875,7 +884,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model if (res > 0 && res is float loc) { int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc); - double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight; + double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeightW; if (loc_index >= 0) { DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量 @@ -883,6 +892,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.6", false); } GVL_SmallStation.GetInstance.DosingTray2 = true; + GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成"); } } @@ -901,29 +911,32 @@ namespace BPASmartClient.JXJFoodSmallStation.Model //HKDevice.HK_PLC_S7.Write("DB3.DBX50.7", false); } GVL_SmallStation.GetInstance.DosingTray2 = true; + GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc; MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成"); } } - if (GVL_SmallStation.GetInstance.DosingTray2 == true) + if (GVL_SmallStation.GetInstance.DosingTray2 == true && GVL_SmallStation.GetInstance.DosingTray1 == false && GVL_SmallStation.GetInstance.DosingTray2Loc > 0 && GVL_SmallStation.GetInstance.DosingTray2Loc < 16) { - for (int i = 1; i < 16; i++) + int i = GVL_SmallStation.GetInstance.DosingTray2Loc; + if (RTrig.GetInstance("Tray2StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)) { - if (RTrig.GetInstance("Tray2StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)) + MessageLog.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{recipeName},{i}号仓,配料完成"); + int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i); + RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback; + string info = DeviceInquire.GetInstance.GetDevice(i).StatusReset(); + MessageLog.GetInstance.ShowRunLog(info); + if (i >= 1 && i <= 8) { - MessageLog.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{recipeName},{i}号仓,配料完成"); - int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i); - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback; - DeviceInquire.GetInstance.GetDevice(i).StatusReset(); - if (i >= 1 && i <= 8) - { - HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true); - } - else if (i >= 9 && i <= 15) - { - HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true); - } - GVL_SmallStation.GetInstance.DosingTray2 = false; + string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true); + MessageLog.GetInstance.ShowRunLog(commInfo); } + else if (i >= 9 && i <= 15) + { + string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true); + MessageLog.GetInstance.ShowRunLog(commInfo1); + } + GVL_SmallStation.GetInstance.DosingTray2 = false; + GVL_SmallStation.GetInstance.DosingTray2Loc = 0; } } if (RTrig.GetInstance("DB3.DBX1.2").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX1.2"))) @@ -957,7 +970,16 @@ namespace BPASmartClient.JXJFoodSmallStation.Model } } } - + private void StockBinInit() + { + for (int i = 1; i < 16; i++) + { + if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3) + { + DeviceInquire.GetInstance.GetDevice(i).StatusReset(); + } + } + } private void DosingDevice(int Index,int DeviceID) { if (RTrig.GetInstance("Tray2StatusDevice" + DeviceID).Start(DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.RunStatus == 3)) diff --git a/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceCurrentStatus.cs b/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceCurrentStatus.cs index 0cfa5646..20626973 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceCurrentStatus.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceCurrentStatus.cs @@ -14,8 +14,8 @@ namespace BPASmartClient.JXJFoodSmallStation.Model private double _mWeight; - public bool RunStatus { get { return _mRunStatus; } set { _mRunStatus = value; OnPropertyChanged(); } } - private bool _mRunStatus; + public ushort RunStatus { get { return _mRunStatus; } set { _mRunStatus = value; OnPropertyChanged(); } } + private ushort _mRunStatus; public int DeviceNum { get { return _mDeviceNum; } set { _mDeviceNum = value; OnPropertyChanged(); } } diff --git a/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceInquire.cs b/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceInquire.cs index 02bc9a42..10f0f3c8 100644 --- a/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceInquire.cs +++ b/BPASmartClient.JXJFoodSmallStation/Model/RawMaterial/DeviceInquire.cs @@ -43,12 +43,14 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { TopDeviceCurrentStatuses.ElementAt(TopIndex).Weight = DeviceLists.ElementAt(i).Value.deviceStatus.WeightFeedback; TopDeviceCurrentStatuses.ElementAt(TopIndex).DeviceNum = DeviceLists.ElementAt(i).Value.deviceStatus.DeviceNum; + TopDeviceCurrentStatuses.ElementAt(TopIndex).RunStatus = DeviceLists.ElementAt(i).Value.deviceStatus.RunStatus; } if (BottomIndex >= 0 && BottomIndex < BottomDeviceCurrentStatuses.Count) { BottomDeviceCurrentStatuses.ElementAt(BottomIndex).Weight = DeviceLists.ElementAt(i).Value.deviceStatus.WeightFeedback; BottomDeviceCurrentStatuses.ElementAt(BottomIndex).DeviceNum = DeviceLists.ElementAt(i).Value.deviceStatus.DeviceNum; + BottomDeviceCurrentStatuses.ElementAt(BottomIndex).RunStatus = DeviceLists.ElementAt(i).Value.deviceStatus.RunStatus; } int deviceIndex = Array.FindIndex(devices.ToArray(), p => p.IpAddress == DeviceLists.ElementAt(i).Key && p.DeviceName != DeviceLists.ElementAt(i).Value.DeviceName); @@ -68,7 +70,9 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { DeviceName = $"测试设备{i + 1}", DeviceNum = i + 1, + RunStatus = 1, Weight = new Random().Next(100, 10000) / 100.0 + }); devices.Add(new Devices() @@ -84,6 +88,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { DeviceName = $"测试设备{i + 1}", DeviceNum = i + 1, + RunStatus = 1, Weight = new Random().Next(100, 10000) / 100.0 }); @@ -293,7 +298,6 @@ namespace BPASmartClient.JXJFoodSmallStation.Model { this.DeviceName = DeviceName; AlarmHelper.Init(); - AlarmHelper.Alarm.EStop1 = true; if (modbusTcp.Connected) { ThreadManage.GetInstance().StartLong(new Action(() => @@ -310,7 +314,7 @@ namespace BPASmartClient.JXJFoodSmallStation.Model deviceStatus.DeviceNum = (ushort)this.modbusTcp.ReadShort(DeviceAddress.DeviceNum);//获取设备编号 deviceStatus.DeviceAlarmCode = (ushort)this.modbusTcp.ReadShort(DeviceAddress.DeviceAlarmCode);//获取设备故障编码 - //AlarmHelper.Alarm.EStop1 = deviceStatus.DeviceAlarmCode.Get16bitValue(1); + AlarmHelper.Alarm.EStop1 = deviceStatus.DeviceAlarmCode.Get16bitValue(1); AlarmHelper.Alarm.Servo = deviceStatus.DeviceAlarmCode.Get16bitValue(2); AlarmHelper.Alarm.Inverter = deviceStatus.DeviceAlarmCode.Get16bitValue(3); AlarmHelper.Alarm.EStop2 = deviceStatus.DeviceAlarmCode.Get16bitValue(7); @@ -328,9 +332,9 @@ namespace BPASmartClient.JXJFoodSmallStation.Model this.modbusTcp.SetString(DeviceAddress.DeviceName, name); } - public void StatusReset() + public string StatusReset() { - this.modbusTcp.Write(DeviceAddress.FinfishStatus, (ushort)1); + return this.modbusTcp.Write(DeviceAddress.FinfishStatus, (ushort)1); //var res = modbusTcp.Read(DeviceAddress.RunStatus); } @@ -344,8 +348,15 @@ namespace BPASmartClient.JXJFoodSmallStation.Model if (modbusTcp.Connected) { modbusTcp.SetReal(DeviceAddress.WeightSet, Value);//写入配方量 - modbusTcp.Write(DeviceAddress.Start, (ushort)1);//设备启动写入 - MessageLog.GetInstance.ShowRunLog($"开始配料"); + string returnValue = modbusTcp.Write(DeviceAddress.Start, (ushort)1);//设备启动写入 + if (returnValue.Substring(0, 2) == "成功") + { + MessageLog.GetInstance.ShowRunLog("发送成功" + returnValue); + } + else + { + MessageLog.GetInstance.ShowRunLog("发送失败" + returnValue); + } //配料设备参数写入 var res = Json.Data.deviceParModels.FirstOrDefault(p => p.MaterialName == DeviceName); if (res != null) diff --git a/BPASmartClient.JXJFoodSmallStation/View/HardwareStatusView.xaml b/BPASmartClient.JXJFoodSmallStation/View/HardwareStatusView.xaml index 625f2a14..efff9b75 100644 --- a/BPASmartClient.JXJFoodSmallStation/View/HardwareStatusView.xaml +++ b/BPASmartClient.JXJFoodSmallStation/View/HardwareStatusView.xaml @@ -62,7 +62,7 @@ - + + + + + + - + + + + (string address, T value, byte slaveAddress = 1) + public string Write(string address, T value, byte slaveAddress = 1) { - if (address == null || tcpClient == null) return; + if (address == null || tcpClient == null) return "失败,地址为空或断开连接"; ushort startAddress = (ushort)GetAddress(address); CommandType commandType = CommandType.Coils; try @@ -305,11 +305,16 @@ namespace BPASmartClient.Modbus { commandType = CommandType.Inputs; } + + return $"成功,地址:{address},值:{value}"; } catch (Exception ex) { MessageLog.GetInstance.ShowEx($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}"); + ExceptionHandling(ex); + + return $"异常,地址:{address},值:{value},发送异常"; } } diff --git a/BPASmartClient.S7Net/SiemensHelper.cs b/BPASmartClient.S7Net/SiemensHelper.cs index 0a2a1ccb..7ec56301 100644 --- a/BPASmartClient.S7Net/SiemensHelper.cs +++ b/BPASmartClient.S7Net/SiemensHelper.cs @@ -58,11 +58,16 @@ namespace BPASmartClient.S7Net return myPlc?.Read(dataType, db, address, varType, count); } - public void Write(string address, TValue value) + public string Write(string address, TValue value) { if (IsConnected) { myPlc?.Write(address, value); + return $"成功,地址:{address},值:{value}"; + } + else + { + return $"失败,地址:{address},值:{value},断开连接"; } } diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index 40b697f6..6472b679 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -337,7 +337,7 @@ namespace BPASmartClient.DosingSystem.Model if (modbusTcp.Connected) { modbusTcp.SetReal(DeviceAddress.WeightSet, Value);//写入配方量 - modbusTcp.Write(DeviceAddress.Start, (ushort)1);//设备启动写入 + string returnValue = modbusTcp.Write(DeviceAddress.Start, (ushort)1);//设备启动写入 //配料设备参数写入 var res = Json.Data.deviceParModels.FirstOrDefault(p => p.MaterialName == DeviceName); if (res != null)