|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using BPASmartClient.Message;
- using BPASmartClient.MessageCommunication;
- using BPASmartClient.MessageCommunication.MsgControl;
- using BPASmartClient.SerialPort;
- using System;
- using System.Threading;
-
- namespace BPASmartClient.GSIceCream
- {
- /// <summary>
- /// 指令封装
- /// </summary>
- internal class CommandHandler
- {
- byte[] cmdHeartDW;
-
- private SerialPortClient commProxy;
- public Action<bool> PauseAsk { get; set; }
-
- /// <summary>
- /// 初始化
- /// </summary>
- internal void Init(SerialPortClient commProxy)
- {
- this.commProxy = commProxy;
- ICMSG_Heart_DW heartDW = new ICMSG_Heart_DW();
- cmdHeartDW = IcPack.StructureToByte(heartDW);
- Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.GSIceCream_ModeSet,"ModeSetHandler");
- Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.GSIceCream_Discharge,"DischargeHandler");
- }
-
- /// <summary>
- /// 发送心跳
- /// </summary>
- internal byte[] GetHeartDW()
- {
- return cmdHeartDW;
- }
- /// <summary>
- /// 模式设置
- /// </summary>
- public void ModeSetHandler(object sender,InnerMessageEventArgs e)
- {
- try
- {
- if (e.obj_MessageObj is MORKI_MODE)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build((MORKI_MODE)(e.obj_MessageObj)));
- commProxy.SendData(data);
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
- MessageLog.GetInstance.Show(string.Format("设置模式[{0}]",Enum.GetName(typeof(MORKI_MODE),(MORKI_MODE)e.obj_MessageObj)));
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,ModeSetHandler 类,描述:[{ex.Message}]");
- }
- }
-
- /// <summary>
- /// 打料
- /// </summary>
- public void DischargeHandler(object sender,InnerMessageEventArgs e)
- {
- try
- {
- if (e.obj_MessageObj is MORKI_MODE)
- {
- if (MorkIStatus.GetInstance().Fault != MORKI_FAULT.未发生故障)
- {
- MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作",MorkIStatus.GetInstance().Fault));
- //callBack?.Invoke(false);
- return;
- }
- if (MorkIStatus.GetInstance().CXB <= 86)
- {
- MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作",MorkIStatus.GetInstance().CXB));
- //callBack?.Invoke(false);
- return;
- }
-
- bool modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
-
- if (!modeRight)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
-
- var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式));
- commProxy.SendData(temp);
-
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
- MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.制冷模式));
-
- DateTime freeTime = DateTime.Now.AddSeconds(5);
- while (DateTime.Now < freeTime)
- {
- Thread.Sleep(10);
- modeRight = MorkIStatus.GetInstance().CurrentMode == MORKI_MODE.制冷模式;
- if (modeRight)
- break;
- }
- }
-
- if (modeRight)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料));
- commProxy.SendData(data);
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
- Class_InnerMessageBus.GetInstance().PostMessage(this,Class_MessageName.GSIceCream_EndCook,"");
- MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.打料));
- //callBack?.Invoke(true);
- }
- else
- {
- MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料",MorkIStatus.GetInstance().CurrentMode));
- //callBack?.Invoke(false);
- }
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,ModeSetHandler 类,描述:[{ex.Message}]");
- }
- }
- }
- }
|