diff --git a/DosingSystem/App.xaml.cs b/DosingSystem/App.xaml.cs index 649ffe85..f851aaaa 100644 --- a/DosingSystem/App.xaml.cs +++ b/DosingSystem/App.xaml.cs @@ -142,6 +142,7 @@ namespace BPASmartClient.DosingSystem Alias = "Recipe Management", subMenumodels = RecipeManage, }); + #endregion #region 参数设置 @@ -161,7 +162,13 @@ namespace BPASmartClient.DosingSystem AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.CommParSetView" }); - + ParSet.Add(new SubMenumodel() + { + SubMenuName = "测试", + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, + AssemblyName = "BPASmartClient.DosingSystem", + ToggleWindowPath = "View.SendCtrlView" + }); //ParSet.Add(new SubMenumodel() //{ // SubMenuName = "出料口管理设置", diff --git a/DosingSystem/Converter/RunStatusConvert.cs b/DosingSystem/Converter/RunStatusConvert.cs index c104e232..1329c03f 100644 --- a/DosingSystem/Converter/RunStatusConvert.cs +++ b/DosingSystem/Converter/RunStatusConvert.cs @@ -4,6 +4,53 @@ using System.Windows.Data; namespace BPASmartClient.DosingSystem.Converter { + public class AutoConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool temp) + { + if (temp) + { + return "自动"; + } + else + { + return "手动"; + } + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + public class RunStateConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool temp) + { + if (temp) + { + return "系统启动"; + } + else + { + return "系统停止"; + } + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + + } public class RunStatusConvert : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/DosingSystem/ExcuteControl .cs b/DosingSystem/ExcuteControl .cs index 76375476..cf15b0d1 100644 --- a/DosingSystem/ExcuteControl .cs +++ b/DosingSystem/ExcuteControl .cs @@ -101,8 +101,9 @@ namespace BPASmartClient.DosingSystem }), "取消配方"); //AliYunInit(); - RecipeRun(); - BusinessExcute(); + //RecipeRun(); + //BusinessExcute(); + MatchRun(); ConveyerPropertyReport(); ThreadTaskInit(); #if Debug @@ -864,21 +865,24 @@ namespace BPASmartClient.DosingSystem { for (int i = 0; i < Recipes.ElementAt(index).RawMaterials.Count; i++) { + string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp; + var device = DeviceInquire.GetInstance.GetDevice(ip); + if (!device.IsConnected) + { + MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error); + return; + } if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1) { - string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp; - var device = DeviceInquire.GetInstance.GetDevice(ip); + if (ip == null && ip == "") { MessageNotify.GetInstance.ShowDialog($"原料 【{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName}】配料系统无法配料,请人工配置此原料:原料{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName},重量{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialWeight}", DialogType.Information); return; } - if (!device.IsConnected) - { - MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error); - return; - } + } + } Recipes.ElementAt(index).IsEnable = false; @@ -1366,5 +1370,393 @@ namespace BPASmartClient.DosingSystem } + public ConcurrentDictionary doDeviceCount = new ConcurrentDictionary(); + + int doDecipeCount = 0; + private void MatchRun() + { + + recipeProcesses.Clear(); + + TaskManage.GetInstance.StartLong(() => + { + SimensSend.GetInstance.SendSimens.Write("M0.0", true); + SimensSend.GetInstance.SendSimens.Write("M0.1", true); + if (RecipeNames.Count > 0) + { + + for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++) + { + if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress)) + { + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1) + { + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 0) + { + if (!doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress)) + { + doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0); + + } + int index = 0; + if (doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]< RecipeNames.Count) + { + index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress])); + + if (index > 0 && index < Recipes.Count) + { + App.Current.Dispatcher.Invoke(new Action(() => + { + if (UserTreeWait.Count > 0) + { + recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(0))); + UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(0))); + } + })); + int maxPail = 0; + foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials) + { + if (rawMaterial.Loc > maxPail) + { + maxPail = rawMaterial.Loc; + } + } + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.DeletePassPail.ToAdd(), 1); + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.MaxPail.ToAdd(), (ushort)maxPail); + doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress] + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]); + } + + } + + } + } + + + } + } + //if (doDeviceCount.ContainsKey("192.168.2.10")&&doDeviceCount.ContainsKey($"192.168.2.{Json.Data.BaseParModel.StockCount * 10}")) + //{ + // if (doDeviceCount[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"] > 0 && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"].deviceStatus.DoRecipeCount == doDeviceCount[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"]) + // { + // App.Current.Dispatcher.Invoke(new Action(() => + // { + // UserTreeCompelete.Insert(0, recipeProcesses.Last()); + // recipeProcesses.Remove(recipeProcesses.Last()); + // })); + + // } + // if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.DoRecipeCount == doDeviceCount["192.168.2.10"]) + // { + // App.Current.Dispatcher.Invoke(new Action(() => + // { + // if (UserTreeWait.Count > 0) + // { + // recipeProcesses.Insert(0, UserTreeWait[0]); + // UserTreeWait.RemoveAt(0); + // } + // })); + // } + //} + + + } + + + Thread.Sleep(10); + }, "设备下发配方"); + + TaskManage.GetInstance.StartLong(() => + { + + for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++) + { + if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress) && doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress)) + { + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 && doDecipeCount > 0) + { + int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount-1)); + if (doCount >= 0 && doCount < Recipes.Count) + { + var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().FindAll(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + foreach (RawMaterialModel item in res) + { + if (item != null && item.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail) + { + DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + if (deviceSet != null && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].IsConnected == true) + { + //开始配料信号 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1); + //传送带停止 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + //设置下料重量 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), item.RawMaterialWeight); + //设置慢加重量 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight); + //设置快慢加速度 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowAcceleration); + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), deviceSet.RapidAcceleration); + //设置提前关阀重量 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight); + //设置伺服手动速度 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed); + //设置料仓上下限重量 + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight); + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo); + ////设置搅拌速度 + //DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed); + } + } + } + } + + + } + } + + } + + Thread.Sleep(10); + }, "下发设备参数"); + + + DeviceStatus nextDevice = new DeviceStatus(); + TaskManage.GetInstance.StartLong(() => + { + + for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++) + { + if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress)) + { + if (DeviceInquire.GetInstance.devices[i].IpAddress != $"192.168.2.{Json.Data.BaseParModel.StockCount * 10}") + { + + ushort deviceNum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum; + string nextIp = ""; + if (DeviceInquire.GetInstance.DeviceLists.TryGetValue($"{Json.Data.BaseParModel.NetworkSegAddress}{(deviceNum+1) * 10}", out nextDevice)&& deviceNum!=0) + { + nextIp = DeviceInquire.GetInstance.DeviceLists.ToList().Find(q => q.Value == nextDevice).Key; + } + if ( nextIp != "") + { + //if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 3) + //{ + // DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 1000); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + //} + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3) + { + + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PailArrive == 1) + { + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + } + else + { + DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 500); + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + } + } + else + { + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + //传送带停止 + } + + //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 1000); + //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + //else if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 1) + //{ + // //传送带运行 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1); + // DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + //} + + } + + } + else + { + if (SimensSend.GetInstance.sendCtrlModel.SendInfo) + { + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0); + + } + else + { + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 500); + DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)1); + } + //传送带终点为3则传送带停止,小于3则按照出料状态运行 + } + + + + if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail != 0 && (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)) + { + + } + + } + } + + + Thread.Sleep(10); + }, "控制传送带"); + //TaskManage.GetInstance.StartLong(() => + //{ + // if (RecipeNames.Count > 0) + // { + // SimensSend.GetInstance.SendSimens.Write("M0.0", true); + // SimensSend.GetInstance.SendSimens.Write("M0.1", true); + // if (DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"].deviceStatus.MaxPassPail != 0 && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json.Data.BaseParModel.StockCount * 10}"].deviceStatus.RunStatus == 1) + // { + // recipeProcesses.Remove(recipeProcesses.Last()); + // UserTreeCompelete.Insert(0, recipeProcesses.Last()); + + // } + // for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++) + // { + // if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress)) + // { + + + // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == 0 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1) + // { + + // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail|| recipeProcesses.Count==0) + // { + + // int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0)); + // if (index >= 0 && index < Recipes.Count) + // { + // App.Current.Dispatcher.Invoke(new Action(() => + // { + // if (UserTreeWait.Count > 0) + // { + // recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(0))); + // UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(0))); + // } + // })); + // int maxPail = 0; + // foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials) + // { + // if (rawMaterial.Loc > maxPail) + // { + // maxPail = rawMaterial.Loc; + // } + // } + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.DeletePassPail.ToAdd(), 1); + // //Thread s = new Thread(() => { mmm(); }); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.MaxPail.ToAdd(), (ushort)maxPail); + + // } + // } + + + + // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1) + // { + // int doCount = Array.FindIndex(Recipes.ToArray(), p => p.SerialNum == (int)DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount-1) ; + // if (doCount >=0) + // { + // var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().FindAll(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // foreach (RawMaterialModel item in res) + // { + // if (item != null && item.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail) + // { + // DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // if (deviceSet != null) + // { + // //开始配料信号 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1); + // //传送带停止 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + // //设置下料重量 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), item.RawMaterialWeight); + // //设置慢加重量 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight); + // //设置快慢加速度 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowAcceleration); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), deviceSet.RapidAcceleration); + // //设置提前关阀重量 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight); + // //设置伺服手动速度 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed); + // //设置料仓上下限重量 + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo); + // ////设置搅拌速度 + // //DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed); + // } + // } + // } + // } + // } + + + + // } + // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail != 0 && (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)) + // { + // string passName = RecipeNames.ElementAt(0); + // RecipeNames.TryDequeue(out passName); + // } + // if (DeviceInquire.GetInstance.devices[i].IpAddress != $"192.168.2.{Json.Data.BaseParModel.StockCount * 10}") + // { + // if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 3) + // { + // DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 1000); + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + // } + // //if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3) + // //{ + // // DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 1000); + // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + // //} + // //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), 1000); + // //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + // //else if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 1) + // //{ + // // //传送带运行 + // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1); + // // DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); + // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp); + // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + // //} + // else + // { + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + // //传送带停止 + // } + // } + // else + // { + // if (SimensSend.GetInstance.sendCtrlModel.Stop) + // { + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); + // } + // else + // { + // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); + // } + // //传送带终点为3则传送带停止,小于3则按照出料状态运行 + // } + // } + + // } + + // } + + // Thread.Sleep(10); + //}, "启动配方下发", true); + } + } } diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index cadb6ff7..51da7d30 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -26,7 +26,7 @@ namespace BPASmartClient.DosingSystem public static DeviceInquire GetInstance => _Instance ?? (_Instance = new DeviceInquire()); private DeviceInquire() { } - string IPSegment = "192.168.0."; + string IPSegment = "192.168.2."; public ConcurrentDictionary DeviceLists = new ConcurrentDictionary(); List InvalidIP = new List();//无效 IP 集合 List IPLists = new List();//启动 Ping 任务IP集合 @@ -150,11 +150,12 @@ namespace BPASmartClient.DosingSystem if (!string.IsNullOrEmpty(Json.Data.BaseParModel.NetworkSegAddress)) IPSegment = Json.Data.BaseParModel.NetworkSegAddress; else Json.Data.BaseParModel.NetworkSegAddress = IPSegment; stockCount = Json.Data.BaseParModel.StockCount; - TestData(); + //TestData(); IpAddressLines(); Task.Factory.StartNew(() => { - SiemensDevice.GetInstance.Connect(Json.Data.BaseParModel.DeviceAddress); + SimensSend.GetInstance.Connect(); + //SiemensDevice.GetInstance.Connect(Json.Data.BaseParModel.DeviceAddress); }); DeviceDataInit(); TaskManage.GetInstance.StartLong(new Action(() => @@ -196,6 +197,7 @@ namespace BPASmartClient.DosingSystem { IPLists.Clear(); IPQueues.Clear(); + //TestData(); /*for (int i = 1; i <= 255; i++) { if (!InvalidIP.Contains($"{IPSegment}{i}") && !DeviceLists.ContainsKey($"{IPSegment}{i}")) @@ -207,7 +209,7 @@ namespace BPASmartClient.DosingSystem } } }*/ - + for (int i = 0; i < stockCount; i++) { IPLists.Add($"{IPSegment}{(i + 1) * 10}"); @@ -228,6 +230,7 @@ namespace BPASmartClient.DosingSystem if (e.Reply != null && e.Reply.Status == IPStatus.Success) { string ip = e.Reply.Address.ToString(); + if (!DeviceLists.ContainsKey(ip)) { DeviceStatus DS = new DeviceStatus(); @@ -236,7 +239,9 @@ namespace BPASmartClient.DosingSystem DS.modbusTcp.Connected = new Action(() => { var tt = DS.modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20); + string DeviceName = DS.modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20).Content?.Trim()?.Replace(" ", "");//读取设备名称 + if (DeviceName.Length > 0) { DeviceLists.TryAdd(ip, DS); @@ -369,7 +374,7 @@ namespace BPASmartClient.DosingSystem ////获取设备料仓剩余重量 var wf = this.modbusTcp.Read(DeviceAddress.WeightFeedback.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); - if (wf.IsSuccess) deviceStatus.WeightFeedback = (float)(wf.Content); + if (wf.IsSuccess) deviceStatus.WeightFeedback = (uint)(wf.Content); ////获取下料重量 var nwf = this.modbusTcp.Read(DeviceAddress.CutWeightFeedback.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); @@ -415,16 +420,16 @@ namespace BPASmartClient.DosingSystem var ss = this.modbusTcp.Read(DeviceAddress.StirringSpeed.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (ss.IsSuccess) deviceStatus.StirringSpeed = ss.Content; //获取桶是否到位 - var pailArrive = this.modbusTcp.Read(DeviceAddress.PailArrive.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); + var pailArrive = this.modbusTcp.Read(DeviceAddress.PailArrive.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (pailArrive.IsSuccess) deviceStatus.PailArrive = pailArrive.Content; //已通过桶数 - var pass = this.modbusTcp.Read(DeviceAddress.PassPail.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); + var pass = this.modbusTcp.Read(DeviceAddress.PassPail.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (pass.IsSuccess) deviceStatus.PassPail = pass.Content; //配料最大桶数 - var max = this.modbusTcp.Read(DeviceAddress.MaxPail.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); + var max = this.modbusTcp.Read(DeviceAddress.MaxPail.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (max.IsSuccess) deviceStatus.MaxPassPail = max.Content; //执行配方数 - var doCount = this.modbusTcp.Read(DeviceAddress.DoRecipeCount.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); + var doCount = this.modbusTcp.Read(DeviceAddress.DoRecipeCount.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (doCount.IsSuccess) deviceStatus.DoRecipeCount = doCount.Content; //this.DeviceName = modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20).Content.Trim().Replace(" ", ""); //deviceStatus.RunStatus = (ushort)this.modbusTcp.Read(DeviceAddress.RunStatus.ToAdd()).Content; //获取设备运行状态 @@ -673,38 +678,38 @@ namespace BPASmartClient.DosingSystem if (value8 != null && value8.ToString() != res.StirringSpeed.ToString()) goto prop8; MessageNotify.GetInstance.ShowRunLog($"{res.MaterialName},配料参数下发完成"); } - prop9: - modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), Value);//写入配方重量 - MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value}"); - - var value9 = modbusTcp.Read(DeviceAddress.WeightSet.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; - if ((value9 != null && value9.ToString() != Value.ToString()) || value9 == 0) goto prop9; - //prop10: - //MessageNotify.GetInstance.ShowRunLog($"写入配方重量,值{Value}:{value9}"); - //modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入 - //var value10 = modbusTcp.Read(DeviceAddress.Start.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; - //if ((value10 != null && value10.ToString() != 1.ToString())||value10==0) goto prop10; - //modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), Value);//写入配方重量 - modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入 - Task.Run(() => - { - while (true) - { - ushort c = modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; - MessageNotify.GetInstance.ShowRunLog($"{IpAddress}:LW51,值:{modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content}"); - string str = DecToBinary(c); - if (str[8].ToString() == 0.ToString()) - { - modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入 - } - else - return; - } + //prop9: + // modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), Value);//写入配方重量 + // MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value}"); + + // var value9 = modbusTcp.Read(DeviceAddress.WeightSet.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; + // if ((value9 != null && value9.ToString() != Value.ToString()) || value9 == 0) goto prop9; + // //prop10: + // //MessageNotify.GetInstance.ShowRunLog($"写入配方重量,值{Value}:{value9}"); + // //modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入 + // //var value10 = modbusTcp.Read(DeviceAddress.Start.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; + // //if ((value10 != null && value10.ToString() != 1.ToString())||value10==0) goto prop10; + // //modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), Value);//写入配方重量 + // modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入 + // Task.Run(() => + // { + // while (true) + // { + // ushort c = modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; + // MessageNotify.GetInstance.ShowRunLog($"{IpAddress}:LW51,值:{modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content}"); + // string str = DecToBinary(c); + // if (str[8].ToString() == 0.ToString()) + // { + // modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入 + // } + // else + // return; + // } - }); + // }); - MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value},味魔方启动配料"); + // MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value},味魔方启动配料"); } } diff --git a/DosingSystem/Model/Expand.cs b/DosingSystem/Model/Expand.cs index c18feeab..b6c1136f 100644 --- a/DosingSystem/Model/Expand.cs +++ b/DosingSystem/Model/Expand.cs @@ -1,9 +1,21 @@ using System; +using System.Windows.Forms; namespace BPASmartClient.DosingSystem.Model { public static class Expand { + public static bool Tobool(this ushort value) + { + if (value == 1) + { + return true; + } + else + { + return false; + } + } /// /// 获取 M 区 和 VW 区的Modbus的地址 /// diff --git a/DosingSystem/Model/RawMaterialDeviceStatus.cs b/DosingSystem/Model/RawMaterialDeviceStatus.cs index 4fa7450a..d7833ba9 100644 --- a/DosingSystem/Model/RawMaterialDeviceStatus.cs +++ b/DosingSystem/Model/RawMaterialDeviceStatus.cs @@ -16,7 +16,7 @@ namespace BPASmartClient.DosingSystem /// /// 料仓重量反馈 /// - public float WeightFeedback { get; set; } + public uint WeightFeedback { get; set; } /// /// 当前出料重量反馈 @@ -101,18 +101,18 @@ namespace BPASmartClient.DosingSystem /// /// 最大通过桶数 /// - public uint MaxPassPail { get; set; } + public ushort MaxPassPail { get; set; } /// /// 已通过桶数 /// - public uint PassPail { get; set; } + public ushort PassPail { get; set; } /// /// 到位检测 为1有桶。0无桶 /// - public uint PailArrive { get; set; } + public ushort PailArrive { get; set; } /// /// 设备执行配方数量 /// - public uint DoRecipeCount { get;set; } + public ushort DoRecipeCount { get;set; } } } diff --git a/DosingSystem/Model/SendCtrlModel.cs b/DosingSystem/Model/SendCtrlModel.cs new file mode 100644 index 00000000..59beae31 --- /dev/null +++ b/DosingSystem/Model/SendCtrlModel.cs @@ -0,0 +1,68 @@ +using BPA.Helper; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.Model +{ + public class SendCtrlModel:NotifyBase + { + + /// + /// T0料仓输送限制 + /// + public bool SendInfo{get { return _sendInfo; }set { _sendInfo = value;OnPropertyChanged(); }} + private bool _sendInfo; + + /// + /// 急停 + /// + public bool Stop{get { return _stop; }set { _stop = value; OnPropertyChanged(); } } + private bool _stop; + /// + /// 出桶光电1 + /// + public bool OutputOptical_1 { get { return _outputOptical_1; } set { _outputOptical_1 = value; OnPropertyChanged(); } } + private bool _outputOptical_1; + /// + /// 出桶光电2 + /// + public bool OutputOptical_2 { get { return _outputOptical_2; } set { _outputOptical_2 = value; OnPropertyChanged(); } } + private bool _outputOptical_2; + /// + /// 出桶光电3 + /// + public bool OutputOptical_3 { get { return _outputOptical_3; } set { _outputOptical_3 = value; OnPropertyChanged(); } } + private bool _outputOptical_3; + /// + /// 出桶光电3 + /// + public bool InputOptical_1 { get { return _inputOptical_1; } set { _inputOptical_1 = value; OnPropertyChanged(); } } + private bool _inputOptical_1; + /// + /// 出桶光电3 + /// + public ObservableCollection CylinderModels { get; set; } = new ObservableCollection(); + } + public class CylinderModel:NotifyBase + { + /// + /// 开到位 + /// + public bool OnStatus { get { return _onStatus; } set { _onStatus = value; OnPropertyChanged(); } } + private bool _onStatus; + /// + /// 关到位 + /// + public bool OffStatus { get { return _offStatus; } set { _offStatus = value; OnPropertyChanged(); } } + private bool _offStatus; + /// + /// 气缸名称 + /// + public string Name { get { return _name; } set { _name = value; OnPropertyChanged(); } } + private string _name; + } +} diff --git a/DosingSystem/Model/par/BasePar.cs b/DosingSystem/Model/par/BasePar.cs index d3439bb0..6c5591cd 100644 --- a/DosingSystem/Model/par/BasePar.cs +++ b/DosingSystem/Model/par/BasePar.cs @@ -12,13 +12,13 @@ namespace BPASmartClient.DosingSystem /// 设备扫描网段 /// public string NetworkSegAddress { get { return _mNetworkSegAddress; } set { _mNetworkSegAddress = value; OnPropertyChanged(); } } - private string _mNetworkSegAddress = "192.168.0."; + private string _mNetworkSegAddress = "192.168.2."; /// /// 输送带设备 PLC IP 地址 /// public string DeviceAddress { get { return _mDeviceAddress; } set { _mDeviceAddress = value; OnPropertyChanged(); } } - private string _mDeviceAddress = "192.168.0.15"; + private string _mDeviceAddress = "192.168.2.200"; /// diff --git a/DosingSystem/Model/par/DeviceParModel.cs b/DosingSystem/Model/par/DeviceParModel.cs index b12a5b63..b18637c2 100644 --- a/DosingSystem/Model/par/DeviceParModel.cs +++ b/DosingSystem/Model/par/DeviceParModel.cs @@ -25,14 +25,14 @@ namespace BPASmartClient.DosingSystem /// /// 快加速度 /// - public int RapidAcceleration { get { return _mRapidAcceleration; } set { _mRapidAcceleration = value; OnPropertyChanged(); } } - private int _mRapidAcceleration; + public float RapidAcceleration { get { return _mRapidAcceleration; } set { _mRapidAcceleration = value; OnPropertyChanged(); } } + private float _mRapidAcceleration; /// /// 慢加速度 /// - public int SlowAcceleration { get { return _mSlowAcceleration; } set { _mSlowAcceleration = value; OnPropertyChanged(); } } - private int _mSlowAcceleration; + public float SlowAcceleration { get { return _mSlowAcceleration; } set { _mSlowAcceleration = value; OnPropertyChanged(); } } + private float _mSlowAcceleration; /// /// 伺服手动速度 @@ -65,7 +65,7 @@ namespace BPASmartClient.DosingSystem public bool IsRedundant { get { return _mIsRedundant; } set { _mIsRedundant = value; OnPropertyChanged(); } } private bool _mIsRedundant; /// - /// 2023.10.10添加字段 + /// 2023.10.10添加字段 输送速度 /// public ushort SendSp { get { return _sendSp; } set { _sendSp = value; OnPropertyChanged(); } } private ushort _sendSp; diff --git a/DosingSystem/Service/SiemensDevice.cs b/DosingSystem/Service/SiemensDevice.cs index 3f1efb93..99c93005 100644 --- a/DosingSystem/Service/SiemensDevice.cs +++ b/DosingSystem/Service/SiemensDevice.cs @@ -1,10 +1,80 @@ using BPA.Communication; using BPA.Helper; +using BPASmartClient.DosingSystem.Model; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal; using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Threading; namespace BPASmartClient.DosingSystem { + public class SimensSend + { + private volatile static SimensSend _Instance; + public static SimensSend GetInstance => _Instance ?? (_Instance = new SimensSend()); + private SimensSend() { } + + static string ip = "192.168.2.200"; + public ObservableCollection sendCtrlModels { get; set; } = new ObservableCollection(); + public SendCtrlModel sendCtrlModel { get; set; } = new SendCtrlModel(); + public Siemens SendSimens { get; set; } = new Siemens(); + private bool IsConnect { get; set; } + public bool tempValue = false; + public void Connect() + { + try + { + + IsConnect = SendSimens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.2.200", cpuType = BPA.Communication.CpuType.S71200, Port = 102 }); + + } + catch (Exception) + { + + //throw; + } + TaskManage.GetInstance.StartLong(new Action(() => + { + if (IsConnect) + { + SendSimens.Write("DB1.DBX704.0", tempValue);//设备心跳 + tempValue = !tempValue; + } + Thread.Sleep(1000); + }), "设备心跳", true); + TaskManage.GetInstance.StartLong(new Action(() => + { + //App.Current.Dispatcher.Invoke(() => { + if (IsConnect) + { + sendCtrlModel.SendInfo = SendSimens.Read("DB1.DBX700.0").Content.Tobool(); + sendCtrlModel.Stop = SendSimens.Read("I0.0").Content.Tobool(); + App.Current.Dispatcher.Invoke(() => + { + if (sendCtrlModel.CylinderModels.Count > 0) + { + sendCtrlModel.CylinderModels.Clear(); + + } + sendCtrlModel.CylinderModels.Add(new CylinderModel() { Name = "气缸3", OnStatus = SendSimens.Read("I0.1").Content.Tobool(), OffStatus = SendSimens.Read("I0.2").Content.Tobool() }); + sendCtrlModel.CylinderModels.Add(new CylinderModel() { Name = "气缸2", OnStatus = SendSimens.Read("I0.4").Content.Tobool(), OffStatus = SendSimens.Read("I0.3").Content.Tobool() }); + sendCtrlModel.CylinderModels.Add(new CylinderModel() { Name = "气缸1", OnStatus = SendSimens.Read("I0.6").Content.Tobool(), OffStatus = SendSimens.Read("I0.5").Content.Tobool() }); + + + }); + + sendCtrlModel.OutputOptical_1 = SendSimens.Read("I0.7").Content.Tobool(); + sendCtrlModel.OutputOptical_2 = SendSimens.Read("I1.0").Content.Tobool(); + sendCtrlModel.OutputOptical_3 = SendSimens.Read("I1.1").Content.Tobool(); + sendCtrlModel.InputOptical_1 = SendSimens.Read("I1.2").Content.Tobool(); + } + //}); + + Thread.Sleep(100); + }), "读取输送线设备数据", true); + } + } public class SiemensDevice { private volatile static SiemensDevice _Instance; @@ -46,7 +116,7 @@ namespace BPASmartClient.DosingSystem }; try { - IsConnect = MySiemens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.0.100", cpuType = BPA.Communication.CpuType.S71200, Port = 102 }); + IsConnect = MySiemens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.2.200", cpuType = BPA.Communication.CpuType.S71200, Port = 102 }); } catch (Exception) diff --git a/DosingSystem/View/SendCtrlView.xaml b/DosingSystem/View/SendCtrlView.xaml new file mode 100644 index 00000000..1b2469e6 --- /dev/null +++ b/DosingSystem/View/SendCtrlView.xaml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DosingSystem/View/SendCtrlView.xaml.cs b/DosingSystem/View/SendCtrlView.xaml.cs new file mode 100644 index 00000000..977b21f6 --- /dev/null +++ b/DosingSystem/View/SendCtrlView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.DosingSystem.View +{ + /// + /// SendCtrlView.xaml 的交互逻辑 + /// + public partial class SendCtrlView : UserControl + { + public SendCtrlView() + { + InitializeComponent(); + } + } +} diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index 80201a8d..5e35a112 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -28,8 +28,7 @@ namespace BPASmartClient.DosingSystem.ViewModel //ChangeRecipeStateCommand = new BPARelayCommand(ChangeRecipeState); //CancelRecipeCommand = new BPARelayCommand(CancelRecipe); //RecipeRun(); - RecipeStatusInquire(); - MatchRun(); + //RecipeStatusInquire(); StartCommand = new BPARelayCommand(new Action((o) => { if (o != null && o is string recipeName) { @@ -122,120 +121,7 @@ namespace BPASmartClient.DosingSystem.ViewModel //} - private void MatchRun() - { - recipeProcesses.Clear(); - TaskManage.GetInstance.StartLong(() => - { - if (RecipeNames.Count > 0) - { - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.MaxPassPail!=0 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices.Last().IpAddress].deviceStatus.RunStatus == 3) - { - recipeProcesses.Remove(recipeProcesses.Last()); - UserTreeCompelete.Insert(0, recipeProcesses.Last()); - - } - for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++) - { - if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress)) - { - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == 0 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3) - { - - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail) - { - string passName = RecipeNames.ElementAt(0); - RecipeNames.TryDequeue(out passName); - int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0)); - if (index > 0 && index < Recipes.Count) - { - App.Current.Dispatcher.Invoke(new Action(() => - { - if (UserTreeWait.Count > 0) - { - recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(0))); - UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(0))); - } - })); - int maxPail = 0; - foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials) - { - if (rawMaterial.Loc > maxPail) - { - maxPail = rawMaterial.Loc; - } - } - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.DeletePassPail.ToAdd(), 1); - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.MaxPail.ToAdd(), (ushort)maxPail); - - } - } - - - - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1) - { - int doCount = Array.FindIndex(Recipes.ToArray(), p => p.SerialNum == (int)DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount); - RawMaterialModel res = Recipes.ElementAt(doCount).RawMaterials?.ToList().Find(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); - if (res != null && res.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail) - { - DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); - if (deviceSet != null) - { - //设置启动 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.Start.ToAdd(), 1); - //设置下料重量 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), res.RawMaterialWeight); - //设置慢加重量 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight); - //设置快慢加速度 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowAcceleration); - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), deviceSet.RapidAcceleration); - //设置提前关阀重量 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight); - //设置伺服手动速度 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed); - //设置料仓上下限重量 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight); - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo); - //设置搅拌速度 - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed); - } - } - - - } - - - } - if (i < DeviceInquire.GetInstance.devices.Count - 1) - { - if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 0) - { - //传送带运行 - DeviceParModel deviceSet = Json.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName); - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp); - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 1); - } - else - { - DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write(DeviceAddress.TranspportSwitch.ToAdd(), 0); - //传送带停止 - } - } - else - { - //传送带终点为3则传送带停止,小于3则按照出料状态运行 - } - } - - } - - } - - Thread.Sleep(100); - }, "启动配方下发", true); - } + /// /// 配方业务执行 @@ -1139,12 +1025,12 @@ namespace BPASmartClient.DosingSystem.ViewModel /// /// 等待制作的配方 /// - public static ObservableCollection UserTreeWait { get; set; } = new ObservableCollection(); + public static ObservableCollection UserTreeWait { get; set; } = ExcuteControl.GetInstance.UserTreeWait; /// /// 已完成的配方 /// - public static ObservableCollection UserTreeCompelete { get; set; } = new ObservableCollection(); + public static ObservableCollection UserTreeCompelete { get; set; } = ExcuteControl.GetInstance.UserTreeCompelete; //private void ChangeRecipeState(object o) diff --git a/DosingSystem/ViewModel/SendCtrlViewModel.cs b/DosingSystem/ViewModel/SendCtrlViewModel.cs new file mode 100644 index 00000000..f21c035e --- /dev/null +++ b/DosingSystem/ViewModel/SendCtrlViewModel.cs @@ -0,0 +1,52 @@ +using BPA.Helper; +using BPASmartClient.DosingSystem.Model; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.ViewModel +{ + public class SendCtrlViewModel:NotifyBase + { + public SendCtrlViewModel() + { + + } + + + /// + /// 传送带状态显示 + /// + public SendCtrlModel SendCtrlModel { get { return sendCtrlModel; } set { sendCtrlModel = value; OnPropertyChanged(); } } + private SendCtrlModel sendCtrlModel = SimensSend.GetInstance.sendCtrlModel; + + public BPARelayCommand MyProperty { get; set; } + + + + /// + /// 系统启停控制 + /// + public bool RunState{ get { return _runState; }set { _runState = value; OnPropertyChanged(); }} + private bool _runState = false; + + + /// + /// 自动 + /// + public bool AutoCtrl{get { return _autoCtrl; }set { _autoCtrl = value;OnPropertyChanged(); }} + private bool _autoCtrl = true; + + /// + /// 手动 + /// + public bool HandCtrl { get { return _handCtrl; } set { _handCtrl = value; OnPropertyChanged(); } } + private bool _handCtrl; + + } +} +