From 2cea2352bf921bbdb1c21281906daaae199806e0 Mon Sep 17 00:00:00 2001 From: ZhaoGang <15196688790@163.com> Date: Fri, 8 Sep 2023 16:54:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=BA=E8=B0=83=E8=AF=95=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.MorkCL/Control_MorkCL.cs | 88 +++++++++++++++++-- BPASmartClient.MorkCL/GVL_MorkCL.cs | 2 +- .../Model/Control/RobotGet.cs | 2 +- .../Model/Json/ConnectPar.cs | 16 ++++ BPASmartClient.MorkCL/Server/OtherServer.cs | 30 +++++++ BPASmartClient.MorkCL/Server/RobotServer.cs | 32 +++++++ BPASmartClient.MorkCL/View/Debug.xaml | 18 ++-- .../View/ItemStorageView.xaml | 28 +++--- .../View/ManualSetItemStorageView.xaml | 37 ++++++++ .../View/ManualSetItemStorageView.xaml.cs | 29 ++++++ .../ViewModel/DebugViewModel.cs | 35 +++++++- .../ViewModel/ItemStorageViewModel.cs | 24 ++++- .../ManualSetItemStorageViewModel.cs | 13 +++ 13 files changed, 326 insertions(+), 28 deletions(-) create mode 100644 BPASmartClient.MorkCL/View/ManualSetItemStorageView.xaml create mode 100644 BPASmartClient.MorkCL/View/ManualSetItemStorageView.xaml.cs create mode 100644 BPASmartClient.MorkCL/ViewModel/ManualSetItemStorageViewModel.cs diff --git a/BPASmartClient.MorkCL/Control_MorkCL.cs b/BPASmartClient.MorkCL/Control_MorkCL.cs index 5c89551e..877d2369 100644 --- a/BPASmartClient.MorkCL/Control_MorkCL.cs +++ b/BPASmartClient.MorkCL/Control_MorkCL.cs @@ -145,7 +145,8 @@ namespace BPASmartClient.MorkCL #endregion //这里判定主要是针对压力锅。 - if (!TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType)) + //修改为炒锅和机器人不允许下单情况下,就不下单。 + if (!TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType)&&GetFryPanAndRobotIsAuto(morkCL.cds.ElementAt(0).DeviceType)) { if (morkCL.cds.TryDequeue(out ControlData cd)) { @@ -575,9 +576,25 @@ namespace BPASmartClient.MorkCL } break; case EFunc.添加辅料: - MaterialBase mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id); + #region 根据配置文件选择每个炒锅的最大最小辅料位置,暂时没使用。 + //var minloc = -1; + //var maxloc = -1; + //if (et == EDeviceType.炒锅1) + //{ + // minloc = Json.Data.FryPanAccessoriesMin_1; + // maxloc = Json.Data.FryPanAccessoriesMax_1; + //} + //else if (et == EDeviceType.炒锅2) + //{ + // minloc = Json.Data.FryPanAccessoriesMin_2; + // maxloc = Json.Data.FryPanAccessoriesMax_2; + //} + #endregion + + MaterialBase mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p =>/*p.Loc>=minloc && p.Loc<=maxloc&& */p.Id == fm.funcPars.ElementAt(0).Id); if (mb != null) { + robot.IsIdle.Wait(Cts: TaskList[et].Cts); //先复位变量。防止上一次是异常结束,设为True时,不会响应。 device.FryingPanHome = false; @@ -882,7 +899,14 @@ namespace BPASmartClient.MorkCL public override void Stop() { } - + private bool GetFryPanAndRobotIsAuto(EDeviceType fryPan) + { + //目前拿不到机器人的远程状态,只能拿到炒锅的。 + var device = (FryingPanServer)devices[fryPan]; + var robot = (RobotServer)devices[EDeviceType.机器人]; + return device.InitComplete && device.StatusMode && device.EStop && robot.RemoteMode; + + } void ManualActionRegiester() { //主料入库委托。 @@ -908,6 +932,17 @@ namespace BPASmartClient.MorkCL var index = Array.FindIndex(Json.Data.IngredientsStorage, i => i.IsEmploy == false); if (index >= 0) { + if (!MessageNotify.GetInstance.ShowDialog($"请确认库位【{index+1}】上无物品,否则可能会造成碰撞事故!",DialogType.Warning)) + { + + DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}],库位[{index+1}]入库失败,未确认库位无异物。"); + Application.Current.Dispatcher.Invoke(() => + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料{ingredients.Name}入库失败。"); + }); + return; + } + var item = Json.Data.IngredientsStorage[index]; item.MaterialID = ingredients.Id; @@ -926,7 +961,7 @@ namespace BPASmartClient.MorkCL ActionManage.GetInstance.Send("RefreshItemStorage"); - DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}]入库成功。"); + DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}],库位[{index + 1}]入库成功。"); Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "入库成功", $"物料{ingredients.Name}入库成功。"); @@ -961,7 +996,7 @@ namespace BPASmartClient.MorkCL { var robot = (RobotServer)devices[EDeviceType.机器人]; //Thread.Sleep(5000); - robot.WarehousingControl(loc); + robot.WarehousingControl(loc,null); //会卡死。 robot.WarehousingComplete[(Convert.ToInt32(loc) - 1)].Wait(); } @@ -1010,12 +1045,41 @@ namespace BPASmartClient.MorkCL ActionManage.GetInstance.Register(() => { //电子秤去皮 + var weghier = (OtherServer)devices[EDeviceType.外部设备]; + if (weghier.WeigherTare()) + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "去皮成功", $"电子秤除皮操作成功。"); + DeviceProcessLogShow($"电子秤除皮操作成功。"); + } + else + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "去皮失败", $"电子秤除皮操作失败。"); + DeviceProcessLogShow($"电子秤除皮操作失败。"); + } + },"WeighrTare",true); ActionManage.GetInstance.Register(() => { //电子秤置零 + var weghier = (OtherServer)devices[EDeviceType.外部设备]; + if (weghier.WeigherZero()) + { + Application.Current.Dispatcher.Invoke(() => + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "置零成功", $"电子秤置零操作成功。"); + }); + DeviceProcessLogShow($"电子秤置零操作成功。"); + } + else + { + Application.Current.Dispatcher.Invoke(() => + { + NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "置零失败", $"电子秤置零操作失败。"); + }); + DeviceProcessLogShow($"电子秤置零操作失败。"); + } }, "WeighrZero", true); @@ -1059,6 +1123,20 @@ namespace BPASmartClient.MorkCL ActionManage.GetInstance.Register(frypanIsIdle, "GetDeviceIsIdle", true); + ActionManage.GetInstance.Register(() => + { + var robot = (RobotServer)devices[EDeviceType.机器人]; + if (robot.InitVariable()) + { + Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"复位所有由上位机下发至机器人的变量成功。"); }); + DeviceProcessLogShow($"复位所有由上位机下发至机器人的变量成功。"); + } + else + { + Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"复位所有由上位机下发至机器人的变量失败。"); }); + DeviceProcessLogShow($"复位所有由上位机下发至机器人的变量失败。"); + } + }, "InitRobotAllVar", true); } Func frypanIsIdle => (o) => diff --git a/BPASmartClient.MorkCL/GVL_MorkCL.cs b/BPASmartClient.MorkCL/GVL_MorkCL.cs index 8fcb1194..6934d04e 100644 --- a/BPASmartClient.MorkCL/GVL_MorkCL.cs +++ b/BPASmartClient.MorkCL/GVL_MorkCL.cs @@ -359,7 +359,7 @@ namespace BPASmartClient.MorkCL /// /// 机器人远程模式 /// - [VariableMonitor("机器人-机器人远程模式", "LW22")] + [VariableMonitor("机器人-机器人远程模式,为True时,代表可下单", "GM130")] public bool RemoteMode { get; set; } /// diff --git a/BPASmartClient.MorkCL/Model/Control/RobotGet.cs b/BPASmartClient.MorkCL/Model/Control/RobotGet.cs index da3ffeb7..53a7e9f1 100644 --- a/BPASmartClient.MorkCL/Model/Control/RobotGet.cs +++ b/BPASmartClient.MorkCL/Model/Control/RobotGet.cs @@ -42,7 +42,7 @@ namespace BPASmartClient.MorkCL.Model.Control public bool EnableState { get; set; } /// - /// 机器人远程模式 + /// 机器人远程模式,为True时,可下单。 /// public bool RemoteMode { get; set; } diff --git a/BPASmartClient.MorkCL/Model/Json/ConnectPar.cs b/BPASmartClient.MorkCL/Model/Json/ConnectPar.cs index 8be4adee..72354e0b 100644 --- a/BPASmartClient.MorkCL/Model/Json/ConnectPar.cs +++ b/BPASmartClient.MorkCL/Model/Json/ConnectPar.cs @@ -61,5 +61,21 @@ namespace BPASmartClient.MorkCL.Model.Json /// 外设端口号 /// public string PPortName { get; set; } = "COM2"; + /// + /// 炒锅1辅料最小位置。 + /// + public int FryPanAccessoriesMin_1 { get; set; } = 1; + /// + /// 炒锅1辅料最大位置。 + /// + public int FryPanAccessoriesMax_1 { get; set; } = 4; + /// + /// 炒锅2辅料最小位置。 + /// + public int FryPanAccessoriesMin_2 { get; set; } = 5; + /// + /// 炒锅2辅料最大位置。 + /// + public int FryPanAccessoriesMax_2 { get; set; } = 8; } } diff --git a/BPASmartClient.MorkCL/Server/OtherServer.cs b/BPASmartClient.MorkCL/Server/OtherServer.cs index cb3773e4..68eaee47 100644 --- a/BPASmartClient.MorkCL/Server/OtherServer.cs +++ b/BPASmartClient.MorkCL/Server/OtherServer.cs @@ -52,5 +52,35 @@ namespace BPASmartClient.MorkCL.Server { throw new NotImplementedException(); } + /// + /// 除皮 + /// + /// + public bool WeigherTare() + { + if (MyModbus is not null && MyModbus.IsConnected()) + { + ModbusRtu weigher = (ModbusRtu)MyModbus; + weigher.SlaveAddress = 2; + return weigher.Write("LB4", false).IsSuccess; + } + else + return false; + } + /// + /// 置零 + /// + /// + public bool WeigherZero() + { + if (MyModbus is not null && MyModbus.IsConnected()) + { + ModbusRtu weigher = (ModbusRtu)MyModbus; + weigher.SlaveAddress = 2; + return weigher.Write("LB3", false).IsSuccess; + } + else + return false; + } } } diff --git a/BPASmartClient.MorkCL/Server/RobotServer.cs b/BPASmartClient.MorkCL/Server/RobotServer.cs index 1dde5e5a..eb776226 100644 --- a/BPASmartClient.MorkCL/Server/RobotServer.cs +++ b/BPASmartClient.MorkCL/Server/RobotServer.cs @@ -32,17 +32,24 @@ namespace BPASmartClient.MorkCL.Server } }); Thread.Sleep(20); + MyModbus.Read("GM620".ToModbusAdd()).OnSuccess((b)=> { Home = b; }); Thread.Sleep(20); + MyModbus.Read("GM630".ToModbusAdd(), 12).OnSuccess(s => { for (byte i = 0; i < s.Length; i++) WarehousingComplete[i] = s[i]; }); Thread.Sleep(20); + MyModbus.Read("GI5".ToModbusAdd(), 1).OnSuccess(s => { TaskFeedback = (RobotMainTask)s; }); IsIdle = (TaskFeedback == RobotMainTask.无任务 && Home); Thread.Sleep(20); + + MyModbus.Read("GM130".ToModbusAdd(), 1).OnSuccess((b) => { RemoteMode = b; }); + Thread.Sleep(20); + }), $"机器人服务-{IP}", true); }); } @@ -86,5 +93,30 @@ namespace BPASmartClient.MorkCL.Server Thread.Sleep(1000); } } + + public bool InitVariable() + { + if (MyModbus is not null && MyModbus.IsConnected()) + { + try + { + MyModbus.Write("GI0".ToModbusAdd(), 0); + MyModbus.Write("GI1".ToModbusAdd(), 0); + for (int i = 0; i <= 8; i++) + { + MyModbus.Write(("GM" + (500 + i).ToString()).ToModbusAdd(), false); + } + return true; + } + catch (Exception) + { + + return false; + } + + } + else + return false; + } } } diff --git a/BPASmartClient.MorkCL/View/Debug.xaml b/BPASmartClient.MorkCL/View/Debug.xaml index 04a3636f..0ff61f2c 100644 --- a/BPASmartClient.MorkCL/View/Debug.xaml +++ b/BPASmartClient.MorkCL/View/Debug.xaml @@ -55,11 +55,11 @@ Margin="10,0" Command="{Binding InitalDeviceCommand}" Content="初始化设备" /> -