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.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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +