diff --git a/DosingSystem/ExcuteControl.cs b/DosingSystem/ExcuteControl.cs index e46cb314..b1ebe2f8 100644 --- a/DosingSystem/ExcuteControl.cs +++ b/DosingSystem/ExcuteControl.cs @@ -55,7 +55,7 @@ namespace BPASmartClient.DosingSystem /// /// 等待制作的配方 /// - public ObservableCollection UserTreeWait { get; set; } = new ObservableCollection() { new RecipeModel { RecipeName="we"} }; + public ObservableCollection UserTreeWait { get; set; } = new ObservableCollection(); /// /// 已完成的配方 @@ -375,7 +375,6 @@ namespace BPASmartClient.DosingSystem mqdeviceTestProperty.Init(); var message = JsonConvert.SerializeObject(mqdeviceTestProperty); var topic = $"/sys/{produtInfo.Get("ProductKey")}/{aliyun[ipaddres]}/thing/event/property/post";//发布主题 - var topicReply = $"/sys/{produtInfo.Get("ProductKey")}/{aliyun[ipaddres]}/thing/event/property/post_reply";//订阅主题 if (mqttCollection.ContainsKey(aliyun[ipaddres])) { @@ -764,9 +763,9 @@ namespace BPASmartClient.DosingSystem { if (RecipeName != null) { - var res = MessageNotify.GetInstance.ShowDialog($"是否取消配方 【{RecipeName}】制作", DialogType.Warning); - if (res) - { + //var res = MessageNotify.GetInstance.ShowDialog($"是否取消配方 【{RecipeName}】制作", DialogType.Warning); + //if (res) + //{ int index = Recipes.ToList().FindIndex(p => p.RecipeName == RecipeName); if (index >= 0 && index < Recipes.Count) { @@ -781,7 +780,10 @@ namespace BPASmartClient.DosingSystem Thread.Sleep(1000); SiemensDevice.GetInstance.MySiemens.Write("M10.5", false); MessageNotify.GetInstance.ShowRunLog($"M10.5:false"); - NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方 [{RecipeName}] 取消成功"); + App.Current.Dispatcher.Invoke(() => + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方 [{RecipeName}] 取消成功"); + }); MessageNotify.GetInstance.ShowUserLog($"取消配方制作 {RecipeName}"); //取消成功 })); @@ -790,11 +792,11 @@ namespace BPASmartClient.DosingSystem { //取消失败 } - } + //} } else { - //取消失败 + MessageNotify.GetInstance.ShowUserLog($"配方 {RecipeName}取消失败"); } } @@ -834,9 +836,9 @@ namespace BPASmartClient.DosingSystem RecipeNames.Enqueue(RecipeName); var res = Recipes.FirstOrDefault(p => p.RecipeName == RecipeName); - UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = RecipeName, RawMaterials = res.RawMaterials }); + App.Current.Dispatcher.Invoke(() => { UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = RecipeName, RawMaterials = res.RawMaterials }); }); } - NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); + App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); }); } /// @@ -857,7 +859,10 @@ namespace BPASmartClient.DosingSystem App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); - if (UserTreeWait.Count > 0) UserTreeWait.RemoveAt(0); + if (UserTreeWait.Count > 0) App.Current.Dispatcher.Invoke(() => + { + UserTreeWait.RemoveAt(0); + }); })); CurrentRecipeName = Recipes.ElementAt(index).RecipeName; #region 执行配方以及等待执行配方上报 diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index 3fab90bc..abfc70ff 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -352,62 +352,62 @@ namespace BPASmartClient.DosingSystem AlarmHelper.Init(); if (IsConnected) { - + TaskManage.GetInstance.StartLong(new Action(() => { var dn = modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20); if (dn.IsSuccess) { this.DeviceName = dn.Content.Trim().Replace(" ", ""); deviceStatus.DeviceName = this.DeviceName; } //获取设备运行状态 - var rs = this.modbusTcp.Read(DeviceAddress.RunStatus.ToAdd()); + var rs = this.modbusTcp.Read(DeviceAddress.RunStatus.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (rs.IsSuccess) deviceStatus.RunStatus = rs.Content; ////获取设备料仓剩余重量 - var wf = this.modbusTcp.Read(DeviceAddress.WeightFeedback.ToAdd()); + var wf = this.modbusTcp.Read(DeviceAddress.WeightFeedback.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (wf.IsSuccess) deviceStatus.WeightFeedback = (float)(wf.Content); ////获取下料重量 - var nwf = this.modbusTcp.Read(DeviceAddress.CutWeightFeedback.ToAdd()); + var nwf = this.modbusTcp.Read(DeviceAddress.CutWeightFeedback.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (nwf.IsSuccess) deviceStatus.NowWeightFeedback = nwf.Content; ////获取设备编号 - var dnum = this.modbusTcp.Read(DeviceAddress.DeviceNum.ToAdd()); + var dnum = this.modbusTcp.Read(DeviceAddress.DeviceNum.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (dnum.IsSuccess) deviceStatus.DeviceNum = dnum.Content; ////获取设备故障编码 - var dac = this.modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd()); + var dac = this.modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (dac.IsSuccess) deviceStatus.DeviceAlarmCode = dac.Content; //获取原料类型 - var mt = this.modbusTcp.Read(DeviceAddress.MaterialDeviceType.ToAdd()); + var mt = this.modbusTcp.Read(DeviceAddress.MaterialDeviceType.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (mt.IsSuccess) deviceStatus.RawMaterialType = mt.Content; //获取工作模式 - var wm = this.modbusTcp.Read(DeviceAddress.WorkModel.ToAdd()); + var wm = this.modbusTcp.Read(DeviceAddress.WorkModel.ToAdd(),1, BPA.Helper.DataFormat.CDAB); if (wm.IsSuccess) deviceStatus.WorkModel = wm.Content.GetBitValue(1); //慢加重量 - var ssaw = this.modbusTcp.Read(DeviceAddress.SlowlyAddWeight.ToAdd()); + var ssaw = this.modbusTcp.Read(DeviceAddress.SlowlyAddWeight.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (ssaw.IsSuccess) deviceStatus.SlowAddWeight = ssaw.Content; //提前关阀重量 - var pcvw = this.modbusTcp.Read(DeviceAddress.PreCloseValveWeight.ToAdd()); + var pcvw = this.modbusTcp.Read(DeviceAddress.PreCloseValveWeight.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (pcvw.IsSuccess) deviceStatus.PreCloseValueWeight = pcvw.Content; //快加速度 - var ra = this.modbusTcp.Read(DeviceAddress.RapidAcceleration.ToAdd()); + var ra = this.modbusTcp.Read(DeviceAddress.RapidAcceleration.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (ra.IsSuccess) deviceStatus.RapidAcceleration = ra.Content; //慢加速度 - var sa = this.modbusTcp.Read(DeviceAddress.SlowAcceleration.ToAdd()); + var sa = this.modbusTcp.Read(DeviceAddress.SlowAcceleration.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (sa.IsSuccess) deviceStatus.SlowAcceleration = sa.Content; //伺服手动速度 - var sms = this.modbusTcp.Read(DeviceAddress.ServoManualSpeed.ToAdd()); + var sms = this.modbusTcp.Read(DeviceAddress.ServoManualSpeed.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (sms.IsSuccess) deviceStatus.ServoManualSpeed = sms.Content; //料仓上限重量 - var ulw = this.modbusTcp.Read(DeviceAddress.SiloUpperLimitWeight.ToAdd()); + var ulw = this.modbusTcp.Read(DeviceAddress.SiloUpperLimitWeight.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (ulw.IsSuccess) deviceStatus.SiloUpperLimitWeight = ulw.Content; //料仓下限重量 - var llw = this.modbusTcp.Read(DeviceAddress.LowerLimitWeightOfSilo.ToAdd()); + var llw = this.modbusTcp.Read(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (llw.IsSuccess) deviceStatus.SiloLowerLimitWeight = llw.Content; //料仓搅拌速度 - var ss = this.modbusTcp.Read(DeviceAddress.StirringSpeed.ToAdd()); + var ss = this.modbusTcp.Read(DeviceAddress.StirringSpeed.ToAdd(), 1, BPA.Helper.DataFormat.CDAB); if (ss.IsSuccess) deviceStatus.StirringSpeed = ss.Content; //this.DeviceName = modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20).Content.Trim().Replace(" ", ""); //deviceStatus.RunStatus = (ushort)this.modbusTcp.Read(DeviceAddress.RunStatus.ToAdd()).Content; //获取设备运行状态 @@ -422,15 +422,21 @@ namespace BPASmartClient.DosingSystem AlarmHelper.GetInstance(DeviceName).EStop2 = deviceStatus.DeviceAlarmCode.GetBitValue(7); AlarmHelper.GetInstance(DeviceName).SiloUpperLimit = deviceStatus.DeviceAlarmCode.GetBitValue(8); AlarmHelper.GetInstance(DeviceName).SiloLowerLimit = deviceStatus.DeviceAlarmCode.GetBitValue(9); + + Thread.Sleep(10); - if (ExcuteControl.GetInstance.mqttCollection.ContainsKey($"Stock{IpAddress.Split(".")[3].Substring(0,1)}") && ExcuteControl.GetInstance.mqttCollection[$"Stock{IpAddress.Split(".")[3].Substring(0, 1)}"]._mqttClient.IsConnected) + }), $"{DeviceName} 开始监听", true); + TaskManage.GetInstance.StartLong(new Action(() => + { + Thread.Sleep(1000); + if (ExcuteControl.GetInstance.mqttCollection.ContainsKey($"Stock{IpAddress.Split(".")[3].Substring(0, 1)}") && ExcuteControl.GetInstance.mqttCollection[$"Stock{IpAddress.Split(".")[3].Substring(0, 1)}"]._mqttClient.IsConnected) { StockPropertyReport(); StockEventReport(); } - Thread.Sleep(10); - }), $"{DeviceName} 开始监听", true); + + }),$"{DeviceName}属性实时上报",true); } } /// @@ -504,26 +510,60 @@ namespace BPASmartClient.DosingSystem public void StockEventReport() { #if !Debug - if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("stop1").Start(AlarmHelper.GetInstance(DeviceName).EStop1)) + try { - ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk1StatusEvent", AliyunMaterialModelType.StockModel); - } - if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("Servo").Start(AlarmHelper.GetInstance(DeviceName).Servo)) - { - ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockServoFalutEvent", AliyunMaterialModelType.StockModel); - } + if (RTrig.GetInstance($"stop1:{IpAddress}").Start(AlarmHelper.GetInstance(DeviceName).EStop1)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk1StatusEvent", AliyunMaterialModelType.StockModel); + } + if (RTrig.GetInstance($"Servo:{IpAddress}").Start(AlarmHelper.GetInstance(DeviceName).Servo)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockServoFalutEvent", AliyunMaterialModelType.StockModel); + } - if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("EStop2").Start(AlarmHelper.GetInstance(DeviceName).EStop2)) - { - ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk2StatusEvent", AliyunMaterialModelType.StockModel); - } - if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("SiloUpperLimit").Start(AlarmHelper.GetInstance(DeviceName).SiloUpperLimit)) - { - ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockUpLimitEvent", AliyunMaterialModelType.StockModel); + if (RTrig.GetInstance($"EStop2:{IpAddress}").Start(AlarmHelper.GetInstance(DeviceName).EStop2)) + { + + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk2StatusEvent", AliyunMaterialModelType.StockModel); + } + if (RTrig.GetInstance($"SiloUpperLimit:{IpAddress}").Start(AlarmHelper.GetInstance(DeviceName).SiloUpperLimit)) + { + if (DeviceName == "盐") + MessageNotify.GetInstance.ShowRunLog("料仓1 上限报警"); + if (DeviceName == "A20") + MessageNotify.GetInstance.ShowRunLog("料仓2 上限报警"); + if (DeviceName == "A30") + MessageNotify.GetInstance.ShowRunLog("料仓3 上限报警"); + if (DeviceName == "A40") + MessageNotify.GetInstance.ShowRunLog("料仓4 上限报警"); + if (DeviceName == "A50") + MessageNotify.GetInstance.ShowRunLog("料仓5 上限报警"); + if (DeviceName == "A60") + MessageNotify.GetInstance.ShowRunLog("料仓6 上限报警"); + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockUpLimitEvent", AliyunMaterialModelType.StockModel); + } + if (RTrig.GetInstance($"SiloLowerLimit:{IpAddress}").Start(AlarmHelper.GetInstance(DeviceName).SiloLowerLimit)) + { + if (DeviceName == "盐") + MessageNotify.GetInstance.ShowRunLog("料仓1 下限报警"); + if (DeviceName == "A20") + MessageNotify.GetInstance.ShowRunLog("料仓2 下限报警"); + if (DeviceName == "A30") + MessageNotify.GetInstance.ShowRunLog("料仓3 下限报警"); + if (DeviceName == "A40") + MessageNotify.GetInstance.ShowRunLog("料仓4 下限报警"); + if (DeviceName == "A50") + MessageNotify.GetInstance.ShowRunLog("料仓5 下限报警"); + if (DeviceName == "A60") + MessageNotify.GetInstance.ShowRunLog("料仓6 下限报警"); + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockDownLimitEvent", AliyunMaterialModelType.StockModel); + + } } - if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("SiloLowerLimit").Start(AlarmHelper.GetInstance(DeviceName).SiloLowerLimit)) + catch (Exception) { - ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockDownLimitEvent", AliyunMaterialModelType.StockModel); + + //throw; } #endif #if Debug diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index 14fdb031..9cd15e18 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -1000,7 +1000,7 @@ namespace BPASmartClient.DosingSystem.ViewModel public BPARelayCommand CancelRecipeCommand { get; set; } - //public static ObservableCollection Recipes { get; set; } = Json.Data.Recipes; + public static ObservableCollection Recipes { get; set; } =ExcuteControl.GetInstance.Recipes; // public static string CurrentRecipeName { get { return _RecipeName; } set { _RecipeName = value; OnStaticPropertyChanged(); } } // private static string _RecipeName; diff --git a/DosingSystem/ViewModel/RecipeSettingsViewModel.cs b/DosingSystem/ViewModel/RecipeSettingsViewModel.cs index f6f44d32..c2d50cad 100644 --- a/DosingSystem/ViewModel/RecipeSettingsViewModel.cs +++ b/DosingSystem/ViewModel/RecipeSettingsViewModel.cs @@ -46,7 +46,7 @@ namespace BPASmartClient.DosingSystem.ViewModel NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方删除成功!"); MessageNotify.GetInstance.ShowUserLog($"删除配方 {res.RecipeName}"); //配方名称集合上报 - if (ExcuteControl.GetInstance.AliyunIsConnect) + if (ExcuteControl.GetInstance.mqttCollection.ContainsKey("Conveyer") && ExcuteControl.GetInstance.mqttCollection["Conveyer"]._mqttClient.IsConnected) { AliyunSystemPropertyReportModel m1 = new AliyunSystemPropertyReportModel(); m1.RecipeCollection = new string[Json.Data.Recipes.Count];