From 10c885341438af00984e7b04efb41900007c57a0 Mon Sep 17 00:00:00 2001 From: taoye Date: Mon, 21 Nov 2022 17:08:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E9=85=92=E6=9C=BA=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.csproj | 2 +- .../Properties/Settings.Designer.cs | 2 +- .../BPASmartClient.JXJFoodSmallStation.csproj | 2 +- .../BPASmartClient.Model.csproj | 2 +- BPASmartClient.Model/MixWinkModel.cs | 25 ++ BPASmartClient.Model/订单/MorkMWSimOrder.cs | 13 + .../BPASmartClient.MorkF.csproj | 2 +- .../BPASmartClient.MorkMW.csproj | 21 ++ BPASmartClient.MorkMW/Control_MorkMW.cs | 313 ++++++++++++++++++ BPASmartClient.MorkMW/GVL_MorkMW.cs | 75 +++++ BPASmartClient.MorkMW/Model/OrderLocInfo.cs | 19 ++ BPASmartClient.MorkMW/Model/SimRecipeModel.cs | 18 + BPASmartClient.MorkMW/View/DebugView.xaml | 75 +++++ BPASmartClient.MorkMW/View/DebugView.xaml.cs | 28 ++ .../ViewModel/DebugViewModel.cs | 58 ++++ .../BPASmartClient.MorkS.csproj | 2 +- BPASmartClient/App.config | 8 +- BPASmartClient/BPASmartClient.csproj | 2 + BPASmartClient/DeviceInfo.xml | 21 +- .../BPASmartClient.DosingSystem.csproj | 2 +- SmartClient.sln | 25 +- TestDemo/Form1.Designer.cs | 37 +++ TestDemo/Form1.cs | 51 ++- TestDemo/MixWinkRecipe.cs | 20 ++ TestDemo/TestDemo.csproj | 1 + 27 files changed, 798 insertions(+), 30 deletions(-) create mode 100644 BPASmartClient.Model/MixWinkModel.cs create mode 100644 BPASmartClient.Model/订单/MorkMWSimOrder.cs create mode 100644 BPASmartClient.MorkMW/BPASmartClient.MorkMW.csproj create mode 100644 BPASmartClient.MorkMW/Control_MorkMW.cs create mode 100644 BPASmartClient.MorkMW/GVL_MorkMW.cs create mode 100644 BPASmartClient.MorkMW/Model/OrderLocInfo.cs create mode 100644 BPASmartClient.MorkMW/Model/SimRecipeModel.cs create mode 100644 BPASmartClient.MorkMW/View/DebugView.xaml create mode 100644 BPASmartClient.MorkMW/View/DebugView.xaml.cs create mode 100644 BPASmartClient.MorkMW/ViewModel/DebugViewModel.cs create mode 100644 TestDemo/MixWinkRecipe.cs diff --git a/BPASmartClient.Business/BPASmartClient.Business.csproj b/BPASmartClient.Business/BPASmartClient.Business.csproj index 7e88a063..9f0f535f 100644 --- a/BPASmartClient.Business/BPASmartClient.Business.csproj +++ b/BPASmartClient.Business/BPASmartClient.Business.csproj @@ -9,7 +9,7 @@ - + diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index 874b83ef..0afdf73d 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -410,7 +410,7 @@ - + diff --git a/BPASmartClient.Device/BPASmartClient.Device.csproj b/BPASmartClient.Device/BPASmartClient.Device.csproj index 456f5bbb..bbef1b12 100644 --- a/BPASmartClient.Device/BPASmartClient.Device.csproj +++ b/BPASmartClient.Device/BPASmartClient.Device.csproj @@ -7,7 +7,7 @@ - + diff --git a/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs b/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs index 804602c2..02053c8a 100644 --- a/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs +++ b/BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace BPASmartClient.JXJFoodBigStation.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj b/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj index cdb1d4f7..4a4ac0e0 100644 --- a/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj +++ b/BPASmartClient.JXJFoodSmallStation/BPASmartClient.JXJFoodSmallStation.csproj @@ -8,7 +8,7 @@ - + diff --git a/BPASmartClient.Model/BPASmartClient.Model.csproj b/BPASmartClient.Model/BPASmartClient.Model.csproj index 6237674c..620f2060 100644 --- a/BPASmartClient.Model/BPASmartClient.Model.csproj +++ b/BPASmartClient.Model/BPASmartClient.Model.csproj @@ -17,7 +17,7 @@ - + diff --git a/BPASmartClient.Model/MixWinkModel.cs b/BPASmartClient.Model/MixWinkModel.cs new file mode 100644 index 00000000..ae41ddbb --- /dev/null +++ b/BPASmartClient.Model/MixWinkModel.cs @@ -0,0 +1,25 @@ +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class MixWinkModel:ObservableObject + { + private string _materialName; + public string materialName { get { return _materialName; } set { _materialName = value;OnPropertyChanged(); } } + /// + /// 位置 + /// + private int _loc; + public int Loc { get { return _loc; } set { _loc = value;OnPropertyChanged(); } } + /// + /// 停留时间 + /// + public int Time { get { return _time; } set { _time = value;OnPropertyChanged(); } } + private int _time; + } +} diff --git a/BPASmartClient.Model/订单/MorkMWSimOrder.cs b/BPASmartClient.Model/订单/MorkMWSimOrder.cs new file mode 100644 index 00000000..5f11798b --- /dev/null +++ b/BPASmartClient.Model/订单/MorkMWSimOrder.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model.订单 +{ + public class MorkMWSimOrder:BaseEvent + { + public List mixWink = new List(); + } +} diff --git a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj index ea0b7fa5..3bfcd2df 100644 --- a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj +++ b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj @@ -10,7 +10,7 @@ - + diff --git a/BPASmartClient.MorkMW/BPASmartClient.MorkMW.csproj b/BPASmartClient.MorkMW/BPASmartClient.MorkMW.csproj new file mode 100644 index 00000000..2ebedcc7 --- /dev/null +++ b/BPASmartClient.MorkMW/BPASmartClient.MorkMW.csproj @@ -0,0 +1,21 @@ + + + + net6.0-windows + enable + true + + + + + + + + + + + + + + + diff --git a/BPASmartClient.MorkMW/Control_MorkMW.cs b/BPASmartClient.MorkMW/Control_MorkMW.cs new file mode 100644 index 00000000..b181c58a --- /dev/null +++ b/BPASmartClient.MorkMW/Control_MorkMW.cs @@ -0,0 +1,313 @@ +using BPA.Helper; +using BPA.Message.Enum; +using BPASmartClient.Device; +using BPASmartClient.EventBus; +using BPASmartClient.Modbus; +using BPASmartClient.Model; +using BPASmartClient.Model.PLC; +using BPASmartClient.Model.; +using BPASmartClient.MorkMW.Model; +using Org.BouncyCastle.Bcpg.OpenPgp; +using System; +using System.Collections.Concurrent; +using System.Threading; +using static BPASmartClient.EventBus.EventBus; + +namespace BPASmartClient.MorkMW +{ + public class Control_MorkMW : BaseDevice + { + ModbusTcp modbus; + public override DeviceClientType DeviceType => DeviceClientType.MORKMW; + GVL_MorkMW morkMW = new GVL_MorkMW(); + public override void DoMain() + { + + ConnectKlpRobot("192.168.0.100", 8001); + } + + public override void MainTask() + { + ToGetWink(); + ToMixWink(); + ToPourWink(); + SignalDetect(); + } + /// + /// Ӿƹ + /// + public void ToGetWink() + { + + if (morkMW.RobotIdle && orderLocInfos.Count > 0 && !morkMW.TaskLock&&!morkMW.PourWinkComplete&& morkMW.CupSignal) + { + DeviceProcessLogShow("ʼ"); + morkMW.TaskLock = true; + if (orderLocInfos.TryDequeue(out OrderLocInfo res)) + { + foreach (var item in res.mixWink) + { + switch (item.Loc) + { + // case 7: ToMixWink(); break; + case 1: ToSpecifiedLocTakeWink(item.Loc, item.Time); break; + case 2: ToSpecifiedLocTakeWink(item.Loc, item.Time); break; + case 3: ToSpecifiedLocTakeWink(item.Loc, item.Time); break; + case 4: ToSpecifiedLocTakeWink(item.Loc, item.Time); break; + case 5: ToSpecifiedLocTakeWink(item.Loc, item.Time); break; + case 6: ToSpecifiedLocTakeWink(item.Loc, item.Time); break; + + } + switch (item.Loc) + { + //case 7: while (!morkMW.MixWinkComplte) { Thread.Sleep(5); } break; + case 1: while (!morkMW.TakeWinkOneComplete) { Thread.Sleep(5); } break; + case 2: while (!morkMW.TakeWinkTwoComplete) { Thread.Sleep(5); } break; + case 3: while (!morkMW.TakeWinkThreeComplete) { Thread.Sleep(5); } break; + case 4: while (!morkMW.TakeWinkFourComplete) { Thread.Sleep(5); } break; + case 5: while (!morkMW.TakeWinkFiveComplete) { Thread.Sleep(5); } break; + case 6: while (!morkMW.TakeWinkSixComplete) { Thread.Sleep(5); } break; + + } + + + } + + morkMW.AllowMixWink = true;//Ӿɣ + // morkMW.AllowPourWink = true;//ɣ + } + } + } + /// + /// ƹ + /// + public void ToMixWink() + { + // modbus.WriteSingleRegister(0000, 7);//˵ + + if (morkMW.AllowMixWink) + { + DeviceProcessLogShow("ʼ"); + modbus.WriteSingleRegister(0000, 7);//˵ + morkMW.AllowMixWink = false; + } + } + /// + /// ȥӦλýӾ + /// + /// + /// + public void ToSpecifiedLocTakeWink(int loc, int time) + { + //ͽӾź + switch (loc) + { + case 1: modbus.WriteSingleRegister(0000, 1); break; + case 2: modbus.WriteSingleRegister(0000, 2); break; + case 3: modbus.WriteSingleRegister(0000, 3); break; + case 4: modbus.WriteSingleRegister(0000, 4); break; + case 5: modbus.WriteSingleRegister(0000, 5); break; + case 6: modbus.WriteSingleRegister(0000, 6); break; + + } + //ȴ˵Ӿλ + switch (loc) + { + case 1: while (!morkMW.ArriveWinkOneLoc) { Thread.Sleep(5); } break; + case 2: while (!morkMW.ArriveWinkTwoLoc) { Thread.Sleep(5); } break; + case 3: while (!morkMW.ArriveWinkThreeLoc) { Thread.Sleep(5); } break; + case 4: while (!morkMW.ArriveWinkFourLoc) { Thread.Sleep(5); } break; + case 5: while (!morkMW.ArriveWinkFiveLoc) { Thread.Sleep(5); } break; + case 6: while (!morkMW.ArriveWinkSixLoc) { Thread.Sleep(5); } break; + + } + Thread.Sleep(time * 1000);//ӾƵȴʱ + //ͽӾź + switch (loc) + { + case 1: modbus.WriteSingleCoil(4596, true); break; + case 2: modbus.WriteSingleCoil(4597, true); break; + case 3: modbus.WriteSingleCoil(4598, true); break; + case 4: modbus.WriteSingleCoil(4599, true); break; + case 5: modbus.WriteSingleCoil(4600, true); break; + case 6: modbus.WriteSingleCoil(4601, true); break; + + } + + } + /// + /// ƹ + /// + public void ToPourWink() + { + //if (morkMW.AllowPourWink && morkMW.CupSignal) + //{ + // morkMW.AllowPourWink = false; + // modbus.WriteSingleRegister(0000, 8);// + + //} + if (morkMW.CupSignal && RTrig.GetInstance("AllowOut").Start(morkMW.MixWinkComplte)) + { + DeviceProcessLogShow("ʼ"); + modbus.WriteSingleRegister(0000, 8);// + + } + + } + /// + /// źż + /// + public void SignalDetect() + { + if (RTrig.GetInstance("AllComplete").Start(morkMW.ProcessComplete)) + { + morkMW.PourWinkComplete = true; + DeviceProcessLogShow("ɣȡߵþƱ"); + } + if (morkMW.PourWinkComplete) + { + if (TTrig.GetInstance("PoutWinkCom").Start(morkMW.CupSignal)) + { + DeviceProcessLogShow("ͻȡߵþƱ,ÿվƱԴ´ζ"); + } + if (RTrig.GetInstance("PoutWinkCom").Start(morkMW.CupSignal)) + { + DeviceProcessLogShow("վƱλִһ"); + morkMW.PourWinkComplete = false; + morkMW.TaskLock = false; + Thread.Sleep(2000); + } + } + } + + + /// + /// ջ״̬ + /// + public override void ReadData() + { + //GetStatus("M230.0", new Action((obj) => + //{ + + //})); + if (modbus.Connected) + { + morkMW.ArriveWinkOneLoc = modbus.ReadCoils(4616); + morkMW.ArriveWinkTwoLoc = modbus.ReadCoils(4617); + morkMW.ArriveWinkThreeLoc = modbus.ReadCoils(4618); + morkMW.ArriveWinkFourLoc = modbus.ReadCoils(4619); + morkMW.ArriveWinkFiveLoc = modbus.ReadCoils(4620); + morkMW.ArriveWinkSixLoc = modbus.ReadCoils(4621); + + morkMW.RobotIdle = modbus.ReadCoils(4201); + + + morkMW.CupSignal = modbus.ReadInputs(0); + + + morkMW.TakeWinkOneComplete = modbus.ReadCoils(4606); + morkMW.TakeWinkTwoComplete = modbus.ReadCoils(4607); + morkMW.TakeWinkThreeComplete = modbus.ReadCoils(4608); + morkMW.TakeWinkFourComplete = modbus.ReadCoils(4609); + morkMW.TakeWinkFiveComplete = modbus.ReadCoils(4610); + morkMW.TakeWinkSixComplete = modbus.ReadCoils(4611); + morkMW.MixWinkComplte = modbus.ReadCoils(4612); + morkMW.ProcessComplete = modbus.ReadCoils(4613); + } + else + { + modbus.ModbusTcpConnect("192.168.0.100", 8001); + } + } + + public override void ResetProgram() + { + morkMW = null; + morkMW = new GVL_MorkMW(); + } + + + public override void SimOrder() + { + EventBus.EventBus.GetInstance().Subscribe(0, delegate (IEvent @event, EventCallBackHandle callBackHandle) + { + + if (@event != null && @event is MorkMWSimOrder order) + { + if (order.mixWink.Count > 0) + { + string guid = Guid.NewGuid().ToString(); + orderLocInfos.Enqueue(new OrderLocInfo { mixWink = order.mixWink, SuborderId = guid }); + DeviceProcessLogShow("յ"); + } + } + + }); + } + + public override void Stop() + { + + } + private void GetStatus(string key, Action action) + { + if (peripheralStatus.ContainsKey(key)) + { + if (peripheralStatus[key] != null) + { + action?.Invoke(peripheralStatus[key]); + } + } + } + /// + /// д + /// + /// + /// + private void WriteData(string address, object value) + { + EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value }); + } + /// + /// ݽ + /// + public void DataParse() + { + EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle) + { + + if (@event != null && @event is DoOrderEvent order) + { + + } + + }); + } + #region Դ + /// + /// ӿջ + /// + /// + /// + public void ConnectKlpRobot(string ip, int port) + { + modbus = new ModbusTcp(); + modbus.Show += new Action((s) => + { + if (s != null) DeviceProcessLogShow(s); + }); + modbus.ShowEx += new Action((s) => + { + if ((s != null)) DeviceProcessLogShow(s); + }); + modbus.ModbusTcpConnect(ip, port); + + } + #endregion + /// + /// ƶ + /// + public ConcurrentQueue orderLocInfos = new ConcurrentQueue(); + + } +} diff --git a/BPASmartClient.MorkMW/GVL_MorkMW.cs b/BPASmartClient.MorkMW/GVL_MorkMW.cs new file mode 100644 index 00000000..c4d8c375 --- /dev/null +++ b/BPASmartClient.MorkMW/GVL_MorkMW.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkMW +{ + public class GVL_MorkMW + { + #region 机器人信号 + + + /// + /// 机器人空闲信号 + /// + public bool RobotIdle { get; set; } + + public bool TakeWinkOneComplete { get; set; } + public bool TakeWinkTwoComplete { get; set; } + public bool TakeWinkThreeComplete { get; set; } + public bool TakeWinkFourComplete { get; set; } + public bool TakeWinkFiveComplete { get; set; } + public bool TakeWinkSixComplete { get; set; } + + + + + public bool ArriveWinkOneLoc { get; set; } + + public bool ArriveWinkTwoLoc { get; set; } + + public bool ArriveWinkThreeLoc { get; set; } + + public bool ArriveWinkFourLoc { get; set; } + + public bool ArriveWinkFiveLoc { get; set; } + + public bool ArriveWinkSixLoc { get; set; } + /// + /// 放杯处传感器信号 + /// + public bool CupSignal { get; set; } + /// + /// 摇酒完成信号 + /// + public bool MixWinkComplte { get; set; } + /// + /// 机器人倒完酒并回到初始位的完成信号 + /// + public bool ProcessComplete { get; set; } + #endregion + + + #region 流程控制 + /// + /// 任务锁 + /// + public bool TaskLock { get; set; } + /// + /// 接酒完成 + /// + public bool AllowMixWink { get; set; } + + /// + /// 调酒完成 + /// + public bool AllowPourWink { get; set; } + /// + /// 倒酒结束标志 + /// + public bool PourWinkComplete { get; set; } + #endregion + } +} diff --git a/BPASmartClient.MorkMW/Model/OrderLocInfo.cs b/BPASmartClient.MorkMW/Model/OrderLocInfo.cs new file mode 100644 index 00000000..e2894ed1 --- /dev/null +++ b/BPASmartClient.MorkMW/Model/OrderLocInfo.cs @@ -0,0 +1,19 @@ +using BPASmartClient.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkMW.Model +{ + public class OrderLocInfo + { + public string SuborderId { get; set; } + /// + /// 单个订单的制作流程 + /// + public List mixWink=new List(); + public string GoodName { get; set; } + } +} diff --git a/BPASmartClient.MorkMW/Model/SimRecipeModel.cs b/BPASmartClient.MorkMW/Model/SimRecipeModel.cs new file mode 100644 index 00000000..071ac08c --- /dev/null +++ b/BPASmartClient.MorkMW/Model/SimRecipeModel.cs @@ -0,0 +1,18 @@ +using BPASmartClient.Model; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkMW.Model +{ + public class SimRecipeModel + { + + public string GoodsName { get; set; } + + public ObservableCollection recipe { get; set; } = new ObservableCollection();// { new MixWinkModel { materialName="白兰地",Loc=7,Time=2} }; + } +} diff --git a/BPASmartClient.MorkMW/View/DebugView.xaml b/BPASmartClient.MorkMW/View/DebugView.xaml new file mode 100644 index 00000000..9620dd48 --- /dev/null +++ b/BPASmartClient.MorkMW/View/DebugView.xaml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +