From 694604c4f0ef5c06e146a19ee848b72bd8fefa57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Wed, 21 Jun 2023 17:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E5=BA=93=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmartClient.Business.csproj | 2 +- .../BPASmartClient.CustomResource.csproj | 2 +- BPASmartClient.Device/BaseDevice.cs | 2 +- .../BPASmartClient.DosingSystemSingle.csproj | 2 +- .../BPASmartClient.FoodStationTest.csproj | 2 +- .../BPASmartClient.JXJFoodBigStation.csproj | 4 +- .../BPASmartClient.JakaRobot.csproj | 2 +- .../BPASmartClient.Modbus.csproj | 2 +- .../BPASmartClient.Model.csproj | 2 +- BPASmartClient.Nfc/BPASmartClient.Nfc.csproj | 2 +- .../BPASmartClient.S7Net.csproj | 2 +- .../BPASmartClient.ScreenLib.csproj | 2 +- .../BPASmartClient.SerialPort.csproj | 2 +- .../BPASmartClient.SmallBatchingSystem.csproj | 2 +- BPASmartClient.Tourism/AddConvert.cs | 29 ----- BPASmartClient.Tourism/Control_MorkCL.cs | 120 +++++++++++++++++- BPASmartClient.Tourism/ExtensionMethod.cs | 78 ++++++++++++ BPASmartClient.Tourism/GVL_MorkCL.cs | 2 + BPASmartClient.Tourism/GlobalUsing.cs | 3 +- .../Model/Control/FryingPanGet.cs | 2 +- .../Model/Control/FryingPanSet.cs | 81 ++++++------ .../Model/Control/OtherDeviceGet.cs | 21 +++ .../OtherDeviceSet.cs} | 7 +- .../Model/Control/PressureCookerGet.cs | 12 ++ .../Model/Control/PressureCookerSet.cs | 12 ++ .../Model/Control/RobotGet.cs | 26 +++- .../Model/Control/RobotSet.cs | 113 ++++++++++++++--- BPASmartClient.Tourism/Model/ControlData.cs | 11 +- .../{ControlDeviceType.cs => EDeviceType.cs} | 13 +- BPASmartClient.Tourism/Model/Func/FuncPar.cs | 5 + BPASmartClient.Tourism/Model/Func/InitData.cs | 2 +- BPASmartClient.Tourism/Model/NotifyTopic.cs | 5 + BPASmartClient.Tourism/Model/Result.cs | 14 ++ .../Server/{ISqlLIte.cs => ISqlite.cs} | 2 +- BPASmartClient.Tourism/Server/OtherServer.cs | 22 +++- .../Server/PressureCookerServer.cs | 15 ++- BPASmartClient.Tourism/Server/RobotServer.cs | 48 +++++++ BPASmartClient.Tourism/Server/SqliteHelper.cs | 2 +- BPASmartClient.Tourism/Server/TaskServer.cs | 29 +++++ .../BPASmartClient.Update.csproj | 2 +- .../BPASmartClient.DosingSystem.csproj | 2 +- WpfTest/WpfTest.csproj | 2 +- 42 files changed, 585 insertions(+), 125 deletions(-) delete mode 100644 BPASmartClient.Tourism/AddConvert.cs create mode 100644 BPASmartClient.Tourism/ExtensionMethod.cs create mode 100644 BPASmartClient.Tourism/Model/Control/OtherDeviceGet.cs rename BPASmartClient.Tourism/Model/{DeviceType.cs => Control/OtherDeviceSet.cs} (53%) create mode 100644 BPASmartClient.Tourism/Model/Control/PressureCookerGet.cs create mode 100644 BPASmartClient.Tourism/Model/Control/PressureCookerSet.cs rename BPASmartClient.Tourism/Model/{ControlDeviceType.cs => EDeviceType.cs} (50%) create mode 100644 BPASmartClient.Tourism/Model/Result.cs rename BPASmartClient.Tourism/Server/{ISqlLIte.cs => ISqlite.cs} (95%) create mode 100644 BPASmartClient.Tourism/Server/TaskServer.cs diff --git a/BPASmartClient.Business/BPASmartClient.Business.csproj b/BPASmartClient.Business/BPASmartClient.Business.csproj index bc5eae2f..03fc5407 100644 --- a/BPASmartClient.Business/BPASmartClient.Business.csproj +++ b/BPASmartClient.Business/BPASmartClient.Business.csproj @@ -8,7 +8,7 @@ - + diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index 767b8ea8..a89335fd 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -463,7 +463,7 @@ - + diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index 072e3f50..c19bcca2 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/BPASmartClient.Device/BaseDevice.cs @@ -162,7 +162,7 @@ namespace BPASmartClient.Device /// public void DeviceProcessLogShow(string info) { - Log.Insert(0, new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = "流程", Text = info }); + Log.Insert(0, new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), Type = "流程", Text = info }); MessageLog.GetInstance.DeviceProcessLogShow(DeviceId.ToString(), info); if (Log.Count > 100) { Log.RemoveAt(Log.Count - 1); } } diff --git a/BPASmartClient.DosingSystemSingle/BPASmartClient.DosingSystemSingle.csproj b/BPASmartClient.DosingSystemSingle/BPASmartClient.DosingSystemSingle.csproj index 465ab84c..4ff09e8b 100644 --- a/BPASmartClient.DosingSystemSingle/BPASmartClient.DosingSystemSingle.csproj +++ b/BPASmartClient.DosingSystemSingle/BPASmartClient.DosingSystemSingle.csproj @@ -16,7 +16,7 @@ - + diff --git a/BPASmartClient.FoodStationTest/BPASmartClient.FoodStationTest.csproj b/BPASmartClient.FoodStationTest/BPASmartClient.FoodStationTest.csproj index 88a9f643..960cb6bf 100644 --- a/BPASmartClient.FoodStationTest/BPASmartClient.FoodStationTest.csproj +++ b/BPASmartClient.FoodStationTest/BPASmartClient.FoodStationTest.csproj @@ -16,7 +16,7 @@ - + diff --git a/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj b/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj index ac53015c..7944d193 100644 --- a/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj +++ b/BPASmartClient.JXJFoodBigStation/BPASmartClient.JXJFoodBigStation.csproj @@ -17,8 +17,8 @@ - - + + diff --git a/BPASmartClient.JakaRobot/BPASmartClient.JakaRobot.csproj b/BPASmartClient.JakaRobot/BPASmartClient.JakaRobot.csproj index defab860..896bc5c4 100644 --- a/BPASmartClient.JakaRobot/BPASmartClient.JakaRobot.csproj +++ b/BPASmartClient.JakaRobot/BPASmartClient.JakaRobot.csproj @@ -7,7 +7,7 @@ - + diff --git a/BPASmartClient.Modbus/BPASmartClient.Modbus.csproj b/BPASmartClient.Modbus/BPASmartClient.Modbus.csproj index da719a10..4f766387 100644 --- a/BPASmartClient.Modbus/BPASmartClient.Modbus.csproj +++ b/BPASmartClient.Modbus/BPASmartClient.Modbus.csproj @@ -5,7 +5,7 @@ - + diff --git a/BPASmartClient.Model/BPASmartClient.Model.csproj b/BPASmartClient.Model/BPASmartClient.Model.csproj index f7881186..98b3af38 100644 --- a/BPASmartClient.Model/BPASmartClient.Model.csproj +++ b/BPASmartClient.Model/BPASmartClient.Model.csproj @@ -16,7 +16,7 @@ - + diff --git a/BPASmartClient.Nfc/BPASmartClient.Nfc.csproj b/BPASmartClient.Nfc/BPASmartClient.Nfc.csproj index ba33798a..0941b50c 100644 --- a/BPASmartClient.Nfc/BPASmartClient.Nfc.csproj +++ b/BPASmartClient.Nfc/BPASmartClient.Nfc.csproj @@ -21,7 +21,7 @@ - + diff --git a/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj b/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj index 3c694624..a4df70c4 100644 --- a/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj +++ b/BPASmartClient.S7Net/BPASmartClient.S7Net.csproj @@ -7,7 +7,7 @@ - + diff --git a/BPASmartClient.ScreenLib/BPASmartClient.ScreenLib.csproj b/BPASmartClient.ScreenLib/BPASmartClient.ScreenLib.csproj index 4531e799..9be6f09f 100644 --- a/BPASmartClient.ScreenLib/BPASmartClient.ScreenLib.csproj +++ b/BPASmartClient.ScreenLib/BPASmartClient.ScreenLib.csproj @@ -24,7 +24,7 @@ - + diff --git a/BPASmartClient.SerialPort/BPASmartClient.SerialPort.csproj b/BPASmartClient.SerialPort/BPASmartClient.SerialPort.csproj index 2c99f76d..d54d2e46 100644 --- a/BPASmartClient.SerialPort/BPASmartClient.SerialPort.csproj +++ b/BPASmartClient.SerialPort/BPASmartClient.SerialPort.csproj @@ -5,7 +5,7 @@ - + diff --git a/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj b/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj index 1cd718e1..ea3327f3 100644 --- a/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj +++ b/BPASmartClient.SmallBatchingSystem/BPASmartClient.SmallBatchingSystem.csproj @@ -21,7 +21,7 @@ - + diff --git a/BPASmartClient.Tourism/AddConvert.cs b/BPASmartClient.Tourism/AddConvert.cs deleted file mode 100644 index 6a1f5a29..00000000 --- a/BPASmartClient.Tourism/AddConvert.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.MorkCL -{ - /// - /// 地址转换类 - /// - internal static class AddConvert - { - public static string ToModbusAdd(this string add) - { - return ""; - } - - /// - /// 煮面机器人地址转换 - /// - /// - /// - public static string AddressConvert(string address) - { - return (Convert.ToInt32(address.Substring(1, address.Length - 1)) + 4096).ToString(); - } - } -} diff --git a/BPASmartClient.Tourism/Control_MorkCL.cs b/BPASmartClient.Tourism/Control_MorkCL.cs index 7832feac..cbce75a0 100644 --- a/BPASmartClient.Tourism/Control_MorkCL.cs +++ b/BPASmartClient.Tourism/Control_MorkCL.cs @@ -1,5 +1,7 @@ using BPA.Message.Enum; using BPASmartClient.Device; +using BPASmartClient.MorkCL.Server; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -14,20 +16,134 @@ namespace BPASmartClient.MorkCL GVL_MorkCL morkCL = new GVL_MorkCL(); Alarm alarm = new Alarm(); + /// + /// 设备信息集合 + /// + ConcurrentDictionary devices { get; set; } = new(); + + /// + /// 任务集合 + /// + ConcurrentDictionary TaskList { get; set; } = new(); public override void DoMain() { MonitorViewModel.DeviceId = DeviceId; + + //注册本地配方接收 + ActionManage.GetInstance.Register(new Action(o => + { + if (o != null && o is ControlData cd) morkCL.cds.Enqueue(cd); + }), NotifyTopic.FormulaDistribution); + + //初始化通讯对象 + devices.TryAdd(EDeviceType.炒锅1, new FryingPanServer()); + devices.TryAdd(EDeviceType.炒锅2, new FryingPanServer()); + devices.TryAdd(EDeviceType.机器人, new RobotServer()); + devices.TryAdd(EDeviceType.压力锅, new PressureCookerServer()); + devices.TryAdd(EDeviceType.外部设备, new OtherServer()); + + devices[EDeviceType.炒锅1].Init(ConnectPar.FryingPanIP1); + devices[EDeviceType.炒锅2].Init(ConnectPar.FryingPanIP2); + devices[EDeviceType.机器人].Init(ConnectPar.RobotIP); + devices[EDeviceType.压力锅].Init(ConnectPar.PressureCookerIP); + devices[EDeviceType.外部设备].Init(ConnectPar.PPortName); } public override void MainTask() { - //throw new NotImplementedException(); + if (morkCL.cds.Count > 0 && !TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType)) + { + if (morkCL.cds.TryDequeue(out ControlData cd)) + { + TaskList.TryAdd(cd.DeviceType, new TaskServer()); + TaskList[cd.DeviceType].TaskName = $"{cd.DeviceType.ToString()}-{cd.Name}"; + TaskList[cd.DeviceType].RunTask = new Task(new Action(() => { FryingPanControl(cd.DeviceType, cd); })); + TaskList[cd.DeviceType].RunTask.Start(); + } + } + //检查到有任务完成后将对已完成的任务进行清理 + var res = TaskList.FirstOrDefault(p => p.Value.IsComplete).Key; + if (TaskList.ContainsKey(res)) TaskList.TryRemove(res, out _); + } + + private void FryingPanControl(EDeviceType et, ControlData cd) + { + DeviceProcessLogShow($"开始执行-{cd.Name} 任务"); + for (int i = 0; i < cd.ControlFuncs.Count; i++) + { + if (TaskList.ContainsKey(et) && TaskList[et].Cts.IsCancellationRequested) return; + var device = (FryingPanServer)devices[et]; + var robot = (RobotServer)devices[EDeviceType.机器人]; + var keyValues = cd.ControlFuncs.ElementAt(i); + int index = (ushort)et - 1; + DeviceProcessLogShow($"{cd.Name}-任务执行-{keyValues.Key.ToString()}-步骤"); + switch (keyValues.Key) + { + case EFunc.搅拌启动: + device.MixingFrequencySet(keyValues.Value[0].ParValue); + device.StirStartOrStop = true; + break; + case EFunc.搅拌停止: + device.StirStartOrStop = false; + break; + case EFunc.加热启动: + device.HeatingGearSet(keyValues.Value[0].ParValue); + device.HeatStartOrStop = true; + break; + case EFunc.加热停止: + device.HeatStartOrStop = false; + break; + case EFunc.添加调料: + var Seasoning = SqliteHelper.GetInstance.GetSeasoning().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); + if (Seasoning != null) + { + device.CuttingControl(Seasoning.Loc.ToString(), keyValues.Value[1].ParValue); + } + break; + case EFunc.添加主料: + case EFunc.添加辅料: + MaterialBase mb = new MaterialBase(); + if (keyValues.Key == EFunc.添加辅料) + mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); + else mb = SqliteHelper.GetInstance.GetIngredients().FirstOrDefault(p => p.Id == keyValues.Value[0].Id); + robot.RobotTaskControl(mb.Loc.ToString(), et); + device.FeedingLocFB.Wait(Cts: TaskList[et].Cts);//等待炒锅到投料位置 + robot.MaterialPouringRequest[index].Wait(Cts: TaskList[et].Cts); //等待机器人到投料位置 + robot.AllowPourVegetables(et);//允许机器人开始投料 + robot.MaterialPouringComplete[index].Wait(Cts: TaskList[et].Cts); //等待机器人投料完成 + break; + case EFunc.炒锅回原点位: + device.FryingPanHome = true; + break; + case EFunc.出餐启动: + robot.RobotTaskControl("1", et);//取空盆 + robot.DiningOutRequest[index].Wait(Cts: TaskList[et].Cts);//等待机器人到出菜位置 + device.DiningOutStart = true; + break; + case EFunc.炒锅清洗: + device.FryingPanClear = true; + break; + case EFunc.炒锅回投料位置: + device.FryingPanFeedingLoc = true; + break; + case EFunc.去指定炒制位: + device.SetStirFryingLoc(keyValues.Value[0].ParValue); + break; + case EFunc.炒制: + if (int.TryParse(keyValues.Value[0].ParValue, out int time)) + Task.Delay(time * 1000).Wait(TaskList[et].Cts.Token); + break; + default: + break; + } + + } } public override void ReadData() { - //throw new NotImplementedException(); + } public override void ResetProgram() diff --git a/BPASmartClient.Tourism/ExtensionMethod.cs b/BPASmartClient.Tourism/ExtensionMethod.cs new file mode 100644 index 00000000..ee41ff9d --- /dev/null +++ b/BPASmartClient.Tourism/ExtensionMethod.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL +{ + /// + /// 地址转换类 + /// + internal static class ExtensionMethod + { + /// + /// Modbus 地址转换 + /// + /// + /// + public static string ToModbusAdd(this string address) + { + if (address == null) return ""; + if (address.Length > 0) + { + address = address.Trim(); + if (address.ToUpper().Contains("GM") && address.Length >= 3) + { + var res = address.Remove(0, 2); + if (res != null && res.Length > 0) return (int.Parse(res) + 4096).ToString(); + } + else if (address.ToUpper().Contains("M") && address.Length >= 4) + { + var res = address.Substring(1).Split('.'); + if (res != null && res.Length == 2) + { + if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress)) + { + if (ExitAddress >= 0 && ExitAddress <= 7) + { + return ((firstAddress * 8) + 320 + ExitAddress).ToString(); + } + } + } + } + else if (address.ToUpper().Contains("GI") && address.Length >= 3) + { + var res = address.Remove(0, 2); + if (res != null && res.Length > 0) return res; + } + else if (address.ToUpper().Contains("LB") && address.Length >= 3) + { + var res = address.Substring(2); + if (res != null && res.Length > 0) + { + if (int.TryParse(res, out int firstAddress)) return firstAddress.ToString(); + } + } + else if ((address.ToUpper().Contains("VW") || address.ToUpper().Contains("VD")) && address.Length >= 3) + { + var res = address.Substring(2); + if (res != null && int.TryParse(res, out int tempAddress)) + { + return ((tempAddress / 2) + 100).ToString(); + } + } + else if (address.ToUpper().Contains("LW") && address.Length >= 3) + { + var res = address.Substring(2); + if (res != null && int.TryParse(res, out int LwAddress)) + { + return LwAddress.ToString(); + } + } + } + return ""; + } + } +} diff --git a/BPASmartClient.Tourism/GVL_MorkCL.cs b/BPASmartClient.Tourism/GVL_MorkCL.cs index dea67c26..5951a23c 100644 --- a/BPASmartClient.Tourism/GVL_MorkCL.cs +++ b/BPASmartClient.Tourism/GVL_MorkCL.cs @@ -8,6 +8,8 @@ namespace BPASmartClient.MorkCL { public class GVL_MorkCL : IStatus { + public ConcurrentQueue cds { get; set; } = new ConcurrentQueue(); + #region 炒锅1 #endregion diff --git a/BPASmartClient.Tourism/GlobalUsing.cs b/BPASmartClient.Tourism/GlobalUsing.cs index 9431fac0..8a8e6609 100644 --- a/BPASmartClient.Tourism/GlobalUsing.cs +++ b/BPASmartClient.Tourism/GlobalUsing.cs @@ -15,4 +15,5 @@ global using System.Collections.ObjectModel; global using BPASmartClient.Device; global using BPASmartClient.MorkCL.Model.Func; global using System.Threading; -global using BPA.Communication.Base; \ No newline at end of file +global using BPA.Communication.Base; +global using BPASmartClient.MorkCL.Model.Control; \ No newline at end of file diff --git a/BPASmartClient.Tourism/Model/Control/FryingPanGet.cs b/BPASmartClient.Tourism/Model/Control/FryingPanGet.cs index 2bbdd18a..3cc9e8b9 100644 --- a/BPASmartClient.Tourism/Model/Control/FryingPanGet.cs +++ b/BPASmartClient.Tourism/Model/Control/FryingPanGet.cs @@ -36,7 +36,7 @@ namespace BPASmartClient.MorkCL.Model.Control /// /// 炒锅在投料位置反馈 /// - public bool FeedingLocFB { get; set; } + public bool FeedingLocFB; /// /// 炒锅在洗锅位置反馈 diff --git a/BPASmartClient.Tourism/Model/Control/FryingPanSet.cs b/BPASmartClient.Tourism/Model/Control/FryingPanSet.cs index 5808f311..bfdd373f 100644 --- a/BPASmartClient.Tourism/Model/Control/FryingPanSet.cs +++ b/BPASmartClient.Tourism/Model/Control/FryingPanSet.cs @@ -22,56 +22,60 @@ namespace BPASmartClient.MorkCL.Model.Control /// /// 通道下料启动控制(1-3) /// - /// 通道编号,1-3 - /// 通道需求值 - public void CuttingControl(int ChannelNum, ushort value) + /// 通道编号,1-3 + /// 通道需求值 + public void CuttingControl(string Num, string demandValue) { - if (ChannelNum >= 1 && ChannelNum <= 3) - { - byte[] VWOffset = new byte[3] { 6, 8, 10 }; - byte[] LBOffset = new byte[3] { 6, 7, 0 }; - MyModbus.Write($"VW10{VWOffset[ChannelNum - 1]}".ToModbusAdd(), value); - MyModbus.Write($"LB{LBOffset[ChannelNum - 1]}".ToModbusAdd(), true); - } + if (ushort.TryParse(Num, out ushort ChannelNum) && ushort.TryParse(demandValue, out ushort value)) + if (ChannelNum >= 1 && ChannelNum <= 3) + { + byte[] VWOffset = new byte[3] { 6, 8, 10 }; + byte[] LBOffset = new byte[3] { 6, 7, 0 }; + MyModbus.Write($"VW10{VWOffset[ChannelNum - 1]}".ToModbusAdd(), value); + MyModbus.Write($"LB{LBOffset[ChannelNum - 1]}".ToModbusAdd(), true); + } } /// /// 加热档位设定 /// - /// 档位,1-8挡 - public void HeatingGearSet(ushort Gear) + /// 档位,1-8挡 + public void HeatingGearSet(string value) { - if (Gear >= 1 && Gear <= 8) - { - MyModbus.Write($"VW100".ToModbusAdd(), Gear); - MyModbus.Write($"LB9".ToModbusAdd(), true); - } + if (ushort.TryParse(value, out ushort Gear)) + if (Gear >= 1 && Gear <= 8) + { + MyModbus.Write($"VW100".ToModbusAdd(), Gear); + MyModbus.Write($"LB9".ToModbusAdd(), true); + } } /// /// 搅拌频率设定 /// - /// 频率,0-50HZ - public void MixingFrequencySet(ushort Frequency) + /// 频率,0-50HZ + public void MixingFrequencySet(string value) { - if (Frequency >= 0 && Frequency <= 50) - { - MyModbus.Write($"VW102".ToModbusAdd(), Frequency); - MyModbus.Write($"LB10".ToModbusAdd(), true); - } + if (ushort.TryParse(value, out ushort Frequency)) + if (Frequency >= 0 && Frequency <= 50) + { + MyModbus.Write($"VW102".ToModbusAdd(), Frequency); + MyModbus.Write($"LB10".ToModbusAdd(), true); + } } /// /// 翻转频率设定 /// - /// 频率,0-50HZ - public void OverturnFrequencySet(ushort Frequency) + /// 频率,0-50HZ + public void OverturnFrequencySet(string value) { - if (Frequency >= 0 && Frequency <= 50) - { - MyModbus.Write($"VW104".ToModbusAdd(), Frequency); - MyModbus.Write($"LB11".ToModbusAdd(), true); - } + if (ushort.TryParse(value, out ushort Frequency)) + if (Frequency >= 0 && Frequency <= 50) + { + MyModbus.Write($"VW104".ToModbusAdd(), Frequency); + MyModbus.Write($"LB11".ToModbusAdd(), true); + } } /// @@ -90,20 +94,21 @@ namespace BPASmartClient.MorkCL.Model.Control public bool FryingPanClear { get { return default; } set { MyModbus.Write("LB14".ToModbusAdd(), value); } } /// - /// 炒锅回投料位置 + /// 炒锅到投料位置 /// public bool FryingPanFeedingLoc { get { return default; } set { MyModbus.Write("LB15".ToModbusAdd(), value); } } /// /// 去炒制位控制 /// - /// 炒锅位置,1-4 - public void SetStirFryingLoc(ushort loc) + /// 炒锅位置,1-4 + public void SetStirFryingLoc(string value) { - if (loc >= 1 && loc <= 4) - { - MyModbus.Write($"LB{loc + 15}".ToModbusAdd(), true); - } + if (ushort.TryParse(value, out ushort loc)) + if (loc >= 1 && loc <= 4) + { + MyModbus.Write($"LB{loc + 15}".ToModbusAdd(), true); + } } } diff --git a/BPASmartClient.Tourism/Model/Control/OtherDeviceGet.cs b/BPASmartClient.Tourism/Model/Control/OtherDeviceGet.cs new file mode 100644 index 00000000..6080d83b --- /dev/null +++ b/BPASmartClient.Tourism/Model/Control/OtherDeviceGet.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model.Control +{ + internal class OtherDeviceGet : ModbusBase + { + /// + /// 电子秤当前重量 + /// + public float CurrentWeight { get; set; } + + /// + /// 空箱子检测 + /// + public bool[] BoxDetection { get; set; } = new bool[4]; + } +} diff --git a/BPASmartClient.Tourism/Model/DeviceType.cs b/BPASmartClient.Tourism/Model/Control/OtherDeviceSet.cs similarity index 53% rename from BPASmartClient.Tourism/Model/DeviceType.cs rename to BPASmartClient.Tourism/Model/Control/OtherDeviceSet.cs index e58d400c..16e91893 100644 --- a/BPASmartClient.Tourism/Model/DeviceType.cs +++ b/BPASmartClient.Tourism/Model/Control/OtherDeviceSet.cs @@ -4,12 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.MorkCL.Model +namespace BPASmartClient.MorkCL.Model.Control { - internal enum DeviceType + internal class OtherDeviceSet : OtherDeviceGet { - 炒锅1, - 炒锅2, - 压力锅 } } diff --git a/BPASmartClient.Tourism/Model/Control/PressureCookerGet.cs b/BPASmartClient.Tourism/Model/Control/PressureCookerGet.cs new file mode 100644 index 00000000..df79d4e4 --- /dev/null +++ b/BPASmartClient.Tourism/Model/Control/PressureCookerGet.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model.Control +{ + internal class PressureCookerGet : ModbusBase + { + } +} diff --git a/BPASmartClient.Tourism/Model/Control/PressureCookerSet.cs b/BPASmartClient.Tourism/Model/Control/PressureCookerSet.cs new file mode 100644 index 00000000..e7b95ed8 --- /dev/null +++ b/BPASmartClient.Tourism/Model/Control/PressureCookerSet.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Model.Control +{ + internal class PressureCookerSet : PressureCookerGet + { + } +} diff --git a/BPASmartClient.Tourism/Model/Control/RobotGet.cs b/BPASmartClient.Tourism/Model/Control/RobotGet.cs index 61479fa2..d60184d1 100644 --- a/BPASmartClient.Tourism/Model/Control/RobotGet.cs +++ b/BPASmartClient.Tourism/Model/Control/RobotGet.cs @@ -14,12 +14,12 @@ namespace BPASmartClient.MorkCL.Model.Control /// /// 倒料请求 /// - public bool[] MaterialPouringRequest { get; set; } = new bool[3]; + public bool[] MaterialPouringRequest = new bool[3]; /// /// 倒料完成 /// - public bool[] MaterialPouringComplete { get; set; } = new bool[3]; + public bool[] MaterialPouringComplete = new bool[3]; /// /// 出餐请求,机器人到位请求炒锅出餐 @@ -29,7 +29,27 @@ namespace BPASmartClient.MorkCL.Model.Control /// /// 入库完成 /// - public bool[] WarehousingComplete { get; set; } = new bool[3]; + public bool[] WarehousingComplete { get; set; } = new bool[12]; + + /// + /// 机器人原点状态 + /// + public bool Home { get; set; } + + /// + /// 机器人使能状态 + /// + public bool EnableState { get; set; } + + /// + /// 机器人远程模式 + /// + public bool RemoteMode { get; set; } + + /// + /// 机器人程序运行中 + /// + public bool ProgramRuning { get; set; } /// /// 机器人任务反馈 diff --git a/BPASmartClient.Tourism/Model/Control/RobotSet.cs b/BPASmartClient.Tourism/Model/Control/RobotSet.cs index 2b5d1e00..cdc9d907 100644 --- a/BPASmartClient.Tourism/Model/Control/RobotSet.cs +++ b/BPASmartClient.Tourism/Model/Control/RobotSet.cs @@ -11,48 +11,129 @@ namespace BPASmartClient.MorkCL.Model.Control /// /// 机器人任务控制 /// - /// - /// - public void RobotTaskControl(ushort mainTask, ushort subTask) + /// + /// + public void RobotTaskControl(string MainTask, EDeviceType SubTask) { - MyModbus.Write("", mainTask); - MyModbus.Write("", subTask); + if (ushort.TryParse(MainTask, out ushort mainTask)) + if (mainTask >= 0 && mainTask <= 24) + { + MyModbus.Write("GI1".ToModbusAdd(), (ushort)SubTask); + MyModbus.Write("GI0".ToModbusAdd(), mainTask); + } } /// /// 入库控制 /// - /// - public void WarehousingControl(ushort loc) + /// + public void WarehousingControl(string Loc) { + if (ushort.TryParse(Loc, out ushort loc)) + if (loc >= 1 && loc <= 12) MyModbus.Write("GI0".ToModbusAdd(), (ushort)(loc + 29)); + } + /// + /// 机器人到位允许倒菜到炒锅 + /// + /// 炒锅类型 + public void AllowPourVegetables(EDeviceType num) + { + switch (num) + { + case EDeviceType.炒锅1: + MyModbus.Write("GM500".ToModbusAdd(), true); + break; + case EDeviceType.炒锅2: + MyModbus.Write("GM501".ToModbusAdd(), true); + break; + case EDeviceType.压力锅: + MyModbus.Write("GM502".ToModbusAdd(), true); + break; + default: + break; + } } /// - /// 运行倒菜 + /// 出餐减速到位 /// - /// 炒锅编号 - public void AllowPourVegetables(ushort num) + /// 炒锅类型 + public void ModerateInPlace(EDeviceType num) { + switch (num) + { + case EDeviceType.炒锅1: + MyModbus.Write("GM503".ToModbusAdd(), true); + break; + case EDeviceType.炒锅2: + MyModbus.Write("GM505".ToModbusAdd(), true); + break; + case EDeviceType.压力锅: + MyModbus.Write("GM507".ToModbusAdd(), true); + break; + default: + break; + } + } + /// + /// 出餐倒菜完成 + /// + /// 炒锅类型 + public void DiningOutComplete(EDeviceType num) + { + switch (num) + { + case EDeviceType.炒锅1: + MyModbus.Write("GM504".ToModbusAdd(), true); + break; + case EDeviceType.炒锅2: + MyModbus.Write("GM506".ToModbusAdd(), true); + break; + case EDeviceType.压力锅: + MyModbus.Write("GM508".ToModbusAdd(), true); + break; + default: + break; + } } /// - /// 出餐减速到位 + /// 设置远程启动(暂停后也可以启动) M702 /// - /// 炒锅编号 - public void ModerateInPlace(ushort num) + public bool RobotStart { + get { return MyModbus.Read("GM702".ToModbusAdd()).Content; } + set { MyModbus.Write("GM702".ToModbusAdd(), value); } + } + /// + /// 设置远程暂停 M703 + /// + public bool RobotSuspend + { + get { return MyModbus.Read("GM703".ToModbusAdd()).Content; } + set { MyModbus.Write("GM703".ToModbusAdd(), value); } } /// - /// 出餐倒菜完成 + /// 设置使能 M700 /// - /// 炒锅编号 - public void DiningOutComplete(ushort num) + public bool RobotEnable { + get { return MyModbus.Read("GM700".ToModbusAdd()).Content; } + set { MyModbus.Write("GM700".ToModbusAdd(), value); } + } + /// + /// 机器人复位 + /// + public bool RobotReset + { + get { return MyModbus.Read("GM701".ToModbusAdd()).Content; } + set { MyModbus.Write("GM701".ToModbusAdd(), value); } } + } } diff --git a/BPASmartClient.Tourism/Model/ControlData.cs b/BPASmartClient.Tourism/Model/ControlData.cs index 65f86f64..823be628 100644 --- a/BPASmartClient.Tourism/Model/ControlData.cs +++ b/BPASmartClient.Tourism/Model/ControlData.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.RightsManagement; using System.Text; using System.Threading.Tasks; using BPASmartClient.MorkCL.Model.DataInfo; @@ -8,8 +9,16 @@ using BPASmartClient.MorkCL.Model.Func; namespace BPASmartClient.MorkCL.Model { - internal class ControlData : RawMaterial + public class ControlData : RawMaterial { + /// + /// 选择设备类型 + /// + public EDeviceType DeviceType { get; set; } + + /// + /// 功能配方 + /// public ConcurrentDictionary> ControlFuncs { get; set; } = new ConcurrentDictionary>(); } } diff --git a/BPASmartClient.Tourism/Model/ControlDeviceType.cs b/BPASmartClient.Tourism/Model/EDeviceType.cs similarity index 50% rename from BPASmartClient.Tourism/Model/ControlDeviceType.cs rename to BPASmartClient.Tourism/Model/EDeviceType.cs index a77fb2c9..648eff41 100644 --- a/BPASmartClient.Tourism/Model/ControlDeviceType.cs +++ b/BPASmartClient.Tourism/Model/EDeviceType.cs @@ -6,12 +6,13 @@ using System.Threading.Tasks; namespace BPASmartClient.MorkCL.Model { - internal enum ControlDeviceType + public enum EDeviceType : ushort { - 炒锅1, - 炒锅2, - 压力锅, - 机器人, - 其它 + 无 = 0, + 炒锅1 = 1, + 炒锅2 = 2, + 压力锅 = 3, + 机器人 = 4, + 外部设备 = 5, } } diff --git a/BPASmartClient.Tourism/Model/Func/FuncPar.cs b/BPASmartClient.Tourism/Model/Func/FuncPar.cs index 7886a43d..148e1053 100644 --- a/BPASmartClient.Tourism/Model/Func/FuncPar.cs +++ b/BPASmartClient.Tourism/Model/Func/FuncPar.cs @@ -11,6 +11,11 @@ namespace BPASmartClient.MorkCL.Model.Func /// public class FuncPar { + /// + /// 物料ID + /// + public string Id { get; set; } + /// /// 参数名 /// diff --git a/BPASmartClient.Tourism/Model/Func/InitData.cs b/BPASmartClient.Tourism/Model/Func/InitData.cs index 57d23e5b..19880abd 100644 --- a/BPASmartClient.Tourism/Model/Func/InitData.cs +++ b/BPASmartClient.Tourism/Model/Func/InitData.cs @@ -31,7 +31,7 @@ namespace BPASmartClient.MorkCL.Model.Func { EFunc.出餐启动,new FuncPar[0] }, { EFunc.炒锅清洗,new FuncPar[0] }, { EFunc.炒锅回投料位置,new FuncPar[0] }, - { EFunc.去指定炒制位,new FuncPar[] { new FuncPar() { ParName="设置炒制位", ParDescribe="请输入 1--3 选择一个合适的炒制位置"} } }, + { EFunc.去指定炒制位,new FuncPar[] { new FuncPar() { ParName="设置炒制位", ParDescribe="请输入 1--4 选择一个合适的炒制位置"} } }, { EFunc.炒制,new FuncPar[] { new FuncPar() { ParName="设置炒制时间",ParUnit="秒", ParDescribe="请设置一个合适的炒制时间"} } }, }; } diff --git a/BPASmartClient.Tourism/Model/NotifyTopic.cs b/BPASmartClient.Tourism/Model/NotifyTopic.cs index e5a1e56b..997182e1 100644 --- a/BPASmartClient.Tourism/Model/NotifyTopic.cs +++ b/BPASmartClient.Tourism/Model/NotifyTopic.cs @@ -17,5 +17,10 @@ namespace BPASmartClient.MorkCL.Model /// 机器人初始化 /// public static string RobotInit => $"{Header}RobotInit"; + + /// + /// 本地配方下发通知 + /// + public static string FormulaDistribution => $"{Header}FormulaDistribution"; } } diff --git a/BPASmartClient.Tourism/Model/Result.cs b/BPASmartClient.Tourism/Model/Result.cs new file mode 100644 index 00000000..c2f25b7f --- /dev/null +++ b/BPASmartClient.Tourism/Model/Result.cs @@ -0,0 +1,14 @@ +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; + +//namespace BPASmartClient.MorkCL.Model +//{ +// public class Result +// { +// public bool IsSuccess { get; set; } +// public string Message { get; set; } +// } +//} diff --git a/BPASmartClient.Tourism/Server/ISqlLIte.cs b/BPASmartClient.Tourism/Server/ISqlite.cs similarity index 95% rename from BPASmartClient.Tourism/Server/ISqlLIte.cs rename to BPASmartClient.Tourism/Server/ISqlite.cs index 0aba62c9..ed6148c6 100644 --- a/BPASmartClient.Tourism/Server/ISqlLIte.cs +++ b/BPASmartClient.Tourism/Server/ISqlite.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BPASmartClient.MorkCL.Server { - internal interface ISqlLIte : IServer + internal interface ISqlite : IServer { //主料 bool AddIngredients(IngredientsTB mb); diff --git a/BPASmartClient.Tourism/Server/OtherServer.cs b/BPASmartClient.Tourism/Server/OtherServer.cs index f4e1963a..12b41d12 100644 --- a/BPASmartClient.Tourism/Server/OtherServer.cs +++ b/BPASmartClient.Tourism/Server/OtherServer.cs @@ -3,13 +3,33 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Controls; namespace BPASmartClient.MorkCL.Server { /// /// 其它服务类 /// - internal class OtherServer + internal class OtherServer : OtherDeviceSet, IModbus { + public void Init(string IP = "", int Port = 502, string PortName = "") + { + MyModbus = new ModbusRtu(); + MyModbus.Connected = () => + { + TaskManage.GetInstance.StartLong(new Action(() => + { + var box = MyModbus.Read("LB100".ToModbusAdd(), 4); + if (box.IsSuccess) + { + for (byte i = 0; i < box.Content.Length; i++) BoxDetection[i] = box.Content[i]; + } + var weight = MyModbus.Read("LW20".ToModbusAdd()); + if (weight.IsSuccess) CurrentWeight = weight.Content; + Thread.Sleep(10); + }), $"其它外部设备-{PortName}", true); + }; + MyModbus.Connect(new ConfigurationOptions() { PortName = PortName }); + } } } diff --git a/BPASmartClient.Tourism/Server/PressureCookerServer.cs b/BPASmartClient.Tourism/Server/PressureCookerServer.cs index c62fc515..c2fe25f5 100644 --- a/BPASmartClient.Tourism/Server/PressureCookerServer.cs +++ b/BPASmartClient.Tourism/Server/PressureCookerServer.cs @@ -9,7 +9,20 @@ namespace BPASmartClient.MorkCL.Server /// /// 压力锅服务类 /// - internal class PressureCookerServer + internal class PressureCookerServer : PressureCookerSet, IModbus { + public void Init(string IP = "", int Port = 502, string PortName = "") + { + MyModbus = new ModbusTcp(); + MyModbus.Connected = () => + { + TaskManage.GetInstance.StartLong(new Action(() => + { + + Thread.Sleep(10); + }), $"压力锅服务-{IP}", true); + }; + MyModbus.Connect(new ConfigurationOptions() { IpAddress = IP, Port = Port }); + } } } diff --git a/BPASmartClient.Tourism/Server/RobotServer.cs b/BPASmartClient.Tourism/Server/RobotServer.cs index 82437d08..9f9dede2 100644 --- a/BPASmartClient.Tourism/Server/RobotServer.cs +++ b/BPASmartClient.Tourism/Server/RobotServer.cs @@ -19,7 +19,25 @@ namespace BPASmartClient.MorkCL.Server { TaskManage.GetInstance.StartLong(new Action(() => { + var m600 = MyModbus.Read("M600".ToModbusAdd(), 9); + if (m600.IsSuccess) + { + for (byte i = 0; i < 3; i++) + { + MaterialPouringRequest[i] = m600.Content[i * 3]; + MaterialPouringComplete[i] = m600.Content[i * 3 + 1]; + DiningOutRequest[i] = m600.Content[i * 3 + 2]; + } + } + var m630 = MyModbus.Read("M630".ToModbusAdd(), 12); + if (m630.IsSuccess) + { + for (byte i = 0; i < m630.Content.Length; i++) WarehousingComplete[i] = m630.Content[i]; + } + + var gi = MyModbus.Read("GI5".ToModbusAdd(), 1); + if (gi.IsSuccess) TaskFeedback = (RobotMainTask)gi.Content; Thread.Sleep(10); }), $"机器人服务-{IP}", true); @@ -29,7 +47,37 @@ namespace BPASmartClient.MorkCL.Server private void RobotInit() { + if (EnableState && ProgramRuning) return; + //if (!CR_Data.Home) + //{ + // Noticer.GetInstance().Show("煮面机器人初始化失败,机器人不在原点"); + // return; + //} + + while (!EnableState || !ProgramRuning) + { + //复位 + RobotReset = true; + Thread.Sleep(1000); + RobotReset = false; + Thread.Sleep(500); + + if (!EnableState) + { + //上使能 + RobotEnable = true; + Thread.Sleep(1000); + RobotEnable = false; + Thread.Sleep(500); + } + + //启动 + RobotStart = true; + Thread.Sleep(1000); + RobotStart = false; + Thread.Sleep(1000); + } } } } diff --git a/BPASmartClient.Tourism/Server/SqliteHelper.cs b/BPASmartClient.Tourism/Server/SqliteHelper.cs index 618c62b9..f6aada80 100644 --- a/BPASmartClient.Tourism/Server/SqliteHelper.cs +++ b/BPASmartClient.Tourism/Server/SqliteHelper.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace BPASmartClient.MorkCL.Server { - internal class SqliteHelper : ISqlLIte + internal class SqliteHelper : ISqlite { private volatile static SqliteHelper _Instance; diff --git a/BPASmartClient.Tourism/Server/TaskServer.cs b/BPASmartClient.Tourism/Server/TaskServer.cs new file mode 100644 index 00000000..90e33566 --- /dev/null +++ b/BPASmartClient.Tourism/Server/TaskServer.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkCL.Server +{ + public class TaskServer + { + /// + /// 获取任务是否执行完成 + /// + public bool IsComplete => RunTask == null ? false : RunTask.IsCompleted; + + /// + /// 任务取消标识 + /// + public CancellationTokenSource Cts { get; set; } = new CancellationTokenSource(); + + /// + /// 任务名称 + /// + public string TaskName { get; set; } + + + public Task RunTask { get; set; } + } +} diff --git a/BPASmartClient.Update/BPASmartClient.Update.csproj b/BPASmartClient.Update/BPASmartClient.Update.csproj index 1734e8bc..f37d5951 100644 --- a/BPASmartClient.Update/BPASmartClient.Update.csproj +++ b/BPASmartClient.Update/BPASmartClient.Update.csproj @@ -8,7 +8,7 @@ - + diff --git a/DosingSystem/BPASmartClient.DosingSystem.csproj b/DosingSystem/BPASmartClient.DosingSystem.csproj index 80a04092..1dfe801d 100644 --- a/DosingSystem/BPASmartClient.DosingSystem.csproj +++ b/DosingSystem/BPASmartClient.DosingSystem.csproj @@ -21,7 +21,7 @@ - + diff --git a/WpfTest/WpfTest.csproj b/WpfTest/WpfTest.csproj index 383e059c..ea14a78a 100644 --- a/WpfTest/WpfTest.csproj +++ b/WpfTest/WpfTest.csproj @@ -9,7 +9,7 @@ - +