diff --git a/BPASmartClient.Bus/BPASmartClient.Bus.csproj b/BPASmartClient.Bus/BPASmartClient.Bus.csproj new file mode 100644 index 00000000..cd3ccbd7 --- /dev/null +++ b/BPASmartClient.Bus/BPASmartClient.Bus.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BPASmartClient.Bus/DataBus/DataBus.cs b/BPASmartClient.Bus/DataBus/DataBus.cs new file mode 100644 index 00000000..232bbc49 --- /dev/null +++ b/BPASmartClient.Bus/DataBus/DataBus.cs @@ -0,0 +1,236 @@ + +using BPASmartClient.Bus.DataBus; +using BPASmartClient.Helper; +using BPASmartClinet.DataBusName; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + + +/* *********************************************** + * subject 数据总线,总线入口,后续按类型分发 + * author 张原川 + * date   2019/6/3 9:49:03 + * ***********************************************/ + +namespace LandStation.Bus.DataBus +{ + public class DataBus : Singleton, IDisposable + { + //原始数据总线 + private IDataBus _dataBus_rawdata; + //MAVLINK消息总线 + private IDataBus _dataBus_mavMessage; + //参数总线 + private IDataBus _dataBus_parameter; + //调试消息总线 + private IDataBus _dataBus_message; + + /// + /// 数据总线初始化 + /// + public void Initialize() + { + _dataBus_rawdata = new DataBus_Byte(); + _dataBus_mavMessage = new DataBus_Currency(); + _dataBus_parameter = new DataBus_Currency(); + _dataBus_message = new DataBus_Currency(); + } + + /// + /// 总线开启 + /// + public void Start() + { + Executer.GetInstance().Start(_dataBus_rawdata.StartBus, ActionKey.DataBus_Rawdata); + Executer.GetInstance().Start(_dataBus_mavMessage.StartBus, ActionKey.DataBus_MAVLinkMessage); + Executer.GetInstance().Start(_dataBus_message.StartBus, ActionKey.DataBus_MessageData); + Executer.GetInstance().Start(_dataBus_parameter.StartBus, ActionKey.DataBus_ParameterData); + + //Executer.GetInstance().Start(delegate () + //{ + // while (true) + // { + // //Console.WriteLine("原始数据========>批量数据订阅数:{0},单数据订阅数:{1}", _dataBus_rawdata.MultSubscriberCount, _dataBus_rawdata.SingleSubscriberCount); + // //Console.WriteLine("MAVLink数据=====>批量数据订阅数:{0},单数据订阅数:{1}", _dataBus_mavMessage.MultSubscriberCount, _dataBus_mavMessage.SingleSubscriberCount); + // //Console.WriteLine("状态数据========>批量数据订阅数:{0},单数据订阅数:{1}", _dataBus_status.MultSubscriberCount, _dataBus_status.SingleSubscriberCount); + // //Console.WriteLine("参数数据========>批量数据订阅数:{0},单数据订阅数:{1}", _dataBus_parameter.MultSubscriberCount, _dataBus_parameter.SingleSubscriberCount); + // //Console.WriteLine("消息数据========>批量数据订阅数:{0},单数据订阅数:{1}", _dataBus_message.MultSubscriberCount, _dataBus_message.SingleSubscriberCount); + // //Console.WriteLine("==============================================================================================="); + // Console.WriteLine("原始数据========>{0}", _dataBus_rawdata.DataCount); + // Console.WriteLine("MAVLink数据=====>{0}", _dataBus_mavMessage.DataCount); + // Console.WriteLine("状态数据========>{0}", _dataBus_status.DataCount); + // Console.WriteLine("参数数据========>{0}", _dataBus_parameter.DataCount); + // Console.WriteLine("消息数据========>{0}", _dataBus_message.DataCount); + // Console.WriteLine("==============================================================================================="); + // Thread.Sleep(50); + // } + //}, ActionKey.DataBus_Monitor, "数据总线监控"); + } + + /// + /// 根据数据类型放入数据到对应总线 + /// + /// 数据实际类型 + /// 数据 + /// 数据业务类型 + public void Put(object data, SimpleDataType simpleData) + { + switch (simpleData) + { + case SimpleDataType.RAW_DATA: + if (data is byte) + _dataBus_rawdata.Put((byte)data); + if (data is byte[]) + _dataBus_rawdata.Put((byte[])data); + break; + case SimpleDataType.MAV_MESSAGE_DATA: + _dataBus_mavMessage.Put((object)data); + break; + case SimpleDataType.PARAMETER: + _dataBus_parameter.Put((object)data); + break; + case SimpleDataType.MESSAGE_DATA: + _dataBus_message.Put((string)data); + break; + } + } + + /// + /// 订阅数据 + /// + /// 数据实际类型 + /// 接收数据推送回调 + /// 数据业务类型 + public void Subscribe(Action action, SimpleDataType dataType) + { + switch (dataType) + { + case SimpleDataType.RAW_DATA: + ((ISimpleDataBus)_dataBus_rawdata).Subscribe(action); + break; + case SimpleDataType.MAV_MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_mavMessage).Subscribe(action); + break; + case SimpleDataType.PARAMETER: + ((ISimpleDataBus)_dataBus_parameter).Subscribe(action); + break; + case SimpleDataType.MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_message).Subscribe(action); + break; + } + } + + /// + /// 订阅数据 + /// + /// 数据实际类型 + /// 接收数据推送回调 + /// 数据业务类型 + public void UnSubscribe(Action action, SimpleDataType dataType) + { + switch (dataType) + { + case SimpleDataType.RAW_DATA: + ((ISimpleDataBus)_dataBus_rawdata).UnSubcribe(action); + break; + case SimpleDataType.MAV_MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_mavMessage).UnSubcribe(action); + break; + case SimpleDataType.PARAMETER: + ((ISimpleDataBus)_dataBus_parameter).UnSubcribe(action); + break; + case SimpleDataType.MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_message).UnSubcribe(action); + break; + } + } + + /// + /// 订阅数据 + /// + /// 数据实际类型 + /// 接收数据推送回调 + /// 数据业务类型 + public void Subscribe(Action action, SimpleDataType dataType) + { + switch (dataType) + { + case SimpleDataType.RAW_DATA: + ((ISimpleDataBus)_dataBus_rawdata).Subscribe(action); + break; + case SimpleDataType.MAV_MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_mavMessage).Subscribe(action); + break; + case SimpleDataType.PARAMETER: + ((ISimpleDataBus)_dataBus_parameter).Subscribe(action); + break; + case SimpleDataType.MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_message).Subscribe(action); + break; + } + } + + /// + /// 订阅数据 + /// + /// 数据实际类型 + /// 接收数据推送回调 + /// 数据业务类型 + public void UnSubscribe(Action action, SimpleDataType dataType) + { + switch (dataType) + { + case SimpleDataType.RAW_DATA: + ((ISimpleDataBus)_dataBus_rawdata).UnSubcribe(action); + break; + case SimpleDataType.MAV_MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_mavMessage).UnSubcribe(action); + break; + case SimpleDataType.PARAMETER: + ((ISimpleDataBus)_dataBus_parameter).UnSubcribe(action); + break; + case SimpleDataType.MESSAGE_DATA: + ((ISimpleDataBus)_dataBus_message).UnSubcribe(action); + break; + } + } + + /// + /// 获取一个数据 + /// + /// 数据实际类型 + /// 数据业务类型 + /// 一个数据 + public byte GetRawdata() + { + return ((IGivenDataBus)_dataBus_rawdata).Get(); + } + + /// + /// 获取多个数据 + /// + /// 数据实际类型 + /// 数据业务类型 + /// 获取数据长度 + /// 一个数据 + public byte[] GetRawdata(int length) + { + return ((IGivenDataBus)_dataBus_rawdata).Get(length); + } + + /// + /// 释放数据总线 + /// + public void Dispose() + { + _dataBus_rawdata.StopBus(); + _dataBus_mavMessage.StopBus(); + _dataBus_message.StopBus(); + _dataBus_parameter.StopBus(); + } + } +} diff --git a/BPASmartClient.Bus/DataBus/DataBus_Byte.cs b/BPASmartClient.Bus/DataBus/DataBus_Byte.cs new file mode 100644 index 00000000..79bdf175 --- /dev/null +++ b/BPASmartClient.Bus/DataBus/DataBus_Byte.cs @@ -0,0 +1,98 @@ + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + + +/* *********************************************** + * subject Byte类型数据总线,在订阅推送模式基础上 + * 增加主动获取 + * author 张原川 + * date   2019/6/3 14:44:36 + * ***********************************************/ + +namespace BPASmartClient.Bus.DataBus +{ + public class DataBus_Byte : DataBus_Currency, IGivenDataBus + { + //接收数据缓冲(用以Get) + //protected CircularBuffer _givenDataPool = new CircularBuffer(1 * 1024 * 1024); + protected ConcurrentQueue _givenDataPool = new ConcurrentQueue(); + + public new int DataCount { get { return _givenDataPool.Count; } } + + /// + /// 重写Put方法,加入givenDataPool + /// + public new void Put(byte data) + { + if (!_running) + return; + if (_multDataHandlers.Count > 0 || _singleDataHandlers.Count > 0) + _dataPool.Enqueue(data); + _givenDataPool.Enqueue(data); + } + + /// + /// 重写Put方法,加入givenDataPool + /// + public new void Put(byte[] data) + { + if (!_running) + return; + if (_multDataHandlers.Count > 0 || _singleDataHandlers.Count > 0) + foreach (var item in data) + _dataPool.Enqueue(item); + foreach (var item in data) + _givenDataPool.Enqueue(item); + } + + /// + /// 数据取出 + /// + public byte Get() + { + agin: + if (_givenDataPool.Count <= 0) + { + Thread.Sleep(5); + goto agin; + } + byte res; + while (!_givenDataPool.TryDequeue(out res)) ; + return res; + } + + /// + /// 数据取出 + /// + public byte[] Get(int count) + { + agin: + if (_givenDataPool.Count < count) + { + Thread.Sleep(5); + goto agin; + } + //Console.WriteLine(_givenDataPool.Size + "===========" + _dataPool.Size); + //for (int i = 0; i < count; i++) { + // _givenDataPool.TryDequeue + //} + int i = 0; + byte[] result = new byte[count]; + while (i < count) + { + if (_givenDataPool.TryDequeue(out result[i])) + { + i++; + } + } + + return result;// _givenDataPool.Get(count); + } + } +} diff --git a/BPASmartClient.Bus/DataBus/DataBus_Currency.cs b/BPASmartClient.Bus/DataBus/DataBus_Currency.cs new file mode 100644 index 00000000..d3d20b97 --- /dev/null +++ b/BPASmartClient.Bus/DataBus/DataBus_Currency.cs @@ -0,0 +1,190 @@ + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + + +/* *********************************************** + * subject 通用数据总线,采取订阅推送模式 + * author 张原川 + * date   2019/6/3 15:03:10 + * ***********************************************/ + +namespace BPASmartClient.Bus.DataBus +{ + public class DataBus_Currency : ISimpleDataBus + { + //接收数据缓冲 + //protected CircularBuffer _dataPool = new CircularBuffer(1 * 1024 * 1024); + protected ConcurrentQueue _dataPool = new ConcurrentQueue(); + //订阅数据回调集合 + protected List> _multDataHandlers = new List>(); + protected List> _singleDataHandlers = new List>(); + //订阅与推送数据信号量 + protected AutoResetEvent _are = new AutoResetEvent(false); + //运行标识 + protected bool _running = false; + + public int MultSubscriberCount { get { return _multDataHandlers.Count; } } + + public int SingleSubscriberCount { get { return _singleDataHandlers.Count; } } + + public int DataCount { get { return _dataPool.Count; } } + + /// + /// 终止事件总线 + /// + public void Dispose() + { + StopBus(); + } + + /// + /// 数据存入 + /// + public void Put(TData data) + { + if (!_running) + return; + if (_multDataHandlers.Count > 0 || _singleDataHandlers.Count > 0) + _dataPool.Enqueue(data); + } + + /// + /// 数据存入 + /// + public void Put(TData[] data) + { + if (!_running) + return; + if (_multDataHandlers.Count > 0 || _singleDataHandlers.Count > 0) + foreach (var item in data) + _dataPool.Enqueue(item); + } + + /// + /// 开启总线 + /// + public void StartBus() + { + _running = true; + List items = new List(); + _are.Set(); + while (_running) + { + int count = _dataPool.Count; + items.Clear(); + if (_singleDataHandlers.Count > 0) + { + _are.WaitOne(TimeSpan.FromMilliseconds(10)); + + for (int i = 0; i < count; i++) + { + TData data = default(TData); + + while (!_dataPool.TryDequeue(out data)) ; + + uint msgId = Convert.ToUInt32(data.GetType().GetProperty("msgid").GetValue(data)); + if (msgId == 316) + { + + } + //var item = _dataPool.Get(); + //Parallel.ForEach(_singleDataHandlers, p => p.Invoke(items[items.Count - 1])); + + for (int j = 0; j < _singleDataHandlers.Count; j++) + { + _singleDataHandlers[j].Invoke(data); + } + items.Add(data); + } + } + if (_multDataHandlers.Count > 0) + { + if (items.Count <= 0) + { + TData data = default(TData); + for (int i = 0; i < count; i++) + { + while (!_dataPool.TryDequeue(out data)) ; + items.Add(data); + } + //items.AddRange(_dataPool.Get(count)); + } + _are.WaitOne(TimeSpan.FromMilliseconds(10)); + //Parallel.For(0, _multDataHandlers.Count, (i) => + //{ + // _multDataHandlers[i].Invoke(items.ToArray()); + //}); + for (int i = _multDataHandlers.Count - 1; i >= 0; i--) + { + _multDataHandlers[i].Invoke(items.ToArray()); + } + } + Thread.Sleep(10); + _are.Set(); + } + } + + public void StopBus() + { + _running = false; + } + + /// + /// 数据订阅 + /// + /// 接收数据回调 + public void Subscribe(Action action) + { + if (_singleDataHandlers.Contains(action)) + return; + _are.Reset(); + _singleDataHandlers.Add(action); + _are.Set(); + } + + /// + /// 数据订阅 + /// + /// 接收数据回调 + public void Subscribe(Action action) + { + if (_multDataHandlers.Contains(action)) + return; + _are.Reset(); + _multDataHandlers.Add(action); + _are.Set(); + } + + /// + /// 取消数据订阅 + /// + /// 接收数据回调 + public void UnSubcribe(Action action) + { + if (!_singleDataHandlers.Contains(action)) + return; + _are.Reset(); + _singleDataHandlers.Remove(action); + _are.Set(); + } + + /// + /// 取消数据订阅 + /// + /// 接收数据回调 + public void UnSubcribe(Action action) + { + if (!_multDataHandlers.Contains(action)) + return; + _are.Reset(); + _multDataHandlers.Remove(action); + _are.Set(); + } + } +} diff --git a/BPASmartClient.Bus/DataBus/Executer.cs b/BPASmartClient.Bus/DataBus/Executer.cs new file mode 100644 index 00000000..3aa83f59 --- /dev/null +++ b/BPASmartClient.Bus/DataBus/Executer.cs @@ -0,0 +1,149 @@ +using BPASmartClient.Helper; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Bus.DataBus +{ + /// + /// 线程集中处理委托 + /// + /// + public delegate void ActionKeyHandle(string action); + public delegate void ThreadExceptionHandle(string action, Exception ex); + public delegate void ThreadExitHandle(string action); + /// + /// 执行器 + /// + public class Executer : Singleton + { + private System.Timers.Timer _timer4Monitor = new System.Timers.Timer(1000); + private ConcurrentDictionary _actions = new ConcurrentDictionary(); + private object _async = new object(); + public event ThreadExceptionHandle OnThreadException; + public event ThreadExitHandle ThreadExit; + /// + /// 构造器 + /// + public Executer() + { + } + + /// + /// + /// + public void Dispose() + { + _timer4Monitor.Stop(); + foreach (var th in _actions) + { + try { th.Value.Abort(); } + catch (ThreadAbortException) { } + } + } + /// + /// + /// + /// + public List GetActionInfos() + { + Monitor.TryEnter(_async, 200); + var actionInfos = _actions.Values.ToList(); + Monitor.Exit(_async); + return actionInfos; + } + + + /// + /// + /// + /// + public void Abort(string key) + { + Monitor.TryEnter(_async, 200); + if (_actions.ContainsKey(key)) + { + try { _actions[key].Abort(); } + catch (ThreadAbortException) { } + } + Monitor.Exit(_async); + } + /// + /// + /// + /// + /// + public bool ContainsKey(string key) + { + Monitor.TryEnter(_async, 200); + var item = _actions[key]; + Monitor.Exit(_async); + if (null != item) + { + return true; + } + return false; + } + /// + /// + /// + /// + /// + /// + /// + public void Start(Action action, string name, bool isBackground = false, ThreadPriority priority = ThreadPriority.Normal) + { + Thread thread = new Thread(() => + { + try + { + action(); + ThreadExit?.Invoke(name); + } + catch (Exception ex) + { + OnThreadException?.Invoke(name, ex); + } + }); + thread.IsBackground = isBackground; + thread.Priority = priority; + thread.Name = name; + thread.Start(); + Monitor.TryEnter(_async, 50); + if (_actions.ContainsKey(name)) + { + try { _actions[name].Abort(); } + catch (ThreadAbortException) { } + } + _actions[name] = thread; + Monitor.Exit(_async); + } + /// + /// + /// + /// + /// + /// + public bool StartWhiteReturn(Func action, int timeout = 3) + { + DateTime beginTime = DateTime.Now; + bool doResult = false; + while (DateTime.Now.Subtract(beginTime).TotalSeconds <= 3 && !doResult) + { + doResult = action(); + } + return doResult; + } + /// + /// + /// + public event ActionKeyHandle ActionAbort; + /// + /// + /// + public event ActionKeyHandle ActionStarted; + } +} diff --git a/BPASmartClient.Bus/DataBus/IDataBus.cs b/BPASmartClient.Bus/DataBus/IDataBus.cs new file mode 100644 index 00000000..34519c41 --- /dev/null +++ b/BPASmartClient.Bus/DataBus/IDataBus.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +/* *********************************************** + * subject 数据总线接口 + * author 张原川 + * date   2019/6/3 11:33:57 + * ***********************************************/ + +namespace BPASmartClient.Bus.DataBus +{ + /// + /// 数据总线接口 + /// + public interface IDataBus + { + /// + /// 多数据订阅数量 + /// + int MultSubscriberCount { get; } + /// + /// 单数据订阅数量 + /// + int SingleSubscriberCount { get; } + /// + /// 数据量 + /// + int DataCount { get; } + /// + /// 开启总线 + /// + void StartBus(); + + /// + /// 关闭总线 + /// + void StopBus(); + + /// + /// 数据放入总线 + /// + /// 数据 + void Put(TData data); + /// + /// 数据放入总线 + /// + /// 数据 + void Put(TData[] data); + } +} diff --git a/BPASmartClient.Bus/DataBus/IGivenDataBus.cs b/BPASmartClient.Bus/DataBus/IGivenDataBus.cs new file mode 100644 index 00000000..5faad71f --- /dev/null +++ b/BPASmartClient.Bus/DataBus/IGivenDataBus.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +/* *********************************************** + * subject 数据总线接口,定义主动取得数据 + * author 张原川 + * date   2019/6/3 11:25:11 + * ***********************************************/ + +namespace BPASmartClient.Bus.DataBus +{ + public interface IGivenDataBus: IDataBus + { + /// + /// 数据取出 + /// + /// + TData Get(); + + /// + /// 数据取出 + /// + /// + TData[] Get(int count); + } +} diff --git a/BPASmartClient.Bus/DataBus/ISimpleDataBus.cs b/BPASmartClient.Bus/DataBus/ISimpleDataBus.cs new file mode 100644 index 00000000..a1e71440 --- /dev/null +++ b/BPASmartClient.Bus/DataBus/ISimpleDataBus.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +/* *********************************************** + * subject 数据总线接口,定义原始数据、MAVLINK消息、状态数据、消息数据标准 + * author 张原川 + * date   2019/6/3 9:50:01 + * ***********************************************/ + +namespace BPASmartClient.Bus.DataBus +{ + interface ISimpleDataBus: IDataBus,IDisposable + { + /// + /// 订阅总线数据 + /// + /// 数据类型 + void Subscribe(Action action); + void Subscribe(Action action); + + /// + /// 取消订阅数据 + /// + /// 数据类型 + void UnSubcribe(Action action); + void UnSubcribe(Action action); + + } +} diff --git a/BPASmartClient.Bus/DataBus/SimpleDataType.cs b/BPASmartClient.Bus/DataBus/SimpleDataType.cs new file mode 100644 index 00000000..f3a609ee --- /dev/null +++ b/BPASmartClient.Bus/DataBus/SimpleDataType.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Bus.DataBus +{ + public enum SimpleDataType + { + /// + /// 原始数据总线 + /// + RAW_DATA, + /// + /// MAVLINK消息总线 + /// + MAV_MESSAGE_DATA, + /// + /// 全局状态数据总线 + /// + STATUS_DATA, + /// + /// 参数总线 + /// + PARAMETER, + /// + /// 调试消息总线 + /// + MESSAGE_DATA + } +} diff --git a/BPASmartClient.Bus/EventBus/EventBus.cs b/BPASmartClient.Bus/EventBus/EventBus.cs new file mode 100644 index 00000000..1b60cba2 --- /dev/null +++ b/BPASmartClient.Bus/EventBus/EventBus.cs @@ -0,0 +1,108 @@ + +using BPASmartClient.Bus.EventBus; +using BPASmartClient.Helper; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +/* *********************************************** + * subject 事件总线,总线入口,后续按类型分发 + * author 张原川 + * date   2019/6/3 15:49:03 + * ***********************************************/ + +namespace LandStation.Bus +{ + public class EventBus : Singleton + { + //事件处理委托 + public delegate void EventCallBackHandle(params object[] args); + //事件处理委托 + public delegate void EventHandle(IEvent @event, EventCallBackHandle callBack = null); + //事件订阅者集合 + private ConcurrentDictionary> _eventHandls = new ConcurrentDictionary>(); + + /// + /// 事件订阅 + /// + public void Subscribe(EventHandle handle) + { + if (!_eventHandls.ContainsKey(typeof(TEvent))) + _eventHandls.TryAdd(typeof(TEvent), new List()); + lock (_eventHandls) + _eventHandls[typeof(TEvent)].Add(handle); + } + + /// + /// 事件退订 + /// + public void UnSubscribe(EventHandle handle) + { + if (_eventHandls.ContainsKey(typeof(TEvent))) + { + if (_eventHandls[typeof(TEvent)].Contains(handle)) + { + lock (_eventHandls) + _eventHandls[typeof(TEvent)].Remove(handle); + } + } + } + + /// + /// 事件发布,不带返回 + /// + public void Publish(TEvent @event) where TEvent : IEvent + { + if (_eventHandls.ContainsKey(typeof(TEvent))) + { + for (int i = _eventHandls[typeof(TEvent)].Count - 1; i >= 0; i--) + _eventHandls[typeof(TEvent)][i](@event); + + //_eventHandls[typeof(TEvent)].ForEach(p => + //{ + // p(@event); + //}); + } + } + + /// + /// 事件发布,带返回 + /// + public void Publish(TEvent @event, EventCallBackHandle eventCallBack) where TEvent : IEvent + { + List result = new List(); + if (_eventHandls.ContainsKey(typeof(TEvent))) + { + //_eventHandls[typeof(TEvent)].ForEach(p => + //{ + // p(@event, delegate (object[] args) + // { + // result.AddRange(args); + // }); + //}); + + for (int i = _eventHandls[typeof(TEvent)].Count - 1; i >= 0; i--) + { + _eventHandls[typeof(TEvent)][i](@event, delegate (object[] args) + { + result.AddRange(args); + }); + } + + } + eventCallBack.Invoke(result.ToArray()); + } + + /// + /// 事件总线释放 + /// + public void Dispose() + { + _eventHandls.Clear(); + } + } + +} diff --git a/BPASmartClient.Bus/EventBus/IEvent.cs b/BPASmartClient.Bus/EventBus/IEvent.cs new file mode 100644 index 00000000..cffc3ad9 --- /dev/null +++ b/BPASmartClient.Bus/EventBus/IEvent.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Bus.EventBus +{ + /// + /// 事件接口 + /// + public interface IEvent + { + int DeviceId { get; set; } + } +} diff --git a/BPASmartClient.Bus/EventBus/IEventExtends.cs b/BPASmartClient.Bus/EventBus/IEventExtends.cs new file mode 100644 index 00000000..9dea6010 --- /dev/null +++ b/BPASmartClient.Bus/EventBus/IEventExtends.cs @@ -0,0 +1,35 @@ +/* ============================================================================== +* 功能描述: +* 创 建 者:张原川 +* 创建日期:2016/10/10 16:50:12 +* ==============================================================================*/ + +using BPASmartClient.Bus.EventBus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace LandStation.Bus +{ + /// + /// + /// + public static class IEventExtends + { + + #region Methods - Public + + public static void Publish(this TEvent message) where TEvent : class, IEvent + { + EventBus.GetInstance().Publish(message); + } + + public static void Publish(this TEvent message, EventBus.EventCallBackHandle eventCallBack) where TEvent : class, IEvent + { + EventBus.GetInstance().Publish(message, eventCallBack); + } + + #endregion + } +} diff --git a/BPASmartClient.Compiler/BPASmartClient.Compiler.csproj b/BPASmartClient.Compiler/BPASmartClient.Compiler.csproj new file mode 100644 index 00000000..f8198dde --- /dev/null +++ b/BPASmartClient.Compiler/BPASmartClient.Compiler.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + + + DLL\Antlr3.Runtime.dll + + + DLL\Unvell.ReoScript.dll + + + + diff --git a/BPASmartClient.Compiler/Config.cs b/BPASmartClient.Compiler/Config.cs new file mode 100644 index 00000000..b2f51e33 --- /dev/null +++ b/BPASmartClient.Compiler/Config.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Unvell.ReoScript; + +namespace BPASmartClient.Compiler +{ + public class Config + { + #region 单例模式 + public static Config Instance = null; + + public static Config GetInstance() + { + if (Instance == null) + { + Instance = new Config(); + } + return Instance; + } + #endregion + + public static ScriptRunningMachine srm { get; } = new ScriptRunningMachine(); + + public Config() + { + srm.WorkMode |= + // Enable DirectAccess + MachineWorkMode.AllowDirectAccess + // Ignore exceptions in CLR calling (by default) + | MachineWorkMode.IgnoreCLRExceptions + // Enable CLR Event Binding + | MachineWorkMode.AllowCLREventBind; + + RegisterFunction(); + } + + /// + /// 运行脚本 + /// + /// + public void RunJsScipt(string script) + { + try + { + srm.Run(script); + } + catch (Exception e) + { + //MessageBox.Show(e.Message, "脚本错误"); + } + } + + /// + /// 注册对象到js + /// + public void SetVariable(string name, object obj) + { + srm.SetGlobalVariable(name, obj); + } + + /// + /// 注册方法到Js + /// + private static void RegisterFunction() + { + srm["ShowMessage"] = new NativeFunctionObject("ShowMessage", (ctx, owner, args) => + { + StringBuilder sb = new StringBuilder(); + foreach (var item in args) + { + sb.Append(item.ToString()); + } + + //MessageBox.Show($"{sb}", "提示"); + return null; + }); + + srm["SetICDValue"] = new NativeFunctionObject("SetICDValue", (ctx, owner, args) => + { + //MessageBox.Show($"发送ICD数据", "提示"); + return null; + }); + } + } +} \ No newline at end of file diff --git a/BPASmartClient.Compiler/DLL/Antlr3.Runtime.dll b/BPASmartClient.Compiler/DLL/Antlr3.Runtime.dll new file mode 100644 index 00000000..34bd478f Binary files /dev/null and b/BPASmartClient.Compiler/DLL/Antlr3.Runtime.dll differ diff --git a/BPASmartClient.Compiler/DLL/Unvell.ReoScript.dll b/BPASmartClient.Compiler/DLL/Unvell.ReoScript.dll new file mode 100644 index 00000000..eae3ea23 Binary files /dev/null and b/BPASmartClient.Compiler/DLL/Unvell.ReoScript.dll differ diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index 3098ed7c..93ff2f7a 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -87,6 +87,7 @@ + @@ -113,6 +114,8 @@ + + @@ -122,6 +125,10 @@ + + + + @@ -131,6 +138,7 @@ + @@ -141,9 +149,12 @@ + + + @@ -186,12 +197,14 @@ + + @@ -207,9 +220,17 @@ + + + + + + + + @@ -276,6 +297,7 @@ + @@ -286,6 +308,8 @@ + + @@ -294,9 +318,14 @@ + + + + + PreserveNewest @@ -304,6 +333,9 @@ + + + @@ -312,9 +344,12 @@ + + + @@ -322,6 +357,13 @@ + + + + + + + diff --git a/BPASmartClient.CustomResource/Fonts/font/iconfont.ttf b/BPASmartClient.CustomResource/Fonts/font/iconfont.ttf index f964af1f..f34fabb3 100644 Binary files a/BPASmartClient.CustomResource/Fonts/font/iconfont.ttf and b/BPASmartClient.CustomResource/Fonts/font/iconfont.ttf differ diff --git a/BPASmartClient.CustomResource/Fonts/iconfont.ttf b/BPASmartClient.CustomResource/Fonts/iconfont.ttf index 49538a0d..3fa0ee4c 100644 Binary files a/BPASmartClient.CustomResource/Fonts/iconfont.ttf and b/BPASmartClient.CustomResource/Fonts/iconfont.ttf differ diff --git a/BPASmartClient.CustomResource/Image/中间.png b/BPASmartClient.CustomResource/Image/中间.png new file mode 100644 index 00000000..79d33689 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/中间.png differ diff --git a/BPASmartClient.CustomResource/Image/外边框1.png b/BPASmartClient.CustomResource/Image/外边框1.png new file mode 100644 index 00000000..99e43642 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/外边框1.png differ diff --git a/BPASmartClient.CustomResource/Image/容器边框2.png b/BPASmartClient.CustomResource/Image/容器边框2.png new file mode 100644 index 00000000..ce789ebc Binary files /dev/null and b/BPASmartClient.CustomResource/Image/容器边框2.png differ diff --git a/BPASmartClient.CustomResource/Image/按钮/组 7.png b/BPASmartClient.CustomResource/Image/按钮/组 7.png new file mode 100644 index 00000000..47cf27eb Binary files /dev/null and b/BPASmartClient.CustomResource/Image/按钮/组 7.png differ diff --git a/BPASmartClient.CustomResource/Image/按钮/组 8.png b/BPASmartClient.CustomResource/Image/按钮/组 8.png new file mode 100644 index 00000000..c58a30eb Binary files /dev/null and b/BPASmartClient.CustomResource/Image/按钮/组 8.png differ diff --git a/BPASmartClient.CustomResource/Image/按钮背景蓝色.png b/BPASmartClient.CustomResource/Image/按钮背景蓝色.png new file mode 100644 index 00000000..1841afb6 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/按钮背景蓝色.png differ diff --git a/BPASmartClient.CustomResource/Image/按钮背景黄.png b/BPASmartClient.CustomResource/Image/按钮背景黄.png new file mode 100644 index 00000000..493b0a24 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/按钮背景黄.png differ diff --git a/BPASmartClient.CustomResource/Image/标签.png b/BPASmartClient.CustomResource/Image/标签.png new file mode 100644 index 00000000..a06611f3 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/标签.png differ diff --git a/BPASmartClient.CustomResource/Image/直线.png b/BPASmartClient.CustomResource/Image/直线.png new file mode 100644 index 00000000..cd2e45ba Binary files /dev/null and b/BPASmartClient.CustomResource/Image/直线.png differ diff --git a/BPASmartClient.CustomResource/Image/矩形2.png b/BPASmartClient.CustomResource/Image/矩形2.png new file mode 100644 index 00000000..e3ee2060 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/矩形2.png differ diff --git a/BPASmartClient.CustomResource/Image/矩形边框.png b/BPASmartClient.CustomResource/Image/矩形边框.png new file mode 100644 index 00000000..c5b24170 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/矩形边框.png differ diff --git a/BPASmartClient.CustomResource/Image/背景框.png b/BPASmartClient.CustomResource/Image/背景框.png new file mode 100644 index 00000000..abb15a4b Binary files /dev/null and b/BPASmartClient.CustomResource/Image/背景框.png differ diff --git a/BPASmartClient.CustomResource/Image/背景边框4.png b/BPASmartClient.CustomResource/Image/背景边框4.png new file mode 100644 index 00000000..9232c1e3 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/背景边框4.png differ diff --git a/BPASmartClient.CustomResource/Image/边框线.png b/BPASmartClient.CustomResource/Image/边框线.png new file mode 100644 index 00000000..881680e1 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/边框线.png differ diff --git a/BPASmartClient.CustomResource/Image/透明背景.png b/BPASmartClient.CustomResource/Image/透明背景.png new file mode 100644 index 00000000..597bfb87 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/透明背景.png differ diff --git a/BPASmartClient.CustomResource/Image/配方背景/圆角矩形.png b/BPASmartClient.CustomResource/Image/配方背景/圆角矩形.png new file mode 100644 index 00000000..8cd9f0c5 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/配方背景/圆角矩形.png differ diff --git a/BPASmartClient.CustomResource/Image/配方背景/竖背景框.png b/BPASmartClient.CustomResource/Image/配方背景/竖背景框.png new file mode 100644 index 00000000..4863dfe8 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/配方背景/竖背景框.png differ diff --git a/BPASmartClient.CustomResource/Image/配方背景/组 5.png b/BPASmartClient.CustomResource/Image/配方背景/组 5.png new file mode 100644 index 00000000..d0b0290d Binary files /dev/null and b/BPASmartClient.CustomResource/Image/配方背景/组 5.png differ diff --git a/BPASmartClient.CustomResource/Image/配方背景/蓝色背景.png b/BPASmartClient.CustomResource/Image/配方背景/蓝色背景.png new file mode 100644 index 00000000..f1084a3f Binary files /dev/null and b/BPASmartClient.CustomResource/Image/配方背景/蓝色背景.png differ diff --git a/BPASmartClient.CustomResource/Image/配方背景/蓝色背景2.png b/BPASmartClient.CustomResource/Image/配方背景/蓝色背景2.png new file mode 100644 index 00000000..461a5a67 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/配方背景/蓝色背景2.png differ diff --git a/BPASmartClient.CustomResource/Image/配方背景/黄色背景.png b/BPASmartClient.CustomResource/Image/配方背景/黄色背景.png new file mode 100644 index 00000000..e93a3167 Binary files /dev/null and b/BPASmartClient.CustomResource/Image/配方背景/黄色背景.png differ diff --git a/BPASmartClient.CustomResource/Pages/Model/AlarmHelper.cs b/BPASmartClient.CustomResource/Pages/Model/AlarmHelper.cs index e45218ff..9d8a3f76 100644 --- a/BPASmartClient.CustomResource/Pages/Model/AlarmHelper.cs +++ b/BPASmartClient.CustomResource/Pages/Model/AlarmHelper.cs @@ -12,6 +12,7 @@ using System.Windows; namespace BPASmartClient.CustomResource.Pages.Model { + public class AlarmHelper where AlarmT : class, new() { public static ObservableCollection Alarms { get; set; } = new ObservableCollection(); @@ -41,7 +42,7 @@ namespace BPASmartClient.CustomResource.Pages.Model } } Thread.Sleep(100); - }), $"{typeof(AlarmT)},报警通用模块监听"); + }), $"{typeof(AlarmT).Name},报警通用模块监听"); } @@ -82,7 +83,7 @@ namespace BPASmartClient.CustomResource.Pages.Model Value = value.ToString(), Time = DateTime.Now.ToString("HH:mm:ss"), }; - + var res = Sqlite.GetInstance.Base.Add(tempAlarm); Sqlite.GetInstance.Save(); diff --git a/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs b/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs index 3c19179c..ebe66068 100644 --- a/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs +++ b/BPASmartClient.CustomResource/Pages/Model/AlarmInfo.cs @@ -10,9 +10,9 @@ namespace BPASmartClient.CustomResource.Pages.Model { public AlarmInfo() { - } - + + #region 180项目报警信息 /// /// 1 号滚筒线故障 /// @@ -53,7 +53,84 @@ namespace BPASmartClient.CustomResource.Pages.Model /// [Alarm("【5】号炒锅滚筒运行故障", AlarmTriggerType.Rising, AlarmLevel.严重报警)] public ushort FryPotFiveRollerTrouble { get; set; } + #region 滚筒是否运行状态监测 + /// + /// 1号滚筒线滚筒未运行 + /// + [Alarm("【1】号滚筒线未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort LineOneRollerRunning { get; set; } + /// + /// 2号滚筒线滚筒未运行 + /// + [Alarm("【2】号滚筒线未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort LineTwoRollerRunning { get; set; } + /// + /// 3号滚筒线滚筒未运行 + /// + [Alarm("【3】号滚筒线未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort LineThreeRollerRunning { get; set; } + /// + /// 1号炒锅进料滚筒未运行 + /// + [Alarm("【1】号炒锅进料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotOneRollerRunning { get; set; } + /// + /// 2号炒锅进料滚筒未运行 + /// + [Alarm("【2】号炒锅进料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotTwoRollerRunning { get; set; } + /// + /// 3号炒锅进料滚筒未运行 + /// + [Alarm("【3】号炒锅进料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotThreeRollerRunning { get; set; } + /// + /// 4号炒锅进料滚筒未运行 + /// + [Alarm("【4】号炒锅进料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotFourRollerRunning { get; set; } + /// + /// 5号炒锅进料滚筒未运行 + /// + [Alarm("【5】号炒锅进料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotFiveRollerRunning { get; set; } + /// + /// 1号炒锅空桶出料滚筒未运行 + /// + [Alarm("【1】号炒锅空桶出料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotOneEmptyRollerRunning { get; set; } - + /// + /// 2号炒锅空桶出料滚筒未运行 + /// + [Alarm("【2】号炒锅空桶出料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotTwoEmptyRollerRunning { get; set; } + /// + /// 3号炒锅空桶出料滚筒未运行 + /// + [Alarm("【3】号炒锅空桶出料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotThreeEmptyRollerRunning { get; set; } + /// + /// 4号炒锅空桶出料滚筒未运行 + /// + [Alarm("【4】号炒锅空桶出料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotFourEmptyRollerRunning { get; set; } + /// + /// 5号炒锅空桶出料滚筒未运行 + /// + [Alarm("【5】号炒锅空桶出料滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort FryPotFiveEmptyRollerRunning { get; set; } + /// + /// 洗桶工位进桶滚筒未运行 + /// + [Alarm("洗桶工位进桶滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort CleanEnterRollerRunning { get; set; } + /// + /// 洗桶工位出桶滚筒未运行 + /// + [Alarm("洗桶工位出桶滚筒未运行", AlarmTriggerType.Falling, AlarmLevel.一般报警)] + public ushort CleanOutputRollerRunning { get; set; } + #endregion + #endregion } } diff --git a/BPASmartClient.CustomResource/Pages/Model/Config.cs b/BPASmartClient.CustomResource/Pages/Model/Config.cs index dc0eb6ca..496f0942 100644 --- a/BPASmartClient.CustomResource/Pages/Model/Config.cs +++ b/BPASmartClient.CustomResource/Pages/Model/Config.cs @@ -38,7 +38,7 @@ namespace BPASmartClient.CustomResource.Pages.Model private void AddData() { - Global.userManager.userInfos.Add(new UserInfo() { permission = Permission.管理员, UserName = "admin", Password = "admin" }); + Global.userManager.userInfos.Add(new UserInfo() {Id = Guid.NewGuid().ToString(), permission = Permission.管理员, UserName = "admin", Password = "admin" }); SaveUser(); } diff --git a/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs b/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs index d7da48b9..019e2250 100644 --- a/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs +++ b/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs @@ -22,10 +22,10 @@ namespace BPASmartClient.CustomResource.Pages.Model private Permission _perimission; public string UserName { get { return _userName; } set { _userName = value; OnPropertyChanged(); } } - private string _userName = "admin"; + private string _userName ; public string Password { get { return _password; } set { _password = value; OnPropertyChanged(); } } - private string _password = "admin"; + private string _password; public string CardId { get; set; } = string.Empty; diff --git a/BPASmartClient.CustomResource/Pages/View/UserLogView.xaml b/BPASmartClient.CustomResource/Pages/View/UserLogView.xaml index ac3ce937..502972ba 100644 --- a/BPASmartClient.CustomResource/Pages/View/UserLogView.xaml +++ b/BPASmartClient.CustomResource/Pages/View/UserLogView.xaml @@ -256,7 +256,7 @@ FontSize="16" Foreground="{StaticResource TitleFontColor}" Text="日期" /> - + + + + + diff --git a/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml index a3e55d72..3a2e5bfc 100644 --- a/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml +++ b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml @@ -317,11 +317,84 @@ + + + + + + + + + + + + - + + + + + + + + + @@ -418,7 +491,7 @@ - + diff --git a/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs index 13a7bff7..c93bab3a 100644 --- a/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs +++ b/BPASmartClient.CustomResource/Pages/View/UserManageView.xaml.cs @@ -25,6 +25,7 @@ namespace BPASmartClient.CustomResource.Pages.View public UserManageView() { InitializeComponent(); + //this.DataContext = UserManageViewModel.GetInstance; } private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) @@ -32,15 +33,22 @@ namespace BPASmartClient.CustomResource.Pages.View ComboBox cbo = sender as ComboBox; var id = cbo.Tag; var per = cbo.SelectedItem; - if (id == null) + if (id != null) { - var a = UserManageViewModel.GetInstance.usersInfo.FirstOrDefault(p => p.Id == id); + var a = UserManageViewModel.usersInfo.FirstOrDefault(p => p.Id == id.ToString()); if (a != null && per != null) { a.permission = (Permission)Enum.Parse(typeof(Permission), per.ToString()); } } + //else + //{ + // if (UserManageViewModel.usersInfo.Last().permission.ToString() == null) + // UserManageViewModel.usersInfo.Last().permission = (Permission)Enum.Parse(typeof(Permission), per.ToString()); + //} } + + } } diff --git a/BPASmartClient.CustomResource/Pages/View/VariableConfigView.xaml b/BPASmartClient.CustomResource/Pages/View/VariableConfigView.xaml index 5247d35a..9c64bfe2 100644 --- a/BPASmartClient.CustomResource/Pages/View/VariableConfigView.xaml +++ b/BPASmartClient.CustomResource/Pages/View/VariableConfigView.xaml @@ -374,13 +374,15 @@ + VerticalContentAlignment="Center" + SelectionChanged="ComboBox_SelectionChanged" FontSize="20" Foreground="#FF2AB2E7" Width="130" Height="40" Margin="0,0,10,0"> + LoadingRow="DataGrid_LoadingRow" + CanUserDeleteRows="True" ColumnHeaderStyle="{StaticResource ColumHeaderStyle}" RowStyle="{StaticResource rowStyle}" CellStyle="{StaticResource cellStyle}"> diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/AlarmViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/AlarmViewModel.cs index 3476f95f..262d27e5 100644 --- a/BPASmartClient.CustomResource/Pages/ViewModel/AlarmViewModel.cs +++ b/BPASmartClient.CustomResource/Pages/ViewModel/AlarmViewModel.cs @@ -130,7 +130,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel private DateTime _mEndDateTime = DateTime.Now; - public ObservableCollection AlarmInfos { get; set; } + public ObservableCollection AlarmInfos { get; set; } public ObservableCollection HistoryAlarm { get; set; } = new ObservableCollection(); } diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs index c1ad1d9f..7d36078e 100644 --- a/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs +++ b/BPASmartClient.CustomResource/Pages/ViewModel/UserManageViewModel.cs @@ -17,14 +17,18 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel { internal class UserManageViewModel:ObservableObject { - private static UserManageViewModel _instance; - public static UserManageViewModel GetInstance => _instance ??= new UserManageViewModel(); - public ObservableCollection usersInfo { get; set; } = new ObservableCollection(); + //private static UserManageViewModel _instance; + //public static UserManageViewModel GetInstance => _instance ??= new UserManageViewModel(); + public static ObservableCollection usersInfo { get; set; } = new ObservableCollection(); //public List Authorities { get; set; } = new List() { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }; public List Authorities { get; set; } = new List(); public RelayCommand SaveCommand { get; set; } public RelayCommand DeleteCommand { get; set; } + + public RelayCommand AddUserInfoCommand { get; set; } + + public RelayCommand SaveDataCommand { get; set; } public UserManageViewModel() { var userManager = JsonConvert.DeserializeObject(File.ReadAllText("up.hbl").AESDecrypt()); @@ -52,7 +56,10 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } - + } + else + { + MessageBox.Show("用户名为空或输入后未回车确认", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } }); DeleteCommand = new RelayCommand((str) => @@ -73,6 +80,27 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel MessageBox.Show("未找到对应记录", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } } + else + { + usersInfo.Remove(usersInfo.Last()); + Global.userManager.userInfos = usersInfo; + File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); + } + }); + + + AddUserInfoCommand = new RelayCommand( ()=> + { + usersInfo.Add(new UserInfo() { Id=IdProcess()}); + + + }); + SaveDataCommand = new RelayCommand(() => + { + Global.userManager.userInfos = usersInfo; + File.WriteAllText("up.hbl", JsonConvert.SerializeObject(Global.userManager).AESEncrypt()); + MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + }); } diff --git a/BPASmartClient.CustomResource/UserControls/Cylinder.xaml b/BPASmartClient.CustomResource/UserControls/Cylinder.xaml index 97f5d6f8..3d4b4f27 100644 --- a/BPASmartClient.CustomResource/UserControls/Cylinder.xaml +++ b/BPASmartClient.CustomResource/UserControls/Cylinder.xaml @@ -13,14 +13,75 @@ + + + + + + + + + + Width="389" + Height="100"> - - + + + + + + diff --git a/BPASmartClient.CustomResource/UserControls/Cylinder.xaml.cs b/BPASmartClient.CustomResource/UserControls/Cylinder.xaml.cs index b115ba13..9969addd 100644 --- a/BPASmartClient.CustomResource/UserControls/Cylinder.xaml.cs +++ b/BPASmartClient.CustomResource/UserControls/Cylinder.xaml.cs @@ -26,6 +26,38 @@ namespace BPASmartClient.CustomResource.UserControls } + private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as Cylinder)?.Refresh(); + } + + private void Refresh() + { + this.LeftTog.IsChecked = LeftTogIsChecked; + this.RightTog.IsChecked = RightTogIsChecked; + } + + + public bool LeftTogIsChecked + { + get { return (bool)GetValue(LeftTogIsCheckedProperty); } + set { SetValue(LeftTogIsCheckedProperty, value); } + } + public static readonly DependencyProperty LeftTogIsCheckedProperty = + DependencyProperty.Register("LeftTogIsChecked", typeof(bool), typeof(Cylinder), + new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged))); + + + public bool RightTogIsChecked + { + get { return (bool)GetValue(RightTogIsCheckedProperty); } + set { SetValue(RightTogIsCheckedProperty, value); } + } + public static readonly DependencyProperty RightTogIsCheckedProperty = + DependencyProperty.Register("RightTogIsChecked", typeof(bool), typeof(Cylinder), + new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged))); + + } } diff --git a/BPASmartClient.CustomResource/UserControls/ImageBorder.xaml b/BPASmartClient.CustomResource/UserControls/ImageBorder.xaml new file mode 100644 index 00000000..fd8f6be4 --- /dev/null +++ b/BPASmartClient.CustomResource/UserControls/ImageBorder.xaml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.CustomResource/UserControls/ImageBorder.xaml.cs b/BPASmartClient.CustomResource/UserControls/ImageBorder.xaml.cs new file mode 100644 index 00000000..c392c2cd --- /dev/null +++ b/BPASmartClient.CustomResource/UserControls/ImageBorder.xaml.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.CustomResource.UserControls +{ + /// + /// ImageBorder.xaml 的交互逻辑 + /// + public partial class ImageBorder : UserControl + { + public ImageBorder() + { + InitializeComponent(); + this.SizeChanged += ImageBorder_SizeChanged; + } + + private void ImageBorder_SizeChanged(object sender, SizeChangedEventArgs e) + { + double min = Math.Min(this.Width, this.Height); + + PathGeometry geometry = new PathGeometry(); + PathFigure pathFigure = new PathFigure(); + pathFigure.StartPoint = new Point(15, 0); + pathFigure.Segments.Add(new LineSegment(new Point(0, 0), true)); + pathFigure.Segments.Add(new LineSegment(new Point(0, 15), true)); + geometry.Figures.Add(pathFigure); + this.leftTop.Data = geometry; + + geometry = new PathGeometry(); + pathFigure = new PathFigure(); + pathFigure.StartPoint = new Point(this.Width - 15, 0); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, 0), true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, 15), true)); + geometry.Figures.Add(pathFigure); + this.rightTop.Data = geometry; + + geometry = new PathGeometry(); + pathFigure = new PathFigure(); + pathFigure.StartPoint = new Point(0, this.Height - 15); + pathFigure.Segments.Add(new LineSegment(new Point(0, this.Height), true)); + pathFigure.Segments.Add(new LineSegment(new Point(15, this.Height), true)); + geometry.Figures.Add(pathFigure); + this.leftBottom.Data = geometry; + + geometry = new PathGeometry(); + pathFigure = new PathFigure(); + pathFigure.StartPoint = new Point(this.Width - 15, this.Height); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height), true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height - 15), true)); + geometry.Figures.Add(pathFigure); + this.rightBottom.Data = geometry; + + } + } +} diff --git a/BPASmartClient.DATABUS/BPASmartClient.DATABUS.csproj b/BPASmartClient.DATABUS/BPASmartClient.DATABUS.csproj new file mode 100644 index 00000000..132c02c5 --- /dev/null +++ b/BPASmartClient.DATABUS/BPASmartClient.DATABUS.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BPASmartClient.DATABUS/Class_DataBus.cs b/BPASmartClient.DATABUS/Class_DataBus.cs new file mode 100644 index 00000000..ade24c63 --- /dev/null +++ b/BPASmartClient.DATABUS/Class_DataBus.cs @@ -0,0 +1,34 @@ +using System.Collections.Concurrent; + +namespace BPASmartClient.DATABUS +{ + /// + /// 数据总线 + /// + public class Class_DataBus + { + #region 单例模式 + public static Class_DataBus dataBus = null; + + public static Class_DataBus GetInstance() + { + if (dataBus == null) + { + dataBus = new Class_DataBus(); + } + return dataBus; + } + #endregion + + #region 基础配置 + + #endregion + + #region 实时数据->大数据量 + /// + /// 设备数据 + /// + public ConcurrentDictionary Dic_DeviceData = new ConcurrentDictionary(); //原始目标链表 + #endregion + } +} \ No newline at end of file diff --git a/BPASmartClient.JXJFoodSmallStation/View/RecipeSettingsView.xaml b/BPASmartClient.JXJFoodSmallStation/View/RecipeSettingsView.xaml index bc474c0b..20d5eba9 100644 --- a/BPASmartClient.JXJFoodSmallStation/View/RecipeSettingsView.xaml +++ b/BPASmartClient.JXJFoodSmallStation/View/RecipeSettingsView.xaml @@ -90,7 +90,76 @@ - + + + + + + + + net6.0 + enable + enable + + + diff --git a/BPASmartClient.MessageName/DataName.cs b/BPASmartClient.MessageName/DataName.cs new file mode 100644 index 00000000..ba02420f --- /dev/null +++ b/BPASmartClient.MessageName/DataName.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MessageName +{ + /// + /// 数据订阅主题管理中心 + /// + public class DataName + { + #region XX数据 + /// + /// xxx消息 + /// + [Category("测试"), Description("消息备注"), Browsable(true)] + public static string xxx = "xxx"; + /// + /// xxx消息 + /// + [Category("测试"), Description("消息备注1"), Browsable(true)] + public static string 测试 = "测试"; + #endregion + + } +} diff --git a/BPASmartClient.MessageName/MessageName.cs b/BPASmartClient.MessageName/MessageName.cs new file mode 100644 index 00000000..a84404a7 --- /dev/null +++ b/BPASmartClient.MessageName/MessageName.cs @@ -0,0 +1,51 @@ +using System.ComponentModel; + +namespace BPASmartClient.MessageName +{ + /// + /// 消息名称管理中心 + /// 特性:Category,消息分组 + /// Description,消息备注 + /// Browsable,是否使用 + /// 消息发送案例: + /// Class_InnerMessageBus.GetInstance().PostMessage(this, MessageName.xxx, "12321"); + /// 接收数据案例: + /// Class_InnerMessageBus.GetInstance().ListenMessage(this, MessageName.xxx, "xxnameHandler"); + /// public void xxnameHandler(object sender, InnerMessageEventArgs e) { } + /// + public class MessageName + { + #region XX消息 + /// + /// xxx消息 + /// + [Category("消息分组"),Description("消息备注"),Browsable(true)] + public static string xxx = "xxx"; + #endregion + + + #region 滚动线消息事件管理中心 + /// + /// 滚动线控制滚动消息 + /// + [Category("滚动线"), Description("滚动线控制滚动"), Browsable(true)] + public static string ConveyorBeltIsRun = "ConveyorBeltIsRun"; + /// + /// 滚动线控制左转 + /// + [Category("滚动线"), Description("滚动线控制左转"), Browsable(true)] + public static string ConveyorBeltLeft = "ConveyorBeltLeft"; + /// + /// 滚动线控制右转 + /// + [Category("滚动线"), Description("滚动线控制右转"), Browsable(true)] + public static string ConveyorBeltRight = "ConveyorBeltRight"; + /// + /// 滚动线控制停止 + /// + [Category("滚动线"), Description("滚动线控制停止"), Browsable(true)] + public static string ConveyorBeltStop = "ConveyorBeltStop"; + #endregion + + } +} \ No newline at end of file diff --git a/BPASmartClient.Modbus/ModbusTcp.cs b/BPASmartClient.Modbus/ModbusTcp.cs index b17e4d9f..5864e493 100644 --- a/BPASmartClient.Modbus/ModbusTcp.cs +++ b/BPASmartClient.Modbus/ModbusTcp.cs @@ -250,79 +250,7 @@ namespace BPASmartClient.Modbus return default(object); } - #region 180项目调用 - public int GetAddress(string address, string target) - { - if (address == null) return -1; - if (address.Length > 0) - { - if (address.ToUpper().Contains("D") && address.Length == 5) - { - try - { - string head = "4" + (Convert.ToInt32(address.Substring(1, 1)) - 1).ToString(); - string tail = address.Substring(2, 3); - address = head + tail; - return Convert.ToInt32(address); - } - catch (Exception) - { - //打印日志 - - } - } - - } - return -1; - } - public object Read(string address, ushort len, string target, byte slaveAddress = 1) - { - if (address == null || tcpClient == null) return default(object); - ushort startAddress = (ushort)GetAddress(address, target); - CommandType commandType = CommandType.HoldingRegisters; - try - { - if (address.ToUpper().Contains("D")) - { - commandType = CommandType.HoldingRegisters; - return master.ReadHoldingRegisters(slaveAddress, startAddress, len); - } - - } - catch (Exception ex) - { - MessageLog.GetInstance.ShowEx($"读取地址:【{address}:= {startAddress}】,读取类型:【{commandType.ToString()}】出错,{ex.ToString()}"); - ExceptionHandling(ex); - } - return default(object); - } - - public void Write(string address, T value, string target, byte slaveAddress = 1) - { - if (address == null || tcpClient == null) return; - ushort startAddress = (ushort)GetAddress(address, target); - CommandType commandType = CommandType.Coils; - try - { - - if (address.ToUpper().Contains("D")) - { - commandType = CommandType.HoldingRegisters; - if (value is ushort ushortValue) - { - master.WriteSingleRegister(slaveAddress, startAddress, ushortValue); - } - - } - - } - catch (Exception ex) - { - MessageLog.GetInstance.ShowEx($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}"); - ExceptionHandling(ex); - } - } - #endregion + public void Write(string address, T value, byte slaveAddress = 1) diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 269d342c..297fb690 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -229,7 +229,6 @@ namespace BPASmartClient.MorkF } public void TakePot(object obj) { - WriteData("M14.0", true); } @@ -320,7 +319,7 @@ namespace BPASmartClient.MorkF /// private void InitialData() { - //队列 + //单个订单 string subId = Guid.NewGuid().ToString(); morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = new List() { 1 } });//A料 morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = new List() { 2 } });//B料 @@ -328,6 +327,21 @@ namespace BPASmartClient.MorkF morkF.TakePlateQueue.Enqueue(new OrderLocInfo() { SuborderId = subId }); resultorder.AddRange(new int[] { 1, 2, 3 }); morkF.listStirBom.Add(stirFryBom); + + //多个订单 + //string subId = Guid.NewGuid().ToString(); + //morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = new List() { 1 } });//A料 + //morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = new List() { 2 } });//B料 + //morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId, MaterialLoc = new List() { 3 } });//C料 + //morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId+1, MaterialLoc = new List() { 1 } });//A料 + //morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId+1, MaterialLoc = new List() { 2 } });//B料 + //morkF.TakeMaterialQueue.Enqueue(new OrderLocInfo() { SuborderId = subId+1, MaterialLoc = new List() { 3 } });//C料 + //morkF.TakePlateQueue.Enqueue(new OrderLocInfo() { SuborderId = subId }); + //morkF.TakePlateQueue.Enqueue(new OrderLocInfo() { SuborderId = subId+1 }); + //resultorder.AddRange(new int[] { 1, 2, 3 }); + //resultorder.AddRange(new int[] { 1, 2, 3 }); + //morkF.listStirBom.Add(stirFryBom); + //morkF.listStirBom.Add(stirFryBom); } #endregion @@ -466,7 +480,7 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show($"倒菜"); break; case StirFryRobotAction.灶取锅: - MessageLog.GetInstance.Show($"灶取锅"); + MessageLog.GetInstance.Show($"灶取锅"); break; } } @@ -525,7 +539,11 @@ namespace BPASmartClient.MorkF } }); } - + /// + /// 订单状态发布 + /// + /// + /// private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS) { EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid }); @@ -596,7 +614,7 @@ namespace BPASmartClient.MorkF morkF.MinorProcessExcuteLock = true; Task.Run(() => { - if (morkF.MinorProcessFlag && !morkF.RoobotIdle && morkF.TakeMaterialQueue.Count > 0) + if (morkF.MinorProcessFlag && !morkF.RoobotIdle && morkF.TakeMaterialQueue.Count > 0 && morkF.listStirBom.Count > 0 ) { morkF.MinorProessStatus = true; morkF.MainProcessStatus = false; @@ -625,8 +643,8 @@ namespace BPASmartClient.MorkF TakeBurdenCTask();//执行取C料操作 break; case StirFryRobotAction.灶取锅: - OutDishTask();//执行出餐操作 - CleanPotTask();//洗锅操作 + MinorProcessOutDishTask();//执行出餐操作 + MinorProcessCleanPotTask();//洗锅操作 break; } @@ -643,42 +661,42 @@ namespace BPASmartClient.MorkF case StirFryPotAction.NONE: break; case StirFryPotAction.大火t1s: - KitchenAdjustGears(3); - Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作 + MinorProcessKitchenAdjustGears(3); + // Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作 break; case StirFryPotAction.加油: AddOil();//注油//执行加油操作 break; case StirFryPotAction.中火t2s: - KitchenAdjustGears(2); + MinorProcessKitchenAdjustGears(2); Task.Delay(2000).Wait();//执行操作 break; case StirFryPotAction.小火持续: - KitchenAdjustGears(1); + MinorProcessKitchenAdjustGears(1); break; case StirFryPotAction.中火持续: - KitchenAdjustGears(5); + MinorProcessKitchenAdjustGears(5); break; case StirFryPotAction.大火持续: - KitchenAdjustGears(7); + MinorProcessKitchenAdjustGears(7); break; case StirFryPotAction.停止火力: - KitchenAdjustGears(0);//关闭灶加热 + MinorProcessKitchenAdjustGears(0);//关闭灶加热 break; case StirFryPotAction.搅拌臂上位: - TurnUpStatusDetect();//执行搅拌臂上位操作 + MinorProcessTurnUpStatusDetect();//执行搅拌臂上位操作 break; case StirFryPotAction.搅拌臂下位: - TurnDownStatusDetect();//执行搅拌臂下位操作 + MinorProcessTurnDownStatusDetect();//执行搅拌臂下位操作 break; case StirFryPotAction.低速旋转: - TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作 + MinorProcessTurnMachineGearsControl(1);//执行搅拌臂速度1挡操作 break; case StirFryPotAction.快速旋转: - TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作 + MinorProcessTurnMachineGearsControl(2);//执行搅拌臂速度3挡操作 break; case StirFryPotAction.停止旋转: - TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作 + MinorProcessTurnMachineGearsControl(0);//执行搅拌臂速度0挡操作 break; } } @@ -687,21 +705,20 @@ namespace BPASmartClient.MorkF Task.Delay(res.During * 1000).Wait();//当前流程延迟 if (morkF.MainProcessWait) { - if (morkF.MinorHasTakeMaterial) + if (morkF.MainHasTakeMaterial) { } else { - KitchenAdjustGears(0);//关闭灶加热 - morkF.MinorProessStatus = false; - morkF.MainProcessStatus = true; + MinorProcessKitchenAdjustGears(0);//关闭灶加热 //阻塞辅流程 minorReset.WaitOne(); + //morkF.MinorProessStatus = true; + //morkF.MainProcessStatus = false; } } - morkF.MinorProessStatus = true; - morkF.MainProcessStatus = false; + } morkF.MinorOutMealComplete = true; } @@ -721,7 +738,7 @@ namespace BPASmartClient.MorkF morkF.MainProcessExcuteLock = true; Task.Run(new Action(() => { - if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.MainProcessFlag) + if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.MainProcessFlag&& morkF.listStirBom.Count > 0) { morkF.MainProcessStatus = true; morkF.MinorProessStatus = false; @@ -750,8 +767,8 @@ namespace BPASmartClient.MorkF TakeBurdenCTask();//执行取C料操作 break; case StirFryRobotAction.灶取锅: - OutDishTask();//执行出餐操作 - CleanPotTask();//洗锅操作 + MainProcessOutDishTask();//执行出餐操作 + MainProcessCleanPotTask();//洗锅操作 break; } @@ -768,67 +785,65 @@ namespace BPASmartClient.MorkF case StirFryPotAction.NONE: break; case StirFryPotAction.大火t1s: - KitchenAdjustGears(3); - Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作 + MainProcessKitchenAdjustGears(3); + // Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作 break; case StirFryPotAction.加油: AddOil();//注油//执行加油操作 break; case StirFryPotAction.中火t2s: - KitchenAdjustGears(2); + MainProcessKitchenAdjustGears(2); Task.Delay(2000).Wait();//执行操作 break; case StirFryPotAction.小火持续: - KitchenAdjustGears(1); + MainProcessKitchenAdjustGears(1); break; case StirFryPotAction.中火持续: - KitchenAdjustGears(5); + MainProcessKitchenAdjustGears(5); break; case StirFryPotAction.大火持续: - KitchenAdjustGears(7); + MainProcessKitchenAdjustGears(7); break; case StirFryPotAction.停止火力: - KitchenAdjustGears(0);//关闭灶加热 + MainProcessKitchenAdjustGears(0);//关闭灶加热 break; case StirFryPotAction.搅拌臂上位: - TurnUpStatusDetect();//执行搅拌臂上位操作 + MainProcessTurnUpStatusDetect();//执行搅拌臂上位操作 break; case StirFryPotAction.搅拌臂下位: - TurnDownStatusDetect();//执行搅拌臂下位操作 + MainProcessTurnDownStatusDetect();//执行搅拌臂下位操作 break; case StirFryPotAction.低速旋转: - TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作 + MainProcessTurnMachineGearsControl(1);//执行搅拌臂速度1挡操作 break; case StirFryPotAction.快速旋转: - TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作 + MainProcessTurnMachineGearsControl(2);//执行搅拌臂速度3挡操作 break; case StirFryPotAction.停止旋转: - TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作 + MainProcessTurnMachineGearsControl(0);//执行搅拌臂速度0挡操作 break; } } })); - Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束 Task.Delay(res.During * 1000).Wait();//当前流程延迟 - if (morkF.MinorProcessWait) - { - if (morkF.MainHasTakeMaterial)//针对主流程准备出餐但辅流程机器人忙碌情况下,辅流程不阻塞 - { - } - else - { - KitchenAdjustGears(0);//关闭灶加热 - morkF.MinorProessStatus = true; - morkF.MainProcessStatus = false; - //阻塞主流程 - mainReset.WaitOne(); - } - - } - morkF.MinorProessStatus = false; - morkF.MainProcessStatus = true; - + #region 两口锅逻辑 + //if (morkF.MinorProcessWait) + //{ + // if (morkF.MinorHasTakeMaterial)//针对主流程准备出餐但辅流程机器人忙碌情况下,辅流程不阻塞 + // { + // } + // else + // { + // MainProcessKitchenAdjustGears(0);//关闭灶加热 + // //阻塞主流程 + // mainReset.WaitOne(); + // //morkF.MinorProessStatus = false; + // //morkF.MainProcessStatus = true; + // } + + //} + #endregion } morkF.MainOutMealComplete = true; } @@ -845,31 +860,39 @@ namespace BPASmartClient.MorkF /// private void SingleProcess() { - + //主流程出餐完成,相应变量复位 if (morkF.MainOutMealComplete) { + morkF.MainOutMealComplete = false; morkF.TakePlateLock = false; morkF.MainProcessExcuteLock = false; morkF.MainOrderMaterialCom = false; - morkF.MinorProcessWait = false;//主流程出餐完成取消辅流程线程阻塞 - if (morkF.MainProcessPotLoc == 1) - { - morkF.PotInPlace = false; - } - else if (morkF.MainProcessPotLoc == 2) - { - morkF.SecondPotInPlace = false; - } + morkF.MainProcessWait = false;//主流程出餐完成取消辅流程线程阻塞 + + #region 单口锅逻辑 + morkF.PotInPlace = false; + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessPotLoc == 1) + //{ + // morkF.PotInPlace = false; + //} + //else if (morkF.MainProcessPotLoc == 2) + //{ + // morkF.SecondPotInPlace = false; + //} + #endregion } //辅流程出餐完成,相应变量复位 if (morkF.MinorOutMealComplete) { + morkF.MinorOutMealComplete = false; morkF.TakePlateLock = false; morkF.MinorProcessExcuteLock = false; morkF.MinorOrderMaterialCom = false; - morkF.MainProcessWait = false;//辅流程出餐完成取消主流程线程阻塞 + morkF.MinorProcessWait = false;//辅流程出餐完成取消主流程线程阻塞 if (morkF.MinorProcessPotLoc == 1) { morkF.PotInPlace = false; @@ -902,7 +925,7 @@ namespace BPASmartClient.MorkF } else { - DeviceProcessLogShow("未找到可用的物料信息"); + DeviceProcessLogShow("当前订单未找到可用的物料信息"); } } @@ -920,7 +943,7 @@ namespace BPASmartClient.MorkF } else { - DeviceProcessLogShow("未找到可用的物料信息"); + DeviceProcessLogShow("当前订单未找到可用的物料信息"); } } @@ -941,14 +964,19 @@ namespace BPASmartClient.MorkF if (morkF.TakePlateQueue.TryDequeue(out OrderLocInfo order)) { StartTakePlate(); - if (morkF.MainProcessStatus) - morkF.MainCurrentOrderId = order.SuborderId; - if (morkF.MinorProessStatus) - morkF.MinorCurrentOrderId = order.SuborderId; + #region 两口锅逻辑 + //if (morkF.MainProcessStatus) + // morkF.MainCurrentOrderId = order.SuborderId; + + //if (morkF.MinorProessStatus) + // morkF.MinorCurrentOrderId = order.SuborderId; + #endregion + #region 单口锅逻辑 + morkF.CurrentOrderId = order.SuborderId; + #endregion morkF.TakePlateLock = true; //订单完成后置false - morkF.MainOutMealComplete = false; - morkF.MinorOutMealComplete = false; - // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING); + + DeviceProcessLogShow($"订单【{order.SuborderId}】执行取碗控制"); } } @@ -960,75 +988,95 @@ namespace BPASmartClient.MorkF /// private void TakePotTask() { - //while (!((!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) || (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete))) - //{ - // Task.Delay(5).Wait(); - //} - while (!(!morkF.CleanModule || !morkF.SecondCleanModule) && (!morkF.KitchenOneStatus || !morkF.KitchenSecondStatus) && (morkF.CleanComplete || morkF.SecondCleanComplete))//等待取锅条件满足 + + while (morkF.CleanModule || morkF.KitchenOneStatus || !morkF.CleanComplete || morkF.RoobotIdle)//等待取锅条件满足 { Task.Delay(5).Wait(); } - while (morkF.RoobotIdle)//等待机器人空闲 + + #region 单口锅逻辑 + //if (!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) + //{ + //取1号锅到1号灶台 + TakePotToKitchen(1); + WriteData("M1.5", false);//清洗模组1完成复位 + DeviceProcessLogShow($"订单【{morkF.CurrentOrderId}】执行取锅到灶台控制"); + while (!morkF.PutPotToKitchenComlete) { Task.Delay(5).Wait(); } - if (!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) - { - //取1号锅到1号灶台 - TakePotToKitchen(1); - morkF.CurrentPutPotLoc = 1; - WriteData("M1.5", false);//清洗模组1完成复位 - } - else if (!morkF.SecondCleanModule && !morkF.KitchenOneStatus && morkF.SecondCleanComplete) - { - //取2号锅到1号灶台 - TakePotToKitchen(1); - morkF.CurrentPutPotLoc = 1; - WriteData("M2.0", false);//清洗模组2完成复位 - } - if (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete) - { - //取2号锅到2号灶台 - TakePotToKitchen(2); - morkF.CurrentPutPotLoc = 2; - WriteData("M2.0", false);//清洗模组2完成复位 - } - else if (!morkF.CleanModule && !morkF.KitchenSecondStatus && morkF.CleanComplete) - { - //取1号锅到2号灶台 - TakePotToKitchen(2); - morkF.CurrentPutPotLoc = 2; - WriteData("M2.0", false);//清洗模组1完成复位 - } - if (morkF.MainProcessStatus) - { - morkF.MainProcessPotLoc = morkF.CurrentPutPotLoc; - DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行取锅到灶台控制"); - } - if (morkF.MinorProessStatus) - { - morkF.MinorProcessPotLoc = morkF.CurrentPutPotLoc; - DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); - } - if (morkF.CurrentPutPotLoc == 1) - { - while (!morkF.PutPotToKitchenComlete) - { - Task.Delay(5).Wait(); - } - morkF.PotInPlace = morkF.PutPotToKitchenComlete;//锅到位 - WriteData("M14.0", false);//机器人取锅完成复位 - } - if (morkF.CurrentPutPotLoc == 2) - { - while (!morkF.PutPotToSecondKitchenComlete) - { - Task.Delay(5).Wait(); - } - morkF.SecondPotInPlace = morkF.PutPotToSecondKitchenComlete; - WriteData("M14.4", false);//机器人取锅完成复位 - } + morkF.PotInPlace = true;//锅到位 + WriteData("M14.0", false);//机器人取锅完成复位 + //} + #endregion + #region 两口锅逻辑 + //while (!((!morkF.CleanModule || !morkF.SecondCleanModule) && (!morkF.KitchenOneStatus || !morkF.KitchenSecondStatus) && (morkF.CleanComplete || morkF.SecondCleanComplete)))//等待取锅条件满足 + //{ + // Task.Delay(5).Wait(); + //} + //while (morkF.RoobotIdle)//等待机器人空闲 + //{ + // Task.Delay(5).Wait(); + //} + //if (!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) + //{ + // //取1号锅到1号灶台 + // TakePotToKitchen(1); + // morkF.CurrentPutPotLoc = 1; + // WriteData("M1.5", false);//清洗模组1完成复位 + // DeviceProcessLogShow($"订单【{morkF.CurrentOrderId}】执行取锅到灶台控制"); + //} + //else if (!morkF.SecondCleanModule && !morkF.KitchenOneStatus && morkF.SecondCleanComplete) + //{ + // //取2号锅到1号灶台 + // TakePotToKitchen(1); + // morkF.CurrentPutPotLoc = 1; + // WriteData("M2.0", false);//清洗模组2完成复位 + //} + //if (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete) + //{ + // //取2号锅到2号灶台 + // TakePotToKitchen(2); + // morkF.CurrentPutPotLoc = 2; + // WriteData("M2.0", false);//清洗模组2完成复位 + //} + //else if (!morkF.CleanModule && !morkF.KitchenSecondStatus && morkF.CleanComplete) + //{ + // //取1号锅到2号灶台 + // TakePotToKitchen(2); + // morkF.CurrentPutPotLoc = 2; + // WriteData("M2.0", false);//清洗模组1完成复位 + //} + //if (morkF.MainProcessStatus) + //{ + // morkF.MainProcessPotLoc = morkF.CurrentPutPotLoc; + // DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行取锅到灶台控制"); + //} + //if (morkF.MinorProessStatus) + //{ + // morkF.MinorProcessPotLoc = morkF.CurrentPutPotLoc; + // DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); + //} + //if (morkF.CurrentPutPotLoc == 1) + //{ + // while (!morkF.PutPotToKitchenComlete) + // { + // Task.Delay(5).Wait(); + // } + // morkF.PotInPlace = true;//锅到位 + // WriteData("M14.0", false);//机器人取锅完成复位 + //} + //if (morkF.CurrentPutPotLoc == 2) + //{ + // while (!morkF.PutPotToSecondKitchenComlete) + // { + // Task.Delay(5).Wait(); + // } + // morkF.SecondPotInPlace = true; + // WriteData("M14.4", false);//机器人取锅完成复位 + //} + #endregion Thread.Sleep(2000); @@ -1079,76 +1127,94 @@ namespace BPASmartClient.MorkF private void TakeBurdenATask() { int loc = 0; - //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位 - //{ - // Task.Delay(5).Wait(); - //} - if (morkF.MainProcessStatus) + #region 单口锅逻辑 + while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 { - if (morkF.MainProcessPotLoc == 1) - { - while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 - { - Task.Delay(5).Wait(); - } - } - else - { - while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 - { - Task.Delay(5).Wait(); - } - } - if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) - { - loc = order.MaterialLoc[0]; - TakeBurden(); - TurnReset(loc);//转台复位 - - DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); - } - //等待取料完成 - while (!morkF.TakeMaterialComplete) - { - Task.Delay(5).Wait(); - } - morkF.MainOrderMaterialCom = false; - morkF.MainHasTakeMaterial = true; - WriteData("M14.1", false);//机器人取料完成复位 + Task.Delay(5).Wait(); } - if (morkF.MinorProessStatus) + if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) { - if (morkF.MinorProcessPotLoc == 1) - { - while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 - { - Task.Delay(5).Wait(); - } - } - else - { - while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 - { - Task.Delay(5).Wait(); - } - } - if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) - { - loc = order.MaterialLoc[0]; - TakeBurden(); - TurnReset(loc);//转台复位 + loc = order.MaterialLoc[0]; + TakeBurden(); + TurnReset(loc);//转台复位 - DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); - } - //等待取料完成 - while (!morkF.TakeMaterialComplete) - { - Task.Delay(5).Wait(); - } - morkF.MinorOrderMaterialCom = false; - morkF.MinorHasTakeMaterial = true; - WriteData("M14.5", false);//机器人取料完成复位 + DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); + } + //等待取料完成 + while (!morkF.TakeMaterialComplete) + { + Task.Delay(5).Wait(); } + WriteData("M14.1", false);//机器人取料完成复位 + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessStatus) + //{ + // if (morkF.MainProcessPotLoc == 1) + // { + // while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // else + // { + // while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) + // { + // loc = order.MaterialLoc[0]; + // TakeBurden(); + // TurnReset(loc);//转台复位 + + // DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); + // } + // //等待取料完成 + // while (!morkF.TakeMaterialComplete) + // { + // Task.Delay(5).Wait(); + // } + // morkF.MainOrderMaterialCom = false; + // morkF.MainHasTakeMaterial = true; + // WriteData("M14.1", false);//机器人取料完成复位 + //} + //if (morkF.MinorProessStatus) + //{ + // if (morkF.MinorProcessPotLoc == 1) + // { + // while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // else + // { + // while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) + // { + // loc = order.MaterialLoc[0]; + // TakeBurden(); + // TurnReset(loc);//转台复位 + + // DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); + // } + // //等待取料完成 + // while (!morkF.TakeMaterialComplete) + // { + // Task.Delay(5).Wait(); + // } + // morkF.MinorOrderMaterialCom = false; + // morkF.MinorHasTakeMaterial = true; + // WriteData("M14.5", false);//机器人取料完成复位 + //} + #endregion morkF.TurnTableLock = false;//转台互锁解除 @@ -1238,121 +1304,148 @@ namespace BPASmartClient.MorkF /// private void TakeBurdenCTask() { - #region 旧代码 - //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位 - //{ - // Task.Delay(5).Wait(); - //} - //if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) - //{ - // int loc = order.MaterialLoc; - // TakeBurden(loc); - // TurnReset(loc);//转台复位 - // DeviceProcessLogShow($"订单【{ order.SuborderId}】,执行取C料"); - //} - //DeviceProcessLogShow($"剩余配料数量{morkF.TakeMaterialQueue.Count}"); - ////等待取料完成 - //while (!morkF.TakeMaterialComplete) - //{ - // Task.Delay(5).Wait(); - //} - //morkF.MainOrderMaterialCom = false; + #region 单口锅逻辑 + int loc = 0; + while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 + { + Task.Delay(5).Wait(); + } + if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) + { + loc = order.MaterialLoc[0]; + TakeBurden(); + TurnReset(loc);//转台复位 + + DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); + } + //等待取料完成 + while (!morkF.TakeMaterialComplete) + { + Task.Delay(5).Wait(); + } + + WriteData("M14.1", false);//机器人取料完成复位 + morkF.TurnTableLock = false;//转台互锁解除 + #endregion + #region 两口锅逻辑 + //int loc = 0; + //if (morkF.MainProcessStatus) //{ + // if (morkF.MainProcessPotLoc == 1) + // { + // while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // else + // { + // while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) + // { + // loc = order.MaterialLoc[0]; + // TakeBurden(); + // TurnReset(loc);//转台复位 + + // DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); + // } + // //等待取料完成 + // while (!morkF.TakeMaterialComplete) + // { + // Task.Delay(5).Wait(); + // } // morkF.MainOrderMaterialCom = false; + // morkF.MainHasTakeMaterial = true; // WriteData("M14.1", false);//机器人取料完成复位 //} //if (morkF.MinorProessStatus) //{ + // if (morkF.MinorProcessPotLoc == 1) + // { + // while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // else + // { + // while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 + // { + // Task.Delay(5).Wait(); + // } + // } + // if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) + // { + // loc = order.MaterialLoc[0]; + // TakeBurden(); + // TurnReset(loc);//转台复位 + + // DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); + // } + // //等待取料完成 + // while (!morkF.TakeMaterialComplete) + // { + // Task.Delay(5).Wait(); + // } // morkF.MinorOrderMaterialCom = false; + // morkF.MinorHasTakeMaterial = true; // WriteData("M14.5", false);//机器人取料完成复位 //} - //morkF.TurnTableLock = false;//转台互锁解除 + //morkF.TurnTableLock = false;//转台互锁解除 #endregion - int loc = 0; - //while (morkF.RoobotIdle || (!morkF.PotInPlace && !morkF.SecondPotInPlace) || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅到位 + } + /// + /// 主流程出餐 + /// + private void MainProcessOutDishTask() + { + //while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足 //{ // Task.Delay(5).Wait(); //} - if (morkF.MainProcessStatus) + #region 单口锅逻辑 + while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足 { - if (morkF.MainProcessPotLoc == 1) - { - while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 - { - Task.Delay(5).Wait(); - } - } - else - { - while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 - { - Task.Delay(5).Wait(); - } - } - if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) - { - loc = order.MaterialLoc[0]; - TakeBurden(); - TurnReset(loc);//转台复位 - - DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); - } - //等待取料完成 - while (!morkF.TakeMaterialComplete) - { - Task.Delay(5).Wait(); - } - morkF.MainOrderMaterialCom = false; - morkF.MainHasTakeMaterial = true; - WriteData("M14.1", false);//机器人取料完成复位 + Task.Delay(5).Wait(); } - if (morkF.MinorProessStatus) + if (morkF.TakePlateQueue.Count == 0) { - if (morkF.MinorProcessPotLoc == 1) - { - while (morkF.RoobotIdle || !morkF.PotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅1到位 - { - Task.Delay(5).Wait(); - } - } - else - { - while (morkF.RoobotIdle || !morkF.SecondPotInPlace || !morkF.MaterialArriveComplete)//等待机器人空闲以及锅2到位 - { - Task.Delay(5).Wait(); - } - } - if (morkF.TakeMaterialQueue.TryDequeue(out OrderLocInfo order)) - { - loc = order.MaterialLoc[0]; - TakeBurden(); - TurnReset(loc);//转台复位 - - DeviceProcessLogShow($"订单【{order.SuborderId}】,执行到转台{loc}位置取料"); - } - //等待取料完成 - while (!morkF.TakeMaterialComplete) - { - Task.Delay(5).Wait(); - } - morkF.MinorOrderMaterialCom = false; - morkF.MinorHasTakeMaterial = true; - WriteData("M14.5", false);//机器人取料完成复位 + WriteData("M0.7", false);//无订单关闭抽风机 } - morkF.TurnTableLock = false;//转台互锁解除 + MainProcessRobotOutMeal(); + WriteData("M1.2", false);//供盘复位 + DeviceProcessLogShow($"订单【{morkF.CurrentOrderId}】执行取锅到清洗台控制"); + #endregion + #region 两口锅逻辑 + //while (morkF.RoobotIdle || (morkF.CleanModule && morkF.SecondCleanModule) || !morkF.ProvidePlateComplete)//等待条件满足 + //{ + // Task.Delay(5).Wait(); + //} + //if (morkF.TakePlateQueue.Count == 0) + //{ + // WriteData("M0.7", false);//无订单关闭抽风机 + //} + //MainProcessRobotOutMeal(); + //WriteData("M1.2", false);//供盘复位 + //DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行取锅到清洗台控制"); + #endregion } /// - /// 出餐 + /// 复流程流程出餐 /// - private void OutDishTask() + private void MinorProcessOutDishTask() { //while (morkF.RoobotIdle || morkF.CleanModule || !morkF.ProvidePlateComplete)//等待条件满足 //{ // Task.Delay(5).Wait(); //} - while (morkF.RoobotIdle || (!morkF.CleanModule && !morkF.SecondCleanModule) || !morkF.ProvidePlateComplete)//等待条件满足 + while (morkF.RoobotIdle || (morkF.CleanModule && morkF.SecondCleanModule) || !morkF.ProvidePlateComplete)//等待条件满足 { Task.Delay(5).Wait(); } @@ -1360,57 +1453,70 @@ namespace BPASmartClient.MorkF { WriteData("M0.7", false);//无订单关闭抽风机 } - RobotOutMeal(); + MinorProcessRobotOutMeal(); WriteData("M1.2", false);//供盘复位 - if (morkF.MainProcessStatus) - DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行取锅到清洗台控制"); - if (morkF.MinorProessStatus) - DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行取锅到清洗台控制"); + DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行取锅到清洗台控制"); + } + /// + /// 主流程洗锅放锅 + /// + private void MainProcessCleanPotTask() + { + #region 单口锅逻辑 + while (!morkF.PlaceRinseTableComplete || morkF.CleanModule) + { + Task.Delay(5).Wait(); + } + WriteData("M14.2", false);//机器人出餐完成复位 + CleanModuleControl("Start", 1); + DeviceProcessLogShow($"订单【{morkF.CurrentOrderId}】执行清洗操作"); + #endregion + #region 两口锅逻辑 + //while ((!morkF.PlaceRinseTableComplete || morkF.CleanModule) && (!morkF.PlaceRinseSecondTableComplete || morkF.SecondCleanModule)) + //{ + // Task.Delay(5).Wait(); + //} + //WriteData("M14.2", false);//机器人出餐完成复位 + //if (morkF.PlaceRinseTableComplete && !morkF.CleanModule) + //{ + // CleanModuleControl("Start", 1); + //} + //if (morkF.PlaceRinseSecondTableComplete && !morkF.SecondCleanModule) + //{ + // CleanModuleControl("Start", 2); + //} + //DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行清洗操作"); + //morkF.MainProcessFlag = false; + //minorReset.Set(); + #endregion + //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK); } /// - /// 洗锅放锅 + /// 辅流程洗锅放锅 /// - private void CleanPotTask() + private void MinorProcessCleanPotTask() { while ((!morkF.PlaceRinseTableComplete || morkF.CleanModule) && (!morkF.PlaceRinseSecondTableComplete || morkF.SecondCleanModule)) { Task.Delay(5).Wait(); } - if (morkF.MainProcessStatus) + + WriteData("M14.6", false);//机器人出餐完成复位 + if (morkF.PlaceRinseTableComplete && !morkF.CleanModule) { - WriteData("M14.2", false);//机器人出餐完成复位 - if (morkF.PlaceRinseTableComplete && morkF.CleanModule) - { - CleanModuleControl("Start", 1); - } - if (morkF.PlaceRinseSecondTableComplete && morkF.SecondCleanModule) - { - CleanModuleControl("Start", 2); - } - DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行清洗操作"); - morkF.MainProcessFlag = false; - minorReset.Set(); + CleanModuleControl("Start", 1); } - if (morkF.MinorProessStatus) + if (morkF.PlaceRinseSecondTableComplete && !morkF.SecondCleanModule) { - WriteData("M14.6", false);//机器人出餐完成复位 - if (morkF.PlaceRinseTableComplete && morkF.CleanModule) - { - CleanModuleControl("Start", 1); - } - if (morkF.PlaceRinseSecondTableComplete && morkF.SecondCleanModule) - { - CleanModuleControl("Start", 2); - } - DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行清洗操作"); - morkF.MinorProcessFlag = false; - mainReset.Set(); + CleanModuleControl("Start", 2); } - //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK); - + DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行清洗操作"); + morkF.MinorProcessFlag = false; + mainReset.Set(); + //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK); } /// /// 任务复位重启 @@ -1439,11 +1545,37 @@ namespace BPASmartClient.MorkF // }), "ResetProgram"); //} /// - /// 翻转机下降及状态检测 + /// 主流程翻转机下降及状态检测 + /// + public void MainProcessTurnDownStatusDetect() + { + int potLoc = MainProcessTurnMachineOrientControl("Down"); + + if (potLoc == 1) + { + while (!morkF.TurnMachineDownComplete)//等待翻转机下降完成 + { + Task.Delay(5).Wait(); + } + WriteData("M8.3", false);//下降完成复位 + } + if (potLoc == 2) + { + while (!morkF.SecondTurnMachineDownComplete)//等待翻转机下降完成 + { + Task.Delay(5).Wait(); + } + WriteData("M8.7", false);//下降完成复位 + } + DeviceProcessLogShow($"翻转机下降完成"); + + } + /// + /// 辅流程翻转机下降及状态检测 /// - public void TurnDownStatusDetect() + public void MinorProcessTurnDownStatusDetect() { - int potLoc = TurnMachineOrientControl("Down"); + int potLoc = MinorProcessTurnMachineOrientControl("Down"); if (potLoc == 1) { @@ -1472,160 +1604,173 @@ namespace BPASmartClient.MorkF //} } - /// - /// 翻转机上升及状态检测 + /// 主流程翻转机上升及状态检测 /// - public void TurnUpStatusDetect() + public void MainProcessTurnUpStatusDetect() + { + //while (morkF.RoobotIdle)//机器人忙碌 + //{ + // Task.Delay(5).Wait(); + //} + MainProcessTurnMachineOrientControl("Top");//翻转机上升 + #region 单口锅逻辑 + while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成 + { + Task.Delay(5).Wait(); + } + WriteData("M8.1", false);//上升完成复位 + WriteData("M14.3", true);//倒料 + while (!morkF.FallMaterialComplete)//等待倒料完成 + { + Task.Delay(5).Wait(); + } + WriteData("M14.3", false);//倒料复位 + DeviceProcessLogShow($"订单【{morkF.CurrentOrderId}】,配料倒料完成"); + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessPotLoc == 1) + //{ + // while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成 + // { + // Task.Delay(5).Wait(); + // } + // WriteData("M8.1", false);//上升完成复位 + // if (!morkF.MainOrderMaterialCom) + // { + // WriteData("M14.3", true);//倒料 + // while (!morkF.FallMaterialComplete)//等待倒料完成 + // { + // Task.Delay(5).Wait(); + // } + // morkF.MaterialCount++; + // WriteData("M14.3", false);//倒料复位 + // if (morkF.MaterialCount == 3) + // { + // //允许执行下一个订单流程 + // morkF.MaterialCount = 0; + // morkF.MinorProcessFlag = true; + + // } + // morkF.MainOrderMaterialCom = true; + // morkF.MainHasTakeMaterial = false; + // DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】,配料倒料完成"); + // } + // else //辅程准备阻塞 + // { + // morkF.MainProcessWait = true; + // } + //} + //if (morkF.MainProcessPotLoc == 2) + //{ + // while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成 + // { + // Task.Delay(5).Wait(); + // } + // WriteData("M8.5", false);//上升完成复位 + // if (!morkF.MainOrderMaterialCom) + // { + // WriteData("M14.7", true);//倒料 + // while (!morkF.SecondFallMaterialComplete)//等待倒料完成 + // { + // Task.Delay(5).Wait(); + // } + // morkF.MaterialCount++; + // WriteData("M14.7", false);//倒料复位 + // if (morkF.MaterialCount == 3) + // { + // //允许执行下一个订单流程 + // morkF.MaterialCount = 0; + // morkF.MinorProcessFlag = true; + + // } + // morkF.MainOrderMaterialCom = true; + // morkF.MainHasTakeMaterial = false; + // DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】,配料倒料完成"); + // } + // else //辅流程准备阻塞 + // { + // morkF.MainProcessWait = true; + // } + //} + #endregion + DeviceProcessLogShow("翻转机上升完成"); + } + /// + /// 辅流程翻转机上升及状态检测 + /// + public void MinorProcessTurnUpStatusDetect() { while (morkF.RoobotIdle)//机器人忙碌 { Task.Delay(5).Wait(); } - TurnMachineOrientControl("Top");//翻转机上升 - if (morkF.MainProcessStatus) + MinorProcessTurnMachineOrientControl("Top");//翻转机上升 + + if (morkF.MinorProcessPotLoc == 1) { - if (morkF.MainProcessPotLoc == 1) + while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成 { - while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成 - { - Task.Delay(5).Wait(); - } - WriteData("M8.1", false);//上升完成复位 - if (!morkF.MainOrderMaterialCom) - { - WriteData("M14.3", true);//倒料 - while (!morkF.FallMaterialComplete)//等待倒料完成 - { - Task.Delay(5).Wait(); - } - morkF.MaterialCount++; - WriteData("M14.3", false);//倒料复位 - if (morkF.MaterialCount == 3) - { - //允许执行下一个订单流程 - morkF.MaterialCount = 0; - morkF.MinorProcessFlag = true; - - } - morkF.MainOrderMaterialCom = true; - morkF.MainHasTakeMaterial = false; - DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】,配料倒料完成"); - } - else //辅程准备阻塞 - { - morkF.MainProcessWait = true; - } + Task.Delay(5).Wait(); } - if (morkF.MainProcessPotLoc == 2) + WriteData("M8.1", false);//上升完成复位 + if (!morkF.MinorOrderMaterialCom) { - while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成 + WriteData("M14.3", true);//倒料 + while (!morkF.FallMaterialComplete)//等待倒料完成 { Task.Delay(5).Wait(); } - WriteData("M8.5", false);//上升完成复位 - if (!morkF.MainOrderMaterialCom) + morkF.MaterialCount++; + WriteData("M14.3", false);//倒料复位 + if (morkF.MaterialCount == 3) { - WriteData("M14.7", true);//倒料 - while (!morkF.SecondFallMaterialComplete)//等待倒料完成 - { - Task.Delay(5).Wait(); - } - morkF.MaterialCount++; - WriteData("M14.7", false);//倒料复位 - if (morkF.MaterialCount == 3) - { - //允许执行下一个订单流程 - morkF.MaterialCount = 0; - morkF.MinorProcessFlag = true; + //允许执行下一个订单流程 + morkF.MaterialCount = 0; + morkF.MainProcessFlag = true; - } - morkF.MainOrderMaterialCom = true; - morkF.MainHasTakeMaterial = false; - DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】,配料倒料完成"); - } - else //辅流程准备阻塞 - { - morkF.MainProcessWait = true; } + morkF.MinorOrderMaterialCom = true; + morkF.MinorHasTakeMaterial = false; + DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】,配料倒料完成"); + } + else //主程准备阻塞 + { + morkF.MinorProcessWait = true; } } - if (morkF.MinorProessStatus) + if (morkF.MinorProcessPotLoc == 2) { - if (morkF.MinorProcessPotLoc == 1) + while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成 { - while (!morkF.TurnMachineUpComplete)//等待翻转机上升完成以及取料完成 - { - Task.Delay(5).Wait(); - } - WriteData("M8.1", false);//上升完成复位 - if (!morkF.MinorOrderMaterialCom) - { - WriteData("M14.3", true);//倒料 - while (!morkF.FallMaterialComplete)//等待倒料完成 - { - Task.Delay(5).Wait(); - } - morkF.MaterialCount++; - WriteData("M14.3", false);//倒料复位 - if (morkF.MaterialCount == 3) - { - //允许执行下一个订单流程 - morkF.MaterialCount = 0; - morkF.MainProcessFlag = true; - - } - morkF.MinorOrderMaterialCom = true; - morkF.MinorHasTakeMaterial = false; - DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】,配料倒料完成"); - } - else //主程准备阻塞 - { - morkF.MinorProcessWait = true; - } + Task.Delay(5).Wait(); } - if (morkF.MinorProcessPotLoc == 2) + WriteData("M8.5", false);//上升完成复位 + if (!morkF.MinorOrderMaterialCom) { - while (!morkF.SecondTurnMachineUpComplete)//等待翻转机上升完成以及取料完成 + WriteData("M14.7", true);//倒料 + while (!morkF.SecondFallMaterialComplete)//等待倒料完成 { Task.Delay(5).Wait(); } - WriteData("M8.5", false);//上升完成复位 - if (!morkF.MinorOrderMaterialCom) + morkF.MaterialCount++; + WriteData("M14.7", false);//倒料复位 + if (morkF.MaterialCount == 3) { - WriteData("M14.7", true);//倒料 - while (!morkF.SecondFallMaterialComplete)//等待倒料完成 - { - Task.Delay(5).Wait(); - } - morkF.MaterialCount++; - WriteData("M14.7", false);//倒料复位 - if (morkF.MaterialCount == 3) - { - //允许执行下一个订单流程 - morkF.MaterialCount = 0; - morkF.MainProcessFlag = true; + //允许执行下一个订单流程 + morkF.MaterialCount = 0; + morkF.MainProcessFlag = true; - } - morkF.MinorOrderMaterialCom = true; - morkF.MinorHasTakeMaterial = false; - DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】,配料倒料完成"); - } - else //主流程准备阻塞 - { - morkF.MinorProcessWait = true; } + morkF.MinorOrderMaterialCom = true; + morkF.MinorHasTakeMaterial = false; + DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】,配料倒料完成"); + } + else //主流程准备阻塞 + { + morkF.MinorProcessWait = true; } } - //if (morkF.MainProcessStatus)//代表主流程执行的操作 - //{ - - //} - //else if (morkF.MinorProessStatus)//代表辅流程执行的操作 - //{ - - //} - DeviceProcessLogShow("翻转机上升完成"); } @@ -1782,57 +1927,62 @@ namespace BPASmartClient.MorkF } } /// - /// 灶台档位调节 + /// 主流程灶台档位调节 /// - public void KitchenAdjustGears(int number) + public void MainProcessKitchenAdjustGears(int number) { - //while (!morkF.PotInPlace||!morkF.SecondPotInPlace) + #region 单口锅逻辑 + while (!morkF.PotInPlace) + { + Task.Delay(5).Wait(); + } + FirstPotGears(number); + DeviceProcessLogShow($"灶台【{morkF.CurrentOrderId}】档位调节至【{number}】挡"); + #endregion + + #region 两口锅逻辑 + //if (morkF.MainProcessPotLoc == 1) //{ - // Task.Delay(5).Wait(); + // while (!morkF.PotInPlace) + // { + // Task.Delay(5).Wait(); + // } + // FirstPotGears(number); //} - if (morkF.MainProcessStatus) + //if (morkF.MainProcessPotLoc == 2) + //{ + // while (!morkF.SecondPotInPlace) + // { + // Task.Delay(5).Wait(); + // } + // SecondPotGears(number); + //} + //DeviceProcessLogShow($"灶台【{morkF.MainProcessPotLoc}】档位调节至【{number}】挡"); + #endregion + + } + /// + /// 辅流程灶台档位调节 + /// + public void MinorProcessKitchenAdjustGears(int number) + { + if (morkF.MinorProcessPotLoc == 1) { - if (morkF.MainProcessPotLoc == 1) - { - while (!morkF.PotInPlace) - { - Task.Delay(5).Wait(); - } - FirstPotGears(number); - } - if (morkF.MainProcessPotLoc == 2) + while (!morkF.PotInPlace) { - while (!morkF.SecondPotInPlace) - { - Task.Delay(5).Wait(); - } - SecondPotGears(number); + Task.Delay(5).Wait(); } - + FirstPotGears(number); } - if (morkF.MinorProessStatus) + if (morkF.MinorProcessPotLoc == 2) { - if (morkF.MinorProcessPotLoc == 1) + while (!morkF.SecondPotInPlace) { - while (!morkF.PotInPlace) - { - Task.Delay(5).Wait(); - } - FirstPotGears(number); - } - if (morkF.MinorProcessPotLoc == 2) - { - while (!morkF.SecondPotInPlace) - { - Task.Delay(5).Wait(); - } - SecondPotGears(number); + Task.Delay(5).Wait(); } + SecondPotGears(number); } - if (morkF.MainProcessStatus) - DeviceProcessLogShow($"订单【{morkF.MainCurrentOrderId}】执行取锅到灶台控制"); - if (morkF.MinorProessStatus) - DeviceProcessLogShow($"订单【{morkF.MinorCurrentOrderId}】执行取锅到灶台控制"); + DeviceProcessLogShow($"灶台【{morkF.MinorProcessPotLoc}】档位调节至【{number}】挡"); } /// /// PLC转台控制 @@ -1883,33 +2033,41 @@ namespace BPASmartClient.MorkF WriteData("M14.4", true); } /// - /// 机器人出餐并将锅放置清洗台位置 + /// 主流程机器人出餐并将锅放置清洗台位置 /// - public void RobotOutMeal() + public void MainProcessRobotOutMeal() { - if (morkF.MainProcessStatus) + #region 单口锅逻辑 + WriteData("M14.2", true);//1号锅出餐 + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessPotLoc == 1) + //{ + // WriteData("M14.2", true);//1号锅出餐 + //} + //else if (morkF.MainProcessPotLoc == 2) + //{ + // WriteData("M14.6", true);//2号锅出餐 + //} + #endregion + } + + /// + /// 复流程机器人出餐并将锅放置清洗台位置 + /// + public void MinorProcessRobotOutMeal() + { + + if (morkF.MinorProcessPotLoc == 1) { - if (morkF.MainProcessPotLoc == 1) - { - WriteData("M14.2", true);//1号锅出餐 - } - else if (morkF.MainProcessPotLoc == 2) - { - WriteData("M14.6", true);//2号锅出餐 - } + WriteData("M14.2", true);//1号锅出餐 } - if (morkF.MinorProessStatus) + else if (morkF.MinorProcessPotLoc == 2) { - if (morkF.MinorProcessPotLoc == 1) - { - WriteData("M14.2", true);//1号锅出餐 - } - else if (morkF.MinorProcessPotLoc == 2) - { - WriteData("M14.6", true);//2号锅出餐 - } + WriteData("M14.6", true);//2号锅出餐 } + } public void OpenDraft() { @@ -1920,68 +2078,83 @@ namespace BPASmartClient.MorkF /// public void AddOil() { - if (morkF.MainProcessStatus) + #region 单口锅逻辑 + while (!morkF.PotInPlace) { - if (morkF.MainProcessPotLoc == 1) - { - while (!morkF.PotInPlace) - { - Task.Delay(5).Wait(); - } - WriteData("M2.7", true);//加油 - OpenDraft(); - DeviceProcessLogShow("开始注油"); - while (!morkF.FallOilComplete) - { - Task.Delay(5).Wait(); - } - } - if (morkF.MainProcessPotLoc == 2) - { - while (!morkF.SecondPotInPlace) - { - Task.Delay(5).Wait(); - } - WriteData("M3.1", true);//加油 - OpenDraft(); - DeviceProcessLogShow("开始注油"); - while (!morkF.SecondOilComplete) - { - Task.Delay(5).Wait(); - } - } + Task.Delay(5).Wait(); } - if (morkF.MinorProessStatus) + WriteData("M2.7", true);//加油 + OpenDraft(); + DeviceProcessLogShow("开始注油"); + while (!morkF.FallOilComplete) { - if (morkF.MinorProcessPotLoc == 1) - { - while (!morkF.PotInPlace) - { - Task.Delay(5).Wait(); - } - WriteData("M2.7", true);//加油 - OpenDraft(); - DeviceProcessLogShow("开始注油"); - while (!morkF.FallOilComplete) - { - Task.Delay(5).Wait(); - } - } - if (morkF.MinorProcessPotLoc == 2) - { - while (!morkF.SecondPotInPlace) - { - Task.Delay(5).Wait(); - } - WriteData("M3.1", true);//加油 - OpenDraft(); - DeviceProcessLogShow("开始注油"); - while (!morkF.SecondOilComplete) - { - Task.Delay(5).Wait(); - } - } + Task.Delay(5).Wait(); } + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessStatus) + //{ + // if (morkF.MainProcessPotLoc == 1) + // { + // while (!morkF.PotInPlace) + // { + // Task.Delay(5).Wait(); + // } + // WriteData("M2.7", true);//加油 + // OpenDraft(); + // DeviceProcessLogShow("开始注油"); + // while (!morkF.FallOilComplete) + // { + // Task.Delay(5).Wait(); + // } + // } + // if (morkF.MainProcessPotLoc == 2) + // { + // while (!morkF.SecondPotInPlace) + // { + // Task.Delay(5).Wait(); + // } + // WriteData("M3.1", true);//加油 + // OpenDraft(); + // DeviceProcessLogShow("开始注油"); + // while (!morkF.SecondOilComplete) + // { + // Task.Delay(5).Wait(); + // } + // } + //} + //if (morkF.MinorProessStatus) + //{ + // if (morkF.MinorProcessPotLoc == 1) + // { + // while (!morkF.PotInPlace) + // { + // Task.Delay(5).Wait(); + // } + // WriteData("M2.7", true);//加油 + // OpenDraft(); + // DeviceProcessLogShow("开始注油"); + // while (!morkF.FallOilComplete) + // { + // Task.Delay(5).Wait(); + // } + // } + // if (morkF.MinorProcessPotLoc == 2) + // { + // while (!morkF.SecondPotInPlace) + // { + // Task.Delay(5).Wait(); + // } + // WriteData("M3.1", true);//加油 + // OpenDraft(); + // DeviceProcessLogShow("开始注油"); + // while (!morkF.SecondOilComplete) + // { + // Task.Delay(5).Wait(); + // } + // } + //} + #endregion //while (!morkF.FallOilComplete || !morkF.SecondOilComplete) //{ // Task.Delay(5).Wait(); @@ -2007,47 +2180,54 @@ namespace BPASmartClient.MorkF } /// - /// 翻转机方向控制 + /// 主流程翻转机方向控制 /// /// - public int TurnMachineOrientControl(string orientation) + public int MainProcessTurnMachineOrientControl(string orientation) { - int potLoc = 0; ; - //switch (orientation) + int potLoc = 0; + #region 单口锅逻辑 + FirstPotTurnMachine(orientation); + potLoc = 1; + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessPotLoc == 1) //{ - // case "Top": if (morkF.MainProcessStatus) WriteData("M8.0", true); if (morkF.MinorProessStatus) WriteData("M8.4", true); break; - // case "Down": if (morkF.MainProcessStatus) WriteData("M8.2", true); if (morkF.MinorProessStatus) WriteData("M8.6", true); break; + // FirstPotTurnMachine(orientation); + // potLoc = 1; //} - if (morkF.MainProcessStatus) + //if (morkF.MainProcessPotLoc == 2) + //{ + // SecondPotTurnMachine(orientation); + // potLoc = 2; + //} + #endregion + DeviceProcessLogShow($"翻转机执行{orientation}操作"); + + return potLoc; + } + /// + /// 辅流程翻转机方向控制 + /// + /// + public int MinorProcessTurnMachineOrientControl(string orientation) + { + int potLoc = 0; + + if (morkF.MinorProcessPotLoc == 1) { - if (morkF.MainProcessPotLoc == 1) - { - FirstPotTurnMachine(orientation); - potLoc = 1; - } - if (morkF.MainProcessPotLoc == 2) - { - SecondPotTurnMachine(orientation); - potLoc = 2; - } + FirstPotTurnMachine(orientation); + potLoc = 1; } - if (morkF.MinorProessStatus) + if (morkF.MinorProcessPotLoc == 2) { - if (morkF.MinorProcessPotLoc == 1) - { - FirstPotTurnMachine(orientation); - potLoc = 1; - } - if (morkF.MinorProcessPotLoc == 2) - { - SecondPotTurnMachine(orientation); - potLoc = 2; - } + SecondPotTurnMachine(orientation); + potLoc = 2; } + DeviceProcessLogShow($"翻转机执行{orientation}操作"); return potLoc; } - public void FirstPotTurnMachine(int gear) { while (!morkF.PotInPlace) @@ -2078,47 +2258,56 @@ namespace BPASmartClient.MorkF } /// - /// 翻转机档位控制 + /// 主流程翻转机档位控制 /// - public void TurnMachineGearsControl(int gear) + public void MainProcessTurnMachineGearsControl(int gear) { - //while (!morkF.PotInPlace) + #region 单口锅逻辑 + FirstPotTurnMachine(gear); + DeviceProcessLogShow($"炒锅【{morkF.CurrentOrderId}】翻转机档位调至{gear}挡"); + #endregion + #region 两口锅逻辑 + //if (morkF.MainProcessPotLoc == 1) //{ - // Task.Delay(5).Wait(); + // FirstPotTurnMachine(gear); //} - if (morkF.MainProcessStatus) + //if (morkF.MainProcessPotLoc == 2) + //{ + // SecondPotTurnMachine(gear); + //} + //DeviceProcessLogShow($"炒锅【{morkF.MainProcessPotLoc}】翻转机档位调至{gear}挡"); + #endregion + } + /// + /// 辅流程翻转机档位控制 + /// + public void MinorProcessTurnMachineGearsControl(int gear) + { + if (morkF.MinorProcessPotLoc == 1) { - if (morkF.MainProcessPotLoc == 1) - { - FirstPotTurnMachine(gear); - } - if (morkF.MainProcessPotLoc == 2) - { - SecondPotTurnMachine(gear); - } + FirstPotTurnMachine(gear); } - if (morkF.MinorProessStatus) + if (morkF.MinorProcessPotLoc == 2) { - if (morkF.MinorProcessPotLoc == 1) - { - FirstPotTurnMachine(gear); - } - if (morkF.MinorProcessPotLoc == 2) - { - SecondPotTurnMachine(gear); - } + SecondPotTurnMachine(gear); } - DeviceProcessLogShow($"翻转机档位调至{gear}挡"); + + DeviceProcessLogShow($"炒锅【{morkF.MinorProcessPotLoc}】翻转机档位调至{gear}挡"); } /// /// 取A,B,C料 /// public void TakeBurden() { - if (morkF.MainProcessStatus && morkF.PotInPlace) - WriteData("M14.1", true);//机器人倒料至1号锅 - if (morkF.MinorProessStatus && morkF.SecondPotInPlace) - WriteData("M14.5", true);//机器人倒料至2号锅 + #region 单口锅逻辑 + WriteData("M14.1", true);//机器人取料至1号锅 + #endregion + #region 两口锅逻辑 + //if (morkF.PotInPlace) + // WriteData("M14.1", true);//机器人取料至1号锅 + //if (morkF.SecondPotInPlace) + // WriteData("M14.5", true);//机器人取料至2号锅 + #endregion } /// /// 清洗模组1启停控制 diff --git a/BPASmartClient.MorkF/GVL_MorkF.cs b/BPASmartClient.MorkF/GVL_MorkF.cs index f9229946..3aa23c03 100644 --- a/BPASmartClient.MorkF/GVL_MorkF.cs +++ b/BPASmartClient.MorkF/GVL_MorkF.cs @@ -80,7 +80,7 @@ namespace BPASmartClient.MorkF /// public bool MaterialArriveComplete { get; set; } /// - /// 机器人空闲状态 + /// 机器人空闲状态 1:忙碌 0:空闲 /// public bool RoobotIdle { get; set; } /// @@ -291,6 +291,14 @@ namespace BPASmartClient.MorkF /// 辅流程所执行的锅位置 /// public int MinorProcessPotLoc { get; set; } + + + #region 单口锅逻辑变量 + /// + /// 订单唯一ID + /// + public string CurrentOrderId { get; set; } + #endregion } } diff --git a/BPASmartClient.SCADAControl/ArcGauge.cs b/BPASmartClient.SCADAControl/ArcGauge.cs new file mode 100644 index 00000000..51fe9932 --- /dev/null +++ b/BPASmartClient.SCADAControl/ArcGauge.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.SCADAControl +{ + /// + /// 新测试仪表盘 + /// + public class ArcGauge : Control, IExecutable + { + public ArcGauge() + { + Width = 300; + Height = 300; + SetCurrentValue(ValueProperty, 0d); + SetCurrentValue(MinValueProperty, 0d); + SetCurrentValue(MaxValueProperty, 100d); + } + + private void InitTick() + { + // 画大刻度 + for (int i = 0; i < 11; i++) + { + Line line = new Line(); + line.X1 = 0; + line.Y1 = 0; + line.X2 = 0; + line.Y2 = 12; + line.Stroke = Brushes.White; + line.StrokeThickness = 2; + line.HorizontalAlignment = HorizontalAlignment.Center; + line.RenderTransformOrigin = new Point(0.5, 0.5); + line.RenderTransform = new RotateTransform() { Angle = -140 + i * 28 }; + bdGrid.Children.Add(line); + DrawText(); + } + + // 画小刻度 + for (int i = 0; i < 10; i++) + { + var start = -140 + 28 * i + 2.8; + for (int j = 0; j < 9; j++) + { + Line line = new Line(); + line.X1 = 0; + line.Y1 = 0; + line.X2 = 0; + line.Y2 = 6; + line.Stroke = Brushes.White; + line.StrokeThickness = 1; + line.HorizontalAlignment = HorizontalAlignment.Center; + line.RenderTransformOrigin = new Point(0.5, 0.5); + line.RenderTransform = new RotateTransform() { Angle = start + j * 2.8 }; + bdGrid.Children.Add(line); + } + } + } + + List textLabels = new List(); + private void DrawText() + { + foreach (var item in textLabels) + { + bdGrid.Children.Remove(item); + } + textLabels.Clear(); + + var per = MaxValue / 10; + for (int i = 0; i < 11; i++) + { + TextBlock textBlock = new TextBlock(); + textBlock.Text = $"{MinValue + (per * i)}"; + textBlock.HorizontalAlignment = HorizontalAlignment.Center; + textBlock.RenderTransformOrigin = new Point(0.5, 0.5); + textBlock.RenderTransform = new RotateTransform() { Angle = -140 + i * 28 }; + textBlock.Margin = new Thickness(12); + textBlock.Foreground = Brushes.White; + bdGrid.Children.Add(textBlock); + textLabels.Add(textBlock); + } + } + + static ArcGauge() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ArcGauge), new FrameworkPropertyMetadata(typeof(ArcGauge))); + } + + RotateTransform rotateTransform; + Grid bdGrid; + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + rotateTransform = GetTemplateChild("PointRotate") as RotateTransform; + bdGrid = GetTemplateChild("bdGrid") as Grid; + Refresh(); + InitTick(); + } + + private bool isExecuteState; + public bool IsExecuteState + { + get { return isExecuteState; } + set + { + isExecuteState = value; + if (IsExecuteState) + { + Register(); + } + } + } + + [Category("值设定")] + public double Value + { + get { return (double)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(double), typeof(ArcGauge), new PropertyMetadata(0d, OnValueChanged)); + + private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as ArcGauge)?.Refresh(); + + [Category("值设定")] + public double MinValue + { + get { return (double)GetValue(MinValueProperty); } + set { SetValue(MinValueProperty, value); } + } + public static readonly DependencyProperty MinValueProperty = + DependencyProperty.Register("MinValue", typeof(double), typeof(ArcGauge), new PropertyMetadata(0d, OnValueChanged)); + + [Category("值设定")] + public double MaxValue + { + get { return (double)GetValue(MaxValueProperty); } + set { SetValue(MaxValueProperty, value); } + } + + public string ControlType => "控件"; + + public static readonly DependencyProperty MaxValueProperty = + DependencyProperty.Register("MaxValue", typeof(double), typeof(ArcGauge), new PropertyMetadata(0d, OnValueChanged)); + + + private void Refresh() + { + if (rotateTransform == null) + return; + DrawText(); + DoubleAnimation da = new DoubleAnimation(); + da.Duration = new Duration(TimeSpan.FromMilliseconds(350)); + da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; + + if (Value > MaxValue) + { + rotateTransform.Angle = 140; + da.To = 140; + } + else if (Value < MinValue) + { + rotateTransform.Angle = -140; + da.To = -140; + } + else + { + var range = MaxValue - MinValue; + var process = Value / range; + var tAngle = process * 280 - 140; + rotateTransform.Angle = tAngle; + da.To = tAngle; + } + + rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); + } + + public void Register() + { + Refresh(); + } + } +} diff --git a/BPASmartClient.SCADAControl/AssemblyInfo.cs b/BPASmartClient.SCADAControl/AssemblyInfo.cs new file mode 100644 index 00000000..8b5504ec --- /dev/null +++ b/BPASmartClient.SCADAControl/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj b/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj new file mode 100644 index 00000000..ec33f3dc --- /dev/null +++ b/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj @@ -0,0 +1,30 @@ + + + + net6.0-windows + enable + true + + + + + + + + + + + + + DLL\Antlr3.Runtime.dll + + + DLL\Unvell.ReoScript.dll + + + + + + + + diff --git a/BPASmartClient.SCADAControl/Converters/HalfNumberConverter.cs b/BPASmartClient.SCADAControl/Converters/HalfNumberConverter.cs new file mode 100644 index 00000000..7fd6d1a5 --- /dev/null +++ b/BPASmartClient.SCADAControl/Converters/HalfNumberConverter.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace BPASmartClient.SCADAControl.Converters +{ + public class HalfNumberConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (double.TryParse(value.ToString(), out double val)) + { + return val / 2; + } + + return 0; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } +} diff --git a/BPASmartClient.SCADAControl/IExecutable.cs b/BPASmartClient.SCADAControl/IExecutable.cs new file mode 100644 index 00000000..d48c9391 --- /dev/null +++ b/BPASmartClient.SCADAControl/IExecutable.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.SCADAControl +{ + public interface IExecutable + { + /// + /// 是否执行 + /// + bool IsExecuteState { get; set; } + /// + /// 运行程序 注册事件 + /// + void Register(); + /// + /// 控件类型 + /// + string ControlType { get; } + } +} diff --git a/BPASmartClient.SCADAControl/Images/光柱.png b/BPASmartClient.SCADAControl/Images/光柱.png new file mode 100644 index 00000000..da3a0b42 Binary files /dev/null and b/BPASmartClient.SCADAControl/Images/光柱.png differ diff --git a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml new file mode 100644 index 00000000..f30a29d4 --- /dev/null +++ b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs new file mode 100644 index 00000000..3858745d --- /dev/null +++ b/BPASmartClient.SCADAControl/NewConveyorBelt.xaml.cs @@ -0,0 +1,277 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.SCADAControl +{ + /// + /// NewConveyorBelt.xaml 的交互逻辑 + /// + public partial class NewConveyorBelt : UserControl, IExecutable + { + Path Path_mp = null; + Path Path_cb = null; + Storyboard storyboard = new Storyboard(); + Storyboard storyboard1 = new Storyboard(); + public NewConveyorBelt() + { + InitializeComponent(); + Width = 1200; + Height = 400; + this.SizeChanged += ConveyorBelt_SizeChanged; + ConveyorBeltWidth = 70; + Direction = 0; + StrokeBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#00BEFA")); + StrokeDashArray = new DoubleCollection { 1.5, 1.5 }; + StrokeFillBrush = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#00BEFA")); + StrokeThickness = 2; + } + + public string ControlType => "滚动线"; + + private bool isExecuteState; + public bool IsExecuteState + { + get { return isExecuteState; } + set + { + isExecuteState = value; + if (IsExecuteState) + { + IsEnabled = true; + Register(); + Style = null; + } + } + } + + public void Register() + { + } + + public void VisualStateManagerData() + { + storyboard.RepeatBehavior = RepeatBehavior.Forever; + DoubleAnimation dbAscending = new DoubleAnimation + { + From = 0, + To = 100, + Duration = new Duration(new TimeSpan(0, 0, 20)), + + }; + storyboard.Children.Add(dbAscending); + Storyboard.SetTarget(dbAscending, Path_mp); + Storyboard.SetTargetProperty(dbAscending, new PropertyPath("StrokeDashOffset")); + + storyboard1.RepeatBehavior = RepeatBehavior.Forever; + DoubleAnimation dbAscending1 = new DoubleAnimation + { + From = 0, + To = -100, + Duration = new Duration(new TimeSpan(0, 0, 20)), + }; + storyboard1.Children.Add(dbAscending1); + Storyboard.SetTarget(dbAscending1, Path_mp); + Storyboard.SetTargetProperty(dbAscending1, new PropertyPath("StrokeDashOffset")); + Refursh(); + } + + private void ConveyorBelt_SizeChanged(object sender, SizeChangedEventArgs e) + { + //查找 + if (!(Path_cb != null && Path_mp != null)) + { + foreach (Path tb in FindVisualChildren(this)) + { + // do something with tb here + if (tb.Tag != null) + { + if (tb.Tag.ToString() == "cb") + { + Path_cb = tb; + } + else if (tb.Tag.ToString() == "mp") + { + Path_mp = tb; + } + } + } + VisualStateManagerData(); + } + + + //传送带外边框绘制 + PathGeometry geometry = new PathGeometry(); + PathFigure pathFigure = new PathFigure(); + pathFigure.StartPoint = new Point(this.Height / 2, 0); + pathFigure.Segments.Add(new ArcSegment(new Point(this.Height / 2, this.Height), new Size(this.Height / 2, this.Height / 2), 0, false, SweepDirection.Counterclockwise, true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height), true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height - ConveyorBeltWidth), true)); + double innerCircle = (this.Height - (ConveyorBeltWidth * 2)) / 2;//内圆半径 + pathFigure.Segments.Add(new LineSegment(new Point(ConveyorBeltWidth + innerCircle, this.Height - ConveyorBeltWidth), true)); + pathFigure.Segments.Add(new ArcSegment(new Point(ConveyorBeltWidth + innerCircle, ConveyorBeltWidth), new Size(innerCircle, innerCircle), 0, false, SweepDirection.Clockwise, true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, ConveyorBeltWidth), true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Width, 0), true)); + pathFigure.Segments.Add(new LineSegment(new Point(this.Height / 2, 0), true)); + geometry.Figures.Add(pathFigure); + Path_cb.Data = geometry; + + //传送带内部皮带绘制 + PathGeometry geometry1 = new PathGeometry(); + PathFigure pathFigure1 = new PathFigure(); + pathFigure1.StartPoint = new Point(this.Width, ConveyorBeltWidth / 2); + double innerCircle1 = (this.Height - ConveyorBeltWidth) / 2;//内圆半径 + pathFigure1.Segments.Add(new LineSegment(new Point(innerCircle1 + ConveyorBeltWidth / 2, ConveyorBeltWidth / 2), true)); + pathFigure1.Segments.Add(new ArcSegment(new Point(innerCircle1 + ConveyorBeltWidth / 2, this.Height - ConveyorBeltWidth / 2), new Size(innerCircle1, innerCircle1), 0, false, SweepDirection.Counterclockwise, true)); + pathFigure1.Segments.Add(new LineSegment(new Point(this.Width, this.Height - ConveyorBeltWidth / 2), true)); + geometry1.Figures.Add(pathFigure1); + Path_mp.Data = geometry1; + } + /// + /// 搜索指定名称的子元素 + /// + /// + /// + /// + /// + public static T FindChild(DependencyObject obj, string name) where T : FrameworkElement + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) + { + DependencyObject child = VisualTreeHelper.GetChild(obj, i); + if (child != null && child is T && (child as T).Name.Equals(name)) + return (T)child; + else + { + T childOfChild = FindChild(child, name); + if (childOfChild != null) + return childOfChild; + } + } + return null; + } + + public static IEnumerable FindVisualChildren(DependencyObject depObj) where T : DependencyObject + { + if (depObj != null) + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) + { + DependencyObject child = VisualTreeHelper.GetChild(depObj, i); + if (child != null && child is T) + { + yield return (T)child; + } + + foreach (T childOfChild in FindVisualChildren(child)) + { + yield return childOfChild; + } + } + } + } + + private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as NewConveyorBelt)?.Refursh(); + } + + private void Refursh() + { + if (Direction == 1) + { + storyboard.Begin(); + storyboard1.Stop(); + // VisualStateManager.GoToState(this, "Left", false); + } + else if (Direction == 2) + { + storyboard.Stop(); + storyboard1.Begin(); + //VisualStateManager.GoToState(this, "Right", false); + } + else + { + storyboard.Stop(); + storyboard1.Stop(); + //VisualStateManager.GoToState(this, "Stop", false); + } + } + + + public DoubleCollection StrokeDashArray + { + get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); } + set { SetValue(StrokeDashArrayProperty, value); } + } + public static readonly DependencyProperty StrokeDashArrayProperty = + DependencyProperty.Register("StrokeDashArray", typeof(DoubleCollection), typeof(NewConveyorBelt), + new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged))); + + + public double ConveyorBeltWidth + { + get { return (double)GetValue(ConveyorBeltWidthProperty); } + set { SetValue(ConveyorBeltWidthProperty, value); } + } + public static readonly DependencyProperty ConveyorBeltWidthProperty = + DependencyProperty.Register("ConveyorBeltWidth", typeof(double), typeof(NewConveyorBelt), + new PropertyMetadata(50.0, new PropertyChangedCallback(OnPropertyChanged))); + + + public Brush StrokeFillBrush + { + get { return (Brush)GetValue(StrokeFillBrushProperty); } + set { SetValue(StrokeFillBrushProperty, value); } + } + public static readonly DependencyProperty StrokeFillBrushProperty = + DependencyProperty.Register("StrokeFillBrush", typeof(Brush), typeof(NewConveyorBelt), + new PropertyMetadata(Brushes.LightBlue, new PropertyChangedCallback(OnPropertyChanged))); + + + + public Brush StrokeBrush + { + get { return (Brush)GetValue(StrokeBrushProperty); } + set { SetValue(StrokeBrushProperty, value); } + } + public static readonly DependencyProperty StrokeBrushProperty = + DependencyProperty.Register("StrokeBrush", typeof(Brush), typeof(NewConveyorBelt), + new PropertyMetadata(Brushes.LightBlue, new PropertyChangedCallback(OnPropertyChanged))); + + + public double StrokeThickness + { + get { return (double)GetValue(StrokeThicknessProperty); } + set { SetValue(StrokeThicknessProperty, value); } + } + public static readonly DependencyProperty StrokeThicknessProperty = + DependencyProperty.Register("StrokeThickness", typeof(double), typeof(NewConveyorBelt), + new PropertyMetadata(1.0, new PropertyChangedCallback(OnPropertyChanged))); + + [Category("值设定")] + public int Direction + { + get { return (int)GetValue(DirectionProperty); } + set { SetValue(DirectionProperty, value); } + } + public static readonly DependencyProperty DirectionProperty = + DependencyProperty.Register("Direction", typeof(int), typeof(NewConveyorBelt), + new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged))); + + + } +} diff --git a/BPASmartClient.SCADAControl/Silos.xaml b/BPASmartClient.SCADAControl/Silos.xaml new file mode 100644 index 00000000..39b60ba8 --- /dev/null +++ b/BPASmartClient.SCADAControl/Silos.xaml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + diff --git a/BPASmartClient.SCADAControl/Silos.xaml.cs b/BPASmartClient.SCADAControl/Silos.xaml.cs new file mode 100644 index 00000000..2435dc5d --- /dev/null +++ b/BPASmartClient.SCADAControl/Silos.xaml.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.SCADAControl +{ + /// + /// Silos.xaml 的交互逻辑 + /// 物料仓 + /// + public partial class Silos : UserControl, IExecutable + { + public Silos() + { + InitializeComponent(); + this.DataContext = this; + Width = 180; + Height = 270; + Value = 25.23; + Title = "香料"; + Text = "1 号仓"; + } + + public string ControlType => "物料仓"; + + private bool isExecuteState; + public bool IsExecuteState + { + get { return isExecuteState; } + set + { + isExecuteState = value; + if (IsExecuteState) + { + IsEnabled = true; + Register(); + Style = null; + } + } + } + + #region 属性 + [Category("值设定")] + public double Value + { + get { return (double)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(double), typeof(Silos), new PropertyMetadata(0d, OnValueChanged)); + + private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as Silos)?.Refresh(); + + [Category("值设定")] + public string Text + { + get { return (string)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + public static readonly DependencyProperty TextProperty = + DependencyProperty.Register("Text", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); + + [Category("值设定")] + public string Title + { + get { return (string)GetValue(TitleProperty); } + set { SetValue(TitleProperty, value); } + } + public static readonly DependencyProperty TitleProperty = + DependencyProperty.Register("Title", typeof(string), typeof(Silos), new PropertyMetadata(string.Empty)); + #endregion + + #region 函数 + public void Refresh() + { + + } + #endregion + + public void Register() + { + } + } +} diff --git a/BPASmartClient.SCADAControl/SwitchButton.cs b/BPASmartClient.SCADAControl/SwitchButton.cs new file mode 100644 index 00000000..45f405e9 --- /dev/null +++ b/BPASmartClient.SCADAControl/SwitchButton.cs @@ -0,0 +1,144 @@ +using BPASmartClient.Compiler; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.SCADAControl +{ + [TemplatePart(Name = ELLIPSE, Type = typeof(FrameworkElement))] + [TemplatePart(Name = TranslateX, Type = typeof(TranslateTransform))] + public class SwitchButton : ToggleButton, IExecutable + { + public SwitchButton() + { + SetCurrentValue(WidthProperty, 120d); + SetCurrentValue(HeightProperty, 40d); + } + + public const string ELLIPSE = "ELLIPSE"; + public const string TranslateX = "TranslateX"; + static SwitchButton() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(SwitchButton), new FrameworkPropertyMetadata(typeof(SwitchButton))); + } + + /// + /// 不勾选时执行代码 + /// + [Category("事件")] + public string UnCheckedExec + { + get { return (string)GetValue(UnCheckedExecProperty); } + set { SetValue(UnCheckedExecProperty, value); } + } + public static readonly DependencyProperty UnCheckedExecProperty = + DependencyProperty.Register("UnCheckedExec", typeof(string), typeof(SwitchButton), new PropertyMetadata(string.Empty)); + + /// + /// 勾选时执行代码 + /// + [Category("事件")] + public string CheckedExec + { + get { return (string)GetValue(CheckedExecProperty); } + set { SetValue(CheckedExecProperty, value); } + } + public static readonly DependencyProperty CheckedExecProperty = + DependencyProperty.Register("CheckedExec", typeof(string), typeof(SwitchButton), new PropertyMetadata(string.Empty)); + + protected override void OnRender(DrawingContext drawingContext) + { + base.OnRender(drawingContext); + ellipse.Width = Height - 8; + ellipse.Height = Height - 8; + Refresh(); + } + + TranslateTransform transX; + Ellipse ellipse; + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + ellipse = GetTemplateChild(ELLIPSE) as Ellipse; + transX = GetTemplateChild(TranslateX) as TranslateTransform; + } + protected override void OnChecked(RoutedEventArgs e) + { + base.OnChecked(e); + Refresh(); + } + protected override void OnUnchecked(RoutedEventArgs e) + { + base.OnUnchecked(e); + Refresh(); + } + + void Refresh() + { + if (ellipse == null) + { + return; + } + DoubleAnimation da = new DoubleAnimation(); + da.Duration = new Duration(TimeSpan.FromMilliseconds(250)); + da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; + if (IsChecked == true) + { + da.To = ActualWidth - ellipse.ActualWidth - 5; + ellipse.SetCurrentValue(Ellipse.FillProperty, Background); + } + else + { + da.To = 3; + ellipse.SetCurrentValue(Ellipse.FillProperty, Brushes.Gray); + } + + transX.BeginAnimation(TranslateTransform.XProperty, da); + } + + private bool isExecuteState; + public bool IsExecuteState + { + get { return isExecuteState; } + set + { + isExecuteState = value; + if (IsExecuteState) + { + Register(); + } + } + } + + public void Register() + { + Checked += TheCheckBox_Checked; + Unchecked += TheCheckBox_Unchecked; + } + private void TheCheckBox_Unchecked(object sender, RoutedEventArgs e) + { + Config.GetInstance().RunJsScipt(UnCheckedExec); + } + + private void TheCheckBox_Checked(object sender, RoutedEventArgs e) + { + Config.GetInstance().RunJsScipt(CheckedExec); + } + public string ControlType => "控件"; + + } +} diff --git a/BPASmartClient.SCADAControl/Themes/Generic.xaml b/BPASmartClient.SCADAControl/Themes/Generic.xaml new file mode 100644 index 00000000..40a6fbe8 --- /dev/null +++ b/BPASmartClient.SCADAControl/Themes/Generic.xaml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index ec97dc59..49784b1a 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -27,7 +27,7 @@ - + @@ -40,7 +40,8 @@ - ManualControl = new ObservableCollection(); + ManualControl.Add(new SubMenumodel() + { + SubMenuName = "手动控制", + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + AssemblyName = "BPASmartClient.DosingSystem", + ToggleWindowPath = "View.ManualControlView" + }); + + MenuManage.GetInstance.menuModels.Add(new MenuModel() + { + MainMenuIcon = "", + MainMenuName = "手动控制", + Alias = "Parameter Set", + subMenumodels = ManualControl, + }); + #endregion + #region 消息日志 ObservableCollection InfoLog = new ObservableCollection(); InfoLog.Add(new SubMenumodel() diff --git a/DosingSystem/Model/ConveyorServer.cs b/DosingSystem/Model/ConveyorServer.cs new file mode 100644 index 00000000..f2b36ed3 --- /dev/null +++ b/DosingSystem/Model/ConveyorServer.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; + +namespace BPASmartClient.DosingSystem.Model +{ + public class ConveyorServer + { + public ConveyorServer() + { + + } + } +} diff --git a/DosingSystem/Model/CylinderStatusModel.cs b/DosingSystem/Model/CylinderStatusModel.cs new file mode 100644 index 00000000..6c43e5b6 --- /dev/null +++ b/DosingSystem/Model/CylinderStatusModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; + +namespace BPASmartClient.DosingSystem.Model +{ + public class CylinderStatusModel : ObservableObject + { + /// + /// 气缸原点信号 + /// + public bool HomeStatus { get { return _mHomeStatus; } set { _mHomeStatus = value; OnPropertyChanged(); } } + private bool _mHomeStatus; + + /// + /// 气缸到位信号 + /// + public bool InPlace { get { return _mInPlace; } set { _mInPlace = value; OnPropertyChanged(); } } + private bool _mInPlace; + + + + } +} diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index 39ffe443..053a1230 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -66,7 +66,6 @@ namespace BPASmartClient.DosingSystem.Model public void Init() { - devices.Add(new Devices() { DeviceName = "测试", IpAddress = "192.168.0.1" }); IpAddressLines(); DeviceDataInit(); ThreadManage.GetInstance().StartLong(new Action(() => diff --git a/DosingSystem/View/DeviceListView.xaml b/DosingSystem/View/DeviceListView.xaml index 6b01ea58..3d70f591 100644 --- a/DosingSystem/View/DeviceListView.xaml +++ b/DosingSystem/View/DeviceListView.xaml @@ -60,7 +60,7 @@ + Columns="8" /> @@ -68,7 +68,9 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DosingSystem/View/ManualControlView.xaml.cs b/DosingSystem/View/ManualControlView.xaml.cs new file mode 100644 index 00000000..3cd21a96 --- /dev/null +++ b/DosingSystem/View/ManualControlView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.DosingSystem.View +{ + /// + /// ManualControlView.xaml 的交互逻辑 + /// + public partial class ManualControlView : UserControl + { + public ManualControlView() + { + InitializeComponent(); + } + } +} diff --git a/DosingSystem/View/RecipeControlView.xaml b/DosingSystem/View/RecipeControlView.xaml index acd58d57..6fabf2e3 100644 --- a/DosingSystem/View/RecipeControlView.xaml +++ b/DosingSystem/View/RecipeControlView.xaml @@ -9,8 +9,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pry="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource" xmlns:vm="clr-namespace:BPASmartClient.DosingSystem.ViewModel" - d:DesignHeight="450" - d:DesignWidth="800" + d:DesignHeight="800" + d:DesignWidth="1400" mc:Ignorable="d"> @@ -20,8 +20,8 @@ - - + + - - + - - + + - - + + - - - - - - - + - + - + + - + - + - + - - - - - - - - + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - - --> - + + - + + + - + - + + + + - - - + + + - - - - + + + + - - + + + + - - + + - - + + - - - + + + - - -