@@ -5,7 +5,6 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | <ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | ||||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | <ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | ||||
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | <ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | ||||
@@ -3,6 +3,7 @@ using BPASmartClient.EventBus; | |||||
using BPASmartClient.Helper; | using BPASmartClient.Helper; | ||||
using BPASmartClient.Message; | using BPASmartClient.Message; | ||||
using BPASmartClient.Model; | using BPASmartClient.Model; | ||||
using BPASmartClient.Model.咖啡机.Enum; | |||||
using BPASmartClient.Peripheral; | using BPASmartClient.Peripheral; | ||||
using BPASmartClient.SerialPort; | using BPASmartClient.SerialPort; | ||||
using System; | using System; | ||||
@@ -15,78 +16,33 @@ namespace BPASmartClient.DRCoffee | |||||
/// <summary> | /// <summary> | ||||
/// 咖啡机 | /// 咖啡机 | ||||
/// </summary> | /// </summary> | ||||
public class CoffeeMachine: BasePeripheral | |||||
public class CoffeeMachine :BasePeripheral | |||||
{ | { | ||||
//通讯代理 | //通讯代理 | ||||
SerialPortClient commProxy = null; | SerialPortClient commProxy = null; | ||||
//数据仓库 | //数据仓库 | ||||
private DataStorage<byte> dataStorage = new DataStorage<byte>(); | private DataStorage<byte> dataStorage = new DataStorage<byte>(); | ||||
//主线程运行标识 | |||||
private bool running = false; | |||||
//是否下发指令,主线程等待 | //是否下发指令,主线程等待 | ||||
private bool free = true; | |||||
private DrCoffeeStatus drCoffeeStatus; | |||||
/// <summary> | |||||
/// 咖啡机状态 | |||||
/// </summary> | |||||
public DrCoffeeStatus CurrentCoffeeStatus | |||||
{ | |||||
get { return drCoffeeStatus; } | |||||
set | |||||
{ | |||||
if (drCoffeeStatus != value) | |||||
{ | |||||
drCoffeeStatus = value; | |||||
CoffeeStatusChanged?.Invoke(value); | |||||
} | |||||
} | |||||
} | |||||
private DrCoffeeAppStatus coffeeAppStatus; | |||||
/// <summary> | |||||
/// 应用状态 | |||||
/// </summary> | |||||
public DrCoffeeAppStatus CurrentCoffeeAppStatus | |||||
{ | |||||
get { return coffeeAppStatus; } | |||||
set | |||||
{ | |||||
if (coffeeAppStatus != value) | |||||
{ | |||||
coffeeAppStatus = value; | |||||
CoffeeAppStatusChanged?.Invoke(value); | |||||
} | |||||
} | |||||
} | |||||
public Action<string> SendCallback; | |||||
public Action<string> ReciveCallback; | |||||
/// <summary> | |||||
/// 咖啡机状态改变回调 | |||||
/// </summary> | |||||
public Action<DrCoffeeStatus> CoffeeStatusChanged; | |||||
/// <summary> | |||||
/// 应用状态改变回调 | |||||
/// </summary> | |||||
public Action<DrCoffeeAppStatus> CoffeeAppStatusChanged; | |||||
/// <summary> | |||||
/// Dr咖啡机基础协议 | |||||
/// </summary> | |||||
private bool free = false; | |||||
//状态询问指令 | |||||
private byte[] cmdAsk; | |||||
//Dr咖啡机基础协议 | |||||
private DrCoffeePackage drinksOrder = new DrCoffeePackage(); | private DrCoffeePackage drinksOrder = new DrCoffeePackage(); | ||||
/// <summary> | |||||
/// 串口COM口 | |||||
/// </summary> | |||||
//串口COM口 | |||||
public string PortName { get; set; } | public string PortName { get; set; } | ||||
//串口波特率 | |||||
public string BaudRate { get; set; } | |||||
//心跳时间 | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
/// <summary> | /// <summary> | ||||
/// 串口波特率 | |||||
/// 是否在线 | |||||
/// </summary> | /// </summary> | ||||
public string BaudRate { get; set; } | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
public CoffeeMachine() | public CoffeeMachine() | ||||
{ | { | ||||
DrCoffeePackage package = new DrCoffeePackage(); | |||||
package.CommCmd = DrCoffeeCommCmd.饮品制作指令; | |||||
cmdAsk = DrCoffee.Packe(package); | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -94,10 +50,17 @@ namespace BPASmartClient.DRCoffee | |||||
/// </summary> | /// </summary> | ||||
public override void Start() | public override void Start() | ||||
{ | { | ||||
commProxy.Start(); | |||||
running = true; | |||||
MainLoop(); | |||||
try | |||||
{ | |||||
commProxy.Start(); | |||||
IsConnected = true; | |||||
free = false; | |||||
MainLoop(); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -105,8 +68,16 @@ namespace BPASmartClient.DRCoffee | |||||
/// </summary> | /// </summary> | ||||
public override void Stop() | public override void Stop() | ||||
{ | { | ||||
commProxy.Stop(); | |||||
running = false; | |||||
try | |||||
{ | |||||
commProxy.Stop(); | |||||
IsConnected = false; | |||||
free = true; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -114,15 +85,14 @@ namespace BPASmartClient.DRCoffee | |||||
/// </summary> | /// </summary> | ||||
private void MainLoop() | private void MainLoop() | ||||
{ | { | ||||
//ThreadManage.GetInstance.StartLong(new Action(() => | |||||
//{ | |||||
// if (free) | |||||
// { | |||||
// commProxy.SendData(commandHandler.GetStatusAsk()); | |||||
// SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetStatusAsk())); | |||||
// } | |||||
// Thread.Sleep(200); | |||||
//}),"咖啡机询问线程"); | |||||
ThreadManage.GetInstance.StartLong(new Action(() => | |||||
{ | |||||
if (!free) | |||||
{ | |||||
commProxy.SendData(cmdAsk); | |||||
} | |||||
Thread.Sleep(200); | |||||
}),"咖啡机询问线程"); | |||||
ThreadManage.GetInstance.StartLong(new Action(() => | ThreadManage.GetInstance.StartLong(new Action(() => | ||||
{ | { | ||||
@@ -137,9 +107,8 @@ namespace BPASmartClient.DRCoffee | |||||
{ | { | ||||
temp.Add(item); | temp.Add(item); | ||||
var package = DrCoffee.UnPack(temp.ToArray()); | var package = DrCoffee.UnPack(temp.ToArray()); | ||||
ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray())); | |||||
temp.Clear(); | temp.Clear(); | ||||
MorkCStatus.GetInstance().ProcessPackage(package); | |||||
ProcessPackage(package); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -159,14 +128,45 @@ namespace BPASmartClient.DRCoffee | |||||
} | } | ||||
} | } | ||||
Thread.Sleep(5); | Thread.Sleep(5); | ||||
}), "咖啡机解析线程"); | |||||
}),"咖啡机解析线程"); | |||||
} | } | ||||
protected override void InitStatus() | |||||
/// <summary> | |||||
/// 咖啡机状态解析 | |||||
/// </summary> | |||||
/// <param name="package"></param> | |||||
public void ProcessPackage(DrCoffeePackage package) | |||||
{ | { | ||||
if (((DrCoffeeStatus)status["CoffeeStatus"]) == DrCoffeeStatus.Running && package.Status != DrCoffeeStatus.Running) | |||||
{ | |||||
status["CoffeeStatus"] = package.Status; | |||||
lastRefreshTime = DateTime.Now; | |||||
new DRCoffee_CoffeEndCookEvent() { Id = DeviceId }.Publish(); | |||||
} | |||||
else status["CoffeeStatus"] = package.Status; | |||||
status["AppStatus"] = package.ApplicationStatus; | |||||
status["Warning"] = package.Warning; | |||||
status["Fault"] = package.Fault; | |||||
if ((DrCoffeeStatus)status["CoffeeStatus"] == DrCoffeeStatus.Warning | |||||
|| (DrCoffeeStatus)status["CoffeeStatus"] == DrCoffeeStatus.Fault | |||||
|| (DrCoffeeWarning)status["Warning"] != DrCoffeeWarning.无警告 | |||||
|| (DrCoffeeFault)status["Fault"] != DrCoffeeFault.无故障 | |||||
) | |||||
{ | |||||
IsWork = false; | |||||
} | |||||
else | |||||
IsWork = true; | |||||
} | } | ||||
protected override void InitStatus() | |||||
{ | |||||
status["CoffeeStatus"] = DrCoffeeStatus.Wait; | |||||
status["AppStatus"] = DrCoffeeAppStatus.应用无状态; | |||||
status["Warning"] = DrCoffeeWarning.无警告; | |||||
status["Fault"] = DrCoffeeFault.无故障; | |||||
} | |||||
public override void Init() | public override void Init() | ||||
{ | { | ||||
@@ -181,7 +181,7 @@ namespace BPASmartClient.DRCoffee | |||||
free = true; | free = true; | ||||
Thread.Sleep(200); | Thread.Sleep(200); | ||||
drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令; | drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令; | ||||
//drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).CommCmd; | |||||
drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).DrinkCode; | |||||
commProxy.SendData(DrCoffee.Packe(drinksOrder)); | commProxy.SendData(DrCoffee.Packe(drinksOrder)); | ||||
Thread.Sleep(200); | Thread.Sleep(200); | ||||
free = false; | free = false; | ||||
@@ -218,7 +218,7 @@ namespace BPASmartClient.DRCoffee | |||||
{ | { | ||||
free = true; | free = true; | ||||
Thread.Sleep(200); | Thread.Sleep(200); | ||||
//drinksOrder.CommCmd = (DrCoffeeCommCmd)int.Parse(e.obj_MessageObj.ToString()); | |||||
drinksOrder.CommCmd = ((DRCoffee_CoffeeCommCmdEvent)@event).CommCmd; | |||||
commProxy.SendData(DrCoffee.Packe(drinksOrder)); | commProxy.SendData(DrCoffee.Packe(drinksOrder)); | ||||
Thread.Sleep(200); | Thread.Sleep(200); | ||||
free = false; | free = false; | ||||
@@ -229,5 +229,6 @@ namespace BPASmartClient.DRCoffee | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
} | } |
@@ -1,76 +0,0 @@ | |||||
using BPASmartClient.DRCoffee; | |||||
using BPASmartClient.MessageCommunication; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BPASmartClient.DRCoffee | |||||
{ | |||||
public class MorkCStatus | |||||
{ | |||||
private volatile static MorkCStatus _Instance; | |||||
public static MorkCStatus GetInstance() => _Instance ?? (_Instance = new MorkCStatus()); | |||||
private MorkCStatus() { } | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
/// <summary> | |||||
/// 是否在线 | |||||
/// </summary> | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
/// <summary> | |||||
/// 咖啡机状态 | |||||
/// </summary> | |||||
public DrCoffeeStatus CoffeeStatus { get; set; } | |||||
/// <summary> | |||||
/// 应用状态 | |||||
/// </summary> | |||||
public DrCoffeeAppStatus AppStatus { get; set; } | |||||
/// <summary> | |||||
/// 警告信息 | |||||
/// </summary> | |||||
public DrCoffeeWarning Warning { get; set; } | |||||
/// <summary> | |||||
/// 故障信息 | |||||
/// </summary> | |||||
public DrCoffeeFault Fault { get; set; } | |||||
public bool CanDo | |||||
{ | |||||
get | |||||
{ | |||||
if (!OnLine) | |||||
return false; | |||||
if (Warning != DrCoffeeWarning.无警告) | |||||
return false; | |||||
if (Fault != DrCoffeeFault.无故障) | |||||
return false; | |||||
return true; | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 咖啡机状态解析 | |||||
/// </summary> | |||||
/// <param name="package"></param> | |||||
public void ProcessPackage(DrCoffeePackage package) | |||||
{ | |||||
if (CoffeeStatus == DrCoffeeStatus.Running && package.Status != DrCoffeeStatus.Running) | |||||
{ | |||||
CoffeeStatus = package.Status; | |||||
Class_InnerMessageBus.GetInstance().PostMessage(this,Class_MessageName.DRCoffee_CoffeEndCook,""); | |||||
} | |||||
else { | |||||
CoffeeStatus = package.Status; | |||||
} | |||||
AppStatus = package.ApplicationStatus; | |||||
Warning = package.Warning; | |||||
Fault = package.Fault; | |||||
lastRefreshTime = DateTime.Now; | |||||
} | |||||
} | |||||
} |
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.咖啡机.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
@@ -5,7 +5,8 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | <ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -1,134 +0,0 @@ | |||||
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}]"); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -1,47 +1,77 @@ | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.EventBus; | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.Message; | |||||
using BPASmartClient.Model; | |||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using BPASmartClient.Peripheral; | |||||
using BPASmartClient.SerialPort; | using BPASmartClient.SerialPort; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | |||||
using System.Threading; | using System.Threading; | ||||
using static BPASmartClient.EventBus.EventBus; | |||||
using static BPASmartClient.GSIceCream.MessageDefine; | using static BPASmartClient.GSIceCream.MessageDefine; | ||||
namespace BPASmartClient.GSIceCream | namespace BPASmartClient.GSIceCream | ||||
{ | { | ||||
public class IceCreamMachine | |||||
{ | |||||
//指令组装 | |||||
private CommandHandler commandHandler = new CommandHandler(); | |||||
public class IceCreamMachine :BasePeripheral | |||||
{ | |||||
//通讯代理 | //通讯代理 | ||||
SerialPortClient commProxy = null; | SerialPortClient commProxy = null; | ||||
//是否下发指令,主线程等待 | |||||
private bool free = false; | |||||
//心跳指令 | |||||
private byte[] cmdHeartDW; | |||||
//数据仓库 | //数据仓库 | ||||
private DataStorage<byte> dataStorage = new DataStorage<byte>(); | private DataStorage<byte> dataStorage = new DataStorage<byte>(); | ||||
//主线程运行标识 | |||||
private bool running = false; | |||||
//是否下发指令,主线程等待 | |||||
private bool free = true; | |||||
public Action<string> SendCallback; | |||||
public Action<string> ReciveCallback; | |||||
//串口COM口 | |||||
public string PortName { get; set; } | |||||
//串口波特率 | |||||
public string BaudRate { get; set; } | |||||
//心跳时间 | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
//是否在线 | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
public IceCreamMachine(string portName, BaudRates baud) | |||||
public IceCreamMachine() | |||||
{ | { | ||||
commProxy = new SerialPortClient(portName, baud); | |||||
commProxy.SetDataStorage(dataStorage); | |||||
commandHandler.Init(commProxy); | |||||
commandHandler.PauseAsk = delegate (bool pause) | |||||
{ | |||||
free = !pause; | |||||
}; | |||||
ICMSG_Heart_DW heartDW = new ICMSG_Heart_DW(); | |||||
cmdHeartDW = IcPack.StructureToByte(heartDW); | |||||
} | } | ||||
public void Start() | |||||
/// <summary> | |||||
/// 主线程开始运行 | |||||
/// </summary> | |||||
public override void Start() | |||||
{ | { | ||||
commProxy.Start(); | |||||
running = true; | |||||
MainLoop(); | |||||
try | |||||
{ | |||||
commProxy.Start(); | |||||
IsConnected = true; | |||||
free = false; | |||||
MainLoop(); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,IceCreamMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | } | ||||
public void Stop() | |||||
/// <summary> | |||||
/// 停止运行 | |||||
/// </summary> | |||||
public override void Stop() | |||||
{ | { | ||||
try | |||||
{ | |||||
commProxy.Stop(); | |||||
IsConnected = false; | |||||
free = true; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,IceCreamMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | } | ||||
private MSG_RESOLVE_STEP currentStep; | private MSG_RESOLVE_STEP currentStep; | ||||
@@ -49,10 +79,9 @@ namespace BPASmartClient.GSIceCream | |||||
{ | { | ||||
ThreadManage.GetInstance.StartLong(new Action(() => | ThreadManage.GetInstance.StartLong(new Action(() => | ||||
{ | { | ||||
if (free) | |||||
if (!free) | |||||
{ | { | ||||
commProxy.SendData(commandHandler.GetHeartDW()); | |||||
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW())); | |||||
commProxy.SendData(cmdHeartDW); | |||||
} | } | ||||
Thread.Sleep(500); | Thread.Sleep(500); | ||||
}), "冰淇淋询问线程"); | }), "冰淇淋询问线程"); | ||||
@@ -60,16 +89,12 @@ namespace BPASmartClient.GSIceCream | |||||
ThreadManage.GetInstance.StartLong(new Action(() => | ThreadManage.GetInstance.StartLong(new Action(() => | ||||
{ | { | ||||
ResolveMsg(); | ResolveMsg(); | ||||
//Thread.Sleep(2000); | |||||
}), "冰淇淋解析线程"); | }), "冰淇淋解析线程"); | ||||
} | } | ||||
int contentLength = 0; | int contentLength = 0; | ||||
int currentContentOffset = 0; | int currentContentOffset = 0; | ||||
private void ResolveMsg() | private void ResolveMsg() | ||||
{ | { | ||||
//while (running) | |||||
//{ | |||||
List<byte> temp = new List<byte>(); | List<byte> temp = new List<byte>(); | ||||
//一系列解包 | //一系列解包 | ||||
while (dataStorage.GetSize() > 0) | while (dataStorage.GetSize() > 0) | ||||
@@ -142,13 +167,168 @@ namespace BPASmartClient.GSIceCream | |||||
} | } | ||||
temp.Add(dataStorage.GetData()); | temp.Add(dataStorage.GetData()); | ||||
temp.Add(dataStorage.GetData()); | temp.Add(dataStorage.GetData()); | ||||
ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray())); | |||||
MorkIStatus.GetInstance().ProcessMsg(temp.ToArray()); | |||||
ProcessMsg(temp.ToArray()); | |||||
currentStep = MSG_RESOLVE_STEP.NONE; | currentStep = MSG_RESOLVE_STEP.NONE; | ||||
continue; | continue; | ||||
} | } | ||||
Thread.Sleep(5); | Thread.Sleep(5); | ||||
//} | |||||
} | |||||
private void ProcessHeart(ICMSG_Heart_UP heartUpMsg) | |||||
{ | |||||
status["CurrentMode"] = heartUpMsg.MS; | |||||
status["YLWD"] = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L,heartUpMsg.YLWD_H },0); | |||||
status["HQWD"] = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L,heartUpMsg.HQWD_H },0); | |||||
status["HJWD"] = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L,heartUpMsg.HJWD_H },0); | |||||
status["DL"] = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L,heartUpMsg.DL_H },0); | |||||
status["Fault"] = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L,heartUpMsg.GZ_H },0); | |||||
status["CXB"] = heartUpMsg.CXB; | |||||
status["DLCompleted"] = (heartUpMsg.DLTJ >> 4 & 1) == 1; | |||||
if (RTrig.GetInstance("打料完成检测").Start((bool)status["DLCompleted"])) | |||||
{ | |||||
MessageLog.GetInstance.Show("打料完成"); | |||||
} | |||||
if (RTrig.GetInstance("打料中检测").Start(!(bool)status["DLCompleted"])) | |||||
{ | |||||
MessageLog.GetInstance.Show("打料中"); | |||||
} | |||||
} | |||||
private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg) | |||||
{ | |||||
MessageLog.GetInstance.Show(string.Format("模式返回为:{0}",modeUpMsg.Mode)); | |||||
} | |||||
public void ProcessMsg(byte[] data) | |||||
{ | |||||
lastRefreshTime = DateTime.Now; | |||||
try | |||||
{ | |||||
if (data.Length < 5) | |||||
return; | |||||
switch (data[2]) | |||||
{ | |||||
case (byte)IC_CMD.HEART: | |||||
var msg = IcPack.ByteToStructure<ICMSG_Heart_UP>(data.ToArray()); | |||||
ProcessHeart(msg); | |||||
break; | |||||
case (byte)IC_CMD.MODE: | |||||
var modeUp = IcPack.ByteToStructure<ICMSG_MODE_UP>(data.ToArray()); | |||||
ProcessModeUp(modeUp); | |||||
break; | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
protected override void InitStatus() | |||||
{ | |||||
status["YLWD"] = (short)0; | |||||
status["HQWD"] = (short)0; | |||||
status["HJWD"] = (short)0; | |||||
status["DL"] = (short)0; | |||||
status["DY"] = (short)0; | |||||
status["CurrentMode"] = MORKI_MODE.待机模式; | |||||
status["Fault"] = MORKI_FAULT.未发生故障; | |||||
status["CXB"] = (byte)0; | |||||
status["CXB_Threshold"] = (byte)0; | |||||
status["DLCompleted"] = true; | |||||
} | |||||
public override void Init() | |||||
{ | |||||
commProxy = new SerialPortClient(PortName,(BaudRates)Enum.Parse(typeof(BaudRates),BaudRate)); | |||||
commProxy.SetDataStorage(dataStorage); | |||||
//广深冰淇淋机模式设置 | |||||
EventBus.EventBus.GetInstance().Subscribe<GSIceCream_ModeSetEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) | |||||
{ | |||||
try | |||||
{ | |||||
free = true; | |||||
Thread.Sleep(200); | |||||
var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(((GSIceCream_ModeSetEvent)@event).Mode)); | |||||
commProxy.SendData(data); | |||||
Thread.Sleep(200); | |||||
free = false; | |||||
MessageLog.GetInstance.Show(string.Format("设置模式[{0}]",Enum.GetName(typeof(MORKI_MODE),((GSIceCream_ModeSetEvent)@event).Mode))); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,IceCreamMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
}); | |||||
//广深冰淇淋机打料 | |||||
EventBus.EventBus.GetInstance().Subscribe<GSIceCream_DischargeEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) | |||||
{ | |||||
try | |||||
{ | |||||
if ((MORKI_FAULT)status["Fault"] != MORKI_FAULT.未发生故障) | |||||
{ | |||||
MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作",(MORKI_FAULT)status["Fault"])); | |||||
new GSIceCream_EndCookEvent() { Id = DeviceId,Status = false }.Publish(); | |||||
return; | |||||
} | |||||
if ((byte)status["CXB"] <= 86) | |||||
{ | |||||
MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作",(byte)status["CXB"])); | |||||
new GSIceCream_EndCookEvent() { Id = DeviceId,Status = false }.Publish(); | |||||
return; | |||||
} | |||||
bool modeRight = (MORKI_MODE)status["CurrentMode"] == MORKI_MODE.制冷模式; | |||||
if (!modeRight) | |||||
{ | |||||
free = true; | |||||
Thread.Sleep(200); | |||||
var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式)); | |||||
commProxy.SendData(temp); | |||||
Thread.Sleep(200); | |||||
free = false; | |||||
MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.制冷模式)); | |||||
DateTime freeTime = DateTime.Now.AddSeconds(5); | |||||
while (DateTime.Now < freeTime) | |||||
{ | |||||
Thread.Sleep(10); | |||||
modeRight = (MORKI_MODE)status["CurrentMode"] == MORKI_MODE.制冷模式; | |||||
if (modeRight) | |||||
break; | |||||
} | |||||
} | |||||
if (modeRight) | |||||
{ | |||||
free = true; | |||||
Thread.Sleep(200); | |||||
var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料)); | |||||
commProxy.SendData(data); | |||||
Thread.Sleep(200); | |||||
free = false; | |||||
new GSIceCream_EndCookEvent() { Id = DeviceId,Status =true}.Publish(); | |||||
MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]",MORKI_MODE.打料)); | |||||
} | |||||
else | |||||
{ | |||||
MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料",(MORKI_MODE)status["CurrentMode"])); | |||||
new GSIceCream_EndCookEvent() { Id = DeviceId,Status = false }.Publish(); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.GSIceCream 中引发错误,IceCreamMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
}); | |||||
} | } | ||||
} | } | ||||
@@ -1,130 +0,0 @@ | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.Message; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using static BPASmartClient.GSIceCream.MessageDefine; | |||||
namespace BPASmartClient.GSIceCream | |||||
{ | |||||
public class MorkIStatus | |||||
{ | |||||
private volatile static MorkIStatus _Instance; | |||||
public static MorkIStatus GetInstance() => _Instance ?? (_Instance = new MorkIStatus()); | |||||
private MorkIStatus() { } | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
/// <summary> | |||||
/// 是否在线 | |||||
/// </summary> | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
/// <summary> | |||||
/// 预冷温度 | |||||
/// </summary> | |||||
public short YLWD { get; set; } | |||||
/// <summary> | |||||
/// 回气温度 | |||||
/// </summary> | |||||
public short HQWD { get; set; } | |||||
/// <summary> | |||||
/// 环境温度 | |||||
/// </summary> | |||||
public short HJWD { get; set; } | |||||
/// <summary> | |||||
/// 电流 | |||||
/// </summary> | |||||
public short DL { get; set; } | |||||
/// <summary> | |||||
/// 电压 | |||||
/// </summary> | |||||
public short DY { get; set; } | |||||
/// <summary> | |||||
/// 当前模式 | |||||
/// </summary> | |||||
public MORKI_MODE CurrentMode { get; set; } | |||||
/// <summary> | |||||
/// 故障 | |||||
/// </summary> | |||||
public MORKI_FAULT Fault { get; set; } | |||||
/// <summary> | |||||
/// 成型比 | |||||
/// </summary> | |||||
public byte CXB { get; set; } | |||||
/// <summary> | |||||
/// 成型比(门限) | |||||
/// </summary> | |||||
public byte CXB_Threshold { get; set; } | |||||
/// <summary> | |||||
/// 打料完成(完成为true,正在打料为false) | |||||
/// </summary> | |||||
public bool DLCompleted { get; set; } | |||||
public bool CanDo | |||||
{ | |||||
get | |||||
{ | |||||
if (!OnLine) | |||||
return false; | |||||
if (Fault != MORKI_FAULT.未发生故障) | |||||
return false; | |||||
if (CXB < CXB_Threshold) | |||||
return false; | |||||
return true; | |||||
} | |||||
} | |||||
private void ProcessHeart(ICMSG_Heart_UP heartUpMsg) | |||||
{ | |||||
CurrentMode = heartUpMsg.MS; | |||||
YLWD = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L, heartUpMsg.YLWD_H }, 0); | |||||
HQWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L, heartUpMsg.HQWD_H }, 0); | |||||
HJWD = BitConverter.ToInt16(new byte[] { heartUpMsg.HJWD_L, heartUpMsg.HJWD_H }, 0); | |||||
DL = BitConverter.ToInt16(new byte[] { heartUpMsg.DL_L, heartUpMsg.DL_H }, 0); | |||||
Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0); | |||||
CXB = heartUpMsg.CXB; | |||||
DLCompleted = (heartUpMsg.DLTJ >> 4 & 1) == 1; | |||||
if (RTrig.GetInstance("打料完成检测").Start(DLCompleted)) | |||||
{ | |||||
MessageLog.GetInstance.Show("打料完成"); | |||||
} | |||||
if(RTrig.GetInstance("打料中检测").Start(!DLCompleted)) | |||||
{ | |||||
MessageLog.GetInstance.Show("打料中"); | |||||
} | |||||
} | |||||
private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg) | |||||
{ | |||||
MessageLog.GetInstance.Show(string.Format("模式返回为:{0}", modeUpMsg.Mode)); | |||||
} | |||||
public void ProcessMsg(byte[] data) | |||||
{ | |||||
lastRefreshTime = DateTime.Now; | |||||
try | |||||
{ | |||||
if (data.Length < 5) | |||||
return; | |||||
switch (data[2]) | |||||
{ | |||||
case (byte)IC_CMD.HEART: | |||||
var msg = IcPack.ByteToStructure<ICMSG_Heart_UP>(data.ToArray()); | |||||
ProcessHeart(msg); | |||||
break; | |||||
case (byte)IC_CMD.MODE: | |||||
var modeUp = IcPack.ByteToStructure<ICMSG_MODE_UP>(data.ToArray()); | |||||
ProcessModeUp(modeUp); | |||||
break; | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
@@ -1,4 +1,5 @@ | |||||
using System.Runtime.InteropServices; | |||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using System.Runtime.InteropServices; | |||||
using static BPASmartClient.GSIceCream.MessageDefine; | using static BPASmartClient.GSIceCream.MessageDefine; | ||||
namespace BPASmartClient.GSIceCream | namespace BPASmartClient.GSIceCream | ||||
@@ -5,7 +5,8 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | <ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -0,0 +1,36 @@ | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.SerialPort; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BPASmartClient.KLMCoffee | |||||
{ | |||||
public class CoffeeMachine | |||||
{ | |||||
//通讯代理 | |||||
SerialPortClient commProxy = null; | |||||
//数据仓库 | |||||
private DataStorage<byte> dataStorage = new DataStorage<byte>(); | |||||
//是否下发指令,主线程等待 | |||||
private bool free = false; | |||||
//状态询问指令 | |||||
private byte[] cmdAsk; | |||||
//串口COM口 | |||||
public string PortName { get; set; } | |||||
//串口波特率 | |||||
public string BaudRate { get; set; } | |||||
//心跳时间 | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
//是否在线 | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
public CoffeeMachine() | |||||
{ | |||||
} | |||||
} | |||||
} |
@@ -1,44 +0,0 @@ | |||||
using BPASmartClient.KLMCoffee.Protocal; | |||||
namespace BPASmartClient.KLMCoffee | |||||
{ | |||||
/// <summary> | |||||
/// 制作咖啡 | |||||
/// </summary> | |||||
public class MakeCoffeeEvent | |||||
{ | |||||
public DrinkType DrinkCode { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 取消制作 | |||||
/// </summary> | |||||
public class CancelMakeCoffeeEvent | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// 模式设置 | |||||
/// </summary> | |||||
public class CoffeeCommCmdEvent | |||||
{ | |||||
//public DrCoffeeCommCmd CommCmd { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 开始制作 | |||||
/// </summary> | |||||
public class CoffeBeginCook | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// 结束制作 | |||||
/// </summary> | |||||
public class CoffeEndCook | |||||
{ | |||||
} | |||||
} |
@@ -1,111 +0,0 @@ | |||||
using BPASmartClient.KLMCoffee.Protocal; | |||||
using BPASmartClient.MessageCommunication; | |||||
using BPASmartClient.MessageCommunication.MsgControl; | |||||
using BPASmartClient.SerialPort; | |||||
using System; | |||||
using System.Threading; | |||||
namespace BPASmartClient.KLMCoffee | |||||
{ | |||||
/// <summary> | |||||
/// 指令封装 | |||||
/// </summary> | |||||
internal class CommandHandler | |||||
{ | |||||
byte[] cmdAsk; | |||||
private SerialPortClient commProxy; | |||||
private K95Command drinksOrder = new K95Command(); | |||||
public Action<bool> PauseAsk { get; set; } | |||||
/// <summary> | |||||
/// 初始化 | |||||
/// </summary> | |||||
internal void Init(SerialPortClient commProxy) | |||||
{ | |||||
this.commProxy = commProxy; | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.KLMCoffee_MakeCoffee,"MakeCoffeeHandler"); | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.KLMCoffee_CancelMakeCoffee,"CancelMakeCoffeeHandler"); | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.KLMCoffee_CoffeeCommCmd,"CoffeeCommCmdHandler"); | |||||
} | |||||
///// <summary> | |||||
///// 制作咖啡 | |||||
///// </summary> | |||||
//public void MakeCoffeeHandler(object sender,InnerMessageEventArgs e) | |||||
//{ | |||||
// try | |||||
// { | |||||
// if (e.obj_MessageObj is MakeCoffeeEvent) | |||||
// { | |||||
// PauseAsk?.Invoke(true); | |||||
// Thread.Sleep(200); | |||||
// drinksOrder.ReturnsCommandData(K95CommandEnum.配方咖啡制作.GetString(),new new RecipeModel().Packe | |||||
// ); | |||||
// drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令; | |||||
// drinksOrder.DrinksCode = (DrCoffeeDrinksCode)int.Parse(e.obj_MessageObj.ToString()); | |||||
// commProxy.SendData(DrCoffee.Packe(drinksOrder)); | |||||
// Thread.Sleep(200); | |||||
// PauseAsk?.Invoke(false); | |||||
// } | |||||
// } | |||||
// catch (Exception ex) | |||||
// { | |||||
// MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CancelMakeCoffeeHandler 类,描述:[{ex.Message}]"); | |||||
// } | |||||
//} | |||||
///// <summary> | |||||
///// 取消制作 | |||||
///// </summary> | |||||
//public void CancelMakeCoffeeHandler(object sender,InnerMessageEventArgs e) | |||||
//{ | |||||
// try | |||||
// { | |||||
// PauseAsk?.Invoke(true); | |||||
// Thread.Sleep(200); | |||||
// drinksOrder.CommCmd = DrCoffeeCommCmd.取消应用指令; | |||||
// drinksOrder.DrinksCode = 0; | |||||
// commProxy.SendData(DrCoffee.Packe(drinksOrder)); | |||||
// Thread.Sleep(200); | |||||
// PauseAsk?.Invoke(false); | |||||
// } | |||||
// catch (Exception ex) | |||||
// { | |||||
// MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CancelMakeCoffeeHandler 类,描述:[{ex.Message}]"); | |||||
// } | |||||
//} | |||||
///// <summary> | |||||
///// 模式设置 | |||||
///// </summary> | |||||
///// <param name="sender"></param> | |||||
///// <param name="e"></param> | |||||
//public void CoffeeCommCmdHandler(object sender,InnerMessageEventArgs e) | |||||
//{ | |||||
// try | |||||
// { | |||||
// if (e.obj_MessageObj is string) | |||||
// { | |||||
// PauseAsk?.Invoke(true); | |||||
// Thread.Sleep(200); | |||||
// drinksOrder.CommCmd = (DrCoffeeCommCmd)int.Parse(e.obj_MessageObj.ToString()); | |||||
// commProxy.SendData(DrCoffee.Packe(drinksOrder)); | |||||
// Thread.Sleep(200); | |||||
// PauseAsk?.Invoke(false); | |||||
// } | |||||
// } | |||||
// catch (Exception ex) | |||||
// { | |||||
// MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeCommCmdHandler 类,描述:[{ex.Message}]"); | |||||
// } | |||||
//} | |||||
/// <summary> | |||||
/// 发送状态询问 | |||||
/// </summary> | |||||
internal byte[] GetStatusAsk() | |||||
{ | |||||
return cmdAsk; | |||||
} | |||||
} | |||||
} |
@@ -12,26 +12,32 @@ namespace BPASmartClient.KLMCoffee.Protocal | |||||
/// 系统状态 | /// 系统状态 | ||||
/// </summary> | /// </summary> | ||||
public K95SysTemStatus temStatus { get; set; } | public K95SysTemStatus temStatus { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 饮品类型 | /// 饮品类型 | ||||
/// </summary> | /// </summary> | ||||
public DrinkType drinkType { get; set; } | public DrinkType drinkType { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 制作状态 | /// 制作状态 | ||||
/// </summary> | /// </summary> | ||||
public MakeStatus makeStatus { get; set; } | public MakeStatus makeStatus { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 当前任务 | /// 当前任务 | ||||
/// </summary> | /// </summary> | ||||
public TaskIndex taskIndex { get; set; } | public TaskIndex taskIndex { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 当前进度 10% | /// 当前进度 10% | ||||
/// </summary> | /// </summary> | ||||
public int progress { get; set; } | public int progress { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 故障信息 | /// 故障信息 | ||||
/// </summary> | /// </summary> | ||||
public FaultMessage faultMessage { get; set; } | public FaultMessage faultMessage { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 保养信息 | /// 保养信息 | ||||
/// </summary> | /// </summary> | ||||
@@ -11,7 +11,7 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<Folder Include="机器人\" /> | |||||
<Folder Include="机器人\Enum\" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -4,7 +4,7 @@ using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace BPASmartClient.GSIceCream | |||||
namespace BPASmartClient.Model.冰淇淋.Enum | |||||
{ | { | ||||
/* | /* | ||||
* 模式 参数 | * 模式 参数 |
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
@@ -17,7 +18,7 @@ namespace BPASmartClient.Model | |||||
/// </summary> | /// </summary> | ||||
public class GSIceCream_ModeSetEvent :BaseEvent | public class GSIceCream_ModeSetEvent :BaseEvent | ||||
{ | { | ||||
public MORKI_MODE Mode { get; set; } | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -33,6 +34,9 @@ namespace BPASmartClient.Model | |||||
/// </summary> | /// </summary> | ||||
public class GSIceCream_EndCookEvent :BaseEvent | public class GSIceCream_EndCookEvent :BaseEvent | ||||
{ | { | ||||
/// <summary> | |||||
/// 状态:true 成功 false 失败 | |||||
/// </summary> | |||||
public bool Status { get; set; } | |||||
} | } | ||||
} | } |
@@ -4,7 +4,7 @@ using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace BPASmartClient.SCChip | |||||
namespace BPASmartClient.Model.单片机.Enum | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// 杯子 | /// 杯子 |
@@ -4,7 +4,7 @@ using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace BPASmartClient.SCChip | |||||
namespace BPASmartClient.Model.单片机.Enum | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// 冰淇淋舵机 | /// 冰淇淋舵机 |
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.单片机.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
@@ -17,7 +18,10 @@ namespace BPASmartClient.Model.单片机 | |||||
/// </summary> | /// </summary> | ||||
public class SCChip_TakeCupEvent :BaseEvent | public class SCChip_TakeCupEvent :BaseEvent | ||||
{ | { | ||||
/// <summary> | |||||
/// 杯 | |||||
/// </summary> | |||||
public IC_CUP Cup { get; set; } | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -25,7 +29,7 @@ namespace BPASmartClient.Model.单片机 | |||||
/// </summary> | /// </summary> | ||||
public class SCChip_MakeIceCreamEvent :BaseEvent | public class SCChip_MakeIceCreamEvent :BaseEvent | ||||
{ | { | ||||
public IC_SE SteeringEngine { get; set; } | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -33,7 +37,8 @@ namespace BPASmartClient.Model.单片机 | |||||
/// </summary> | /// </summary> | ||||
public class SCChip_SESwitchCreamEvent :BaseEvent | public class SCChip_SESwitchCreamEvent :BaseEvent | ||||
{ | { | ||||
public IC_SE SteeringEngine { get; set; } | |||||
public bool IsOpen { get; set; } | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -41,6 +46,6 @@ namespace BPASmartClient.Model.单片机 | |||||
/// </summary> | /// </summary> | ||||
public class SCChip_RotorSwitchEvent :BaseEvent | public class SCChip_RotorSwitchEvent :BaseEvent | ||||
{ | { | ||||
public bool TurnOn { get; set; } | |||||
} | } | ||||
} | } |
@@ -1,4 +1,5 @@ | |||||
using System; | |||||
using BPASmartClient.Model.咖啡机.Enum; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
@@ -17,6 +18,7 @@ namespace BPASmartClient.Model | |||||
/// </summary> | /// </summary> | ||||
public class DRCoffee_MakeCoffeeEvent :BaseEvent | public class DRCoffee_MakeCoffeeEvent :BaseEvent | ||||
{ | { | ||||
public DrCoffeeDrinksCode DrinkCode { get; set; } | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -32,7 +34,7 @@ namespace BPASmartClient.Model | |||||
/// </summary> | /// </summary> | ||||
public class DRCoffee_CoffeeCommCmdEvent :BaseEvent | public class DRCoffee_CoffeeCommCmdEvent :BaseEvent | ||||
{ | { | ||||
public DrCoffeeCommCmd CommCmd { get; set; } | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -4,12 +4,12 @@ using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace BPASmartClient.DRCoffee | |||||
namespace BPASmartClient.Model.咖啡机.Enum | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// 通信指令 | /// 通信指令 | ||||
/// </summary> | /// </summary> | ||||
public enum DrCoffeeCommCmd : byte | |||||
public enum DrCoffeeCommCmd :byte | |||||
{ | { | ||||
无指令 = 0x00, | 无指令 = 0x00, | ||||
饮品制作指令 = 0x01, | 饮品制作指令 = 0x01, |
@@ -4,12 +4,12 @@ using System.Linq; | |||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace BPASmartClient.DRCoffee | |||||
namespace BPASmartClient.Model.咖啡机.Enum | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// 饮品编号 | /// 饮品编号 | ||||
/// </summary> | /// </summary> | ||||
public enum DrCoffeeDrinksCode : byte | |||||
public enum DrCoffeeDrinksCode :byte | |||||
{ | { | ||||
意式浓缩 = 1, | 意式浓缩 = 1, | ||||
美式咖啡 = 2, | 美式咖啡 = 2, |
@@ -5,7 +5,7 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | |||||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | <ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | ||||
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | <ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -1,128 +0,0 @@ | |||||
using System; | |||||
namespace BPASmartClient.SCChip | |||||
{ | |||||
public class ChipStatus | |||||
{ | |||||
private volatile static ChipStatus _Instance; | |||||
public static ChipStatus GetInstance() => _Instance ?? (_Instance = new ChipStatus()); | |||||
private ChipStatus() { } | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
/// <summary> | |||||
/// 是否在线 | |||||
/// </summary> | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
/// <summary> | |||||
/// 取冰淇淋杯完成 | |||||
/// </summary> | |||||
public bool CompletedTake_CPU_CUP_ICECREAM { get; set; } | |||||
/// <summary> | |||||
/// 取咖啡杯完成 | |||||
/// </summary> | |||||
public bool CompletedTake_CPU_CUP_COFFEE { get; set; } | |||||
/// <summary> | |||||
/// 1号舵机打开完成 | |||||
/// </summary> | |||||
public bool CompletedOpen_SE_1 { get; set; } | |||||
/// <summary> | |||||
/// 2号舵机打开完成 | |||||
/// </summary> | |||||
public bool CompletedOpen_SE_2 { get; set; } | |||||
/// <summary> | |||||
/// 3号舵机打开完成 | |||||
/// </summary> | |||||
public bool CompletedOpen_SE_3 { get; set; } | |||||
/// <summary> | |||||
/// 1号舵机关闭完成 | |||||
/// </summary> | |||||
public bool CompletedClose_SE_1 { get; set; } | |||||
/// <summary> | |||||
/// 2号舵机关闭完成 | |||||
/// </summary> | |||||
public bool CompletedClose_SE_2 { get; set; } | |||||
/// <summary> | |||||
/// 3号舵机关闭完成 | |||||
/// </summary> | |||||
public bool CompletedClose_SE_3 { get; set; } | |||||
/// <summary> | |||||
/// 是否存在物品 | |||||
/// </summary> | |||||
public bool ArticleExits { get; set; } | |||||
/// <summary> | |||||
/// 物品距离 | |||||
/// </summary> | |||||
public byte ArticleDist { get; set; } | |||||
public bool CanDo | |||||
{ | |||||
get | |||||
{ | |||||
if (!OnLine) | |||||
return false; | |||||
return true; | |||||
} | |||||
} | |||||
public void ProcessMsg(ICChipPackage data) | |||||
{ | |||||
try | |||||
{ | |||||
switch (data.Cmd) | |||||
{ | |||||
case IC_CMD.HEART_BEAT: | |||||
lastRefreshTime = DateTime.Now; | |||||
break; | |||||
case IC_CMD.TAKE_CUP: | |||||
switch ((IC_CUP)data.Value) { | |||||
case IC_CUP.CUP_COFFEE: | |||||
CompletedTake_CPU_CUP_COFFEE = true; | |||||
break; | |||||
case IC_CUP.CUP_ICECREAM: | |||||
CompletedTake_CPU_CUP_ICECREAM = true; | |||||
break; | |||||
} | |||||
break; | |||||
case IC_CMD.OPEN_SE: | |||||
switch ((IC_SE)data.Value) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
CompletedOpen_SE_1 = true; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
CompletedOpen_SE_2 = true; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
CompletedOpen_SE_3 = true; | |||||
break; | |||||
} | |||||
break; | |||||
case IC_CMD.CLOSE_SE: | |||||
switch ((IC_SE)data.Value) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
CompletedClose_SE_1 = true; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
CompletedClose_SE_2 = true; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
CompletedClose_SE_3 = true; | |||||
break; | |||||
} | |||||
break; | |||||
case IC_CMD.ARTICLE_EXITS: | |||||
ArticleExits = data.Value > 0; | |||||
break; | |||||
case IC_CMD.ARTICLE_DIST: | |||||
ArticleDist = data.Value; | |||||
break; | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -1,42 +0,0 @@ | |||||
using BPASmartClient.SCChip; | |||||
namespace BPASmartClient.SCChip | |||||
{ | |||||
public class TakeCupEvent | |||||
{ | |||||
/// <summary> | |||||
/// 杯 | |||||
/// </summary> | |||||
public IC_CUP Cup { get; set; } | |||||
} | |||||
public class MakeIceCreamEvent | |||||
{ | |||||
public IC_SE SteeringEngine { get; set; } | |||||
} | |||||
public class SESwitchCreamEvent | |||||
{ | |||||
public IC_SE SteeringEngine { get; set; } | |||||
public bool IsOpen { get; set; } | |||||
} | |||||
public class RotorSwitchEvent | |||||
{ | |||||
public bool TurnOn { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 检测有无杯子 | |||||
/// </summary> | |||||
public class ArticleExitsEvent | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// 检测物品距离 | |||||
/// </summary> | |||||
public class ArticleDistEvent | |||||
{ | |||||
} | |||||
} |
@@ -1,225 +0,0 @@ | |||||
using BPASmartClient.Message; | |||||
using BPASmartClient.MessageCommunication; | |||||
using BPASmartClient.MessageCommunication.MsgControl; | |||||
using BPASmartClient.SerialPort; | |||||
using System; | |||||
using System.Runtime.InteropServices; | |||||
using System.Threading; | |||||
namespace BPASmartClient.SCChip | |||||
{ | |||||
/// <summary> | |||||
/// 指令封装 | |||||
/// </summary> | |||||
internal class CommandHandler | |||||
{ | |||||
private SerialPortClient commProxy; | |||||
private ICChipPackage package = new ICChipPackage(); | |||||
/// <summary> | |||||
/// 初始化 | |||||
/// </summary> | |||||
internal void Init(SerialPortClient commProxy) | |||||
{ | |||||
this.commProxy = commProxy; | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_TakeCup,"TakeCupHandler"); | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_MakeIceCream,"MakeIceCreamHandler"); | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_SESwitchCream,"SESwitchCreamHandler"); | |||||
Class_InnerMessageBus.GetInstance().ListenMessage(this,Class_MessageName.SCChip_RotorSwitch,"RotorSwitchHandler"); | |||||
} | |||||
/// <summary> | |||||
/// STM32F103RCT6单片机舵机打开或者关闭 | |||||
/// </summary> | |||||
public void SESwitchCreamHandler(object sender,InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (e.obj_MessageObj is TakeCupEvent) | |||||
{ | |||||
ChipStatus.GetInstance().ArticleDist = 0; | |||||
package.Cmd = (e.obj_MessageObj as SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE; | |||||
package.Value = (byte)(e.obj_MessageObj as SESwitchCreamEvent).SteeringEngine; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,SESwitchCreamHandler 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// STM32F103RCT6单片机控制冰淇淋机器转 | |||||
/// </summary> | |||||
public void RotorSwitchHandler(object sender,InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (e.obj_MessageObj is RotorSwitchEvent) | |||||
{ | |||||
package.Cmd = IC_CMD.ROTOR; | |||||
package.Value = (e.obj_MessageObj as RotorSwitchEvent).TurnOn ? (byte)IC_ROTOR.OPEN_ROTOR : (byte)IC_ROTOR.CLOSE_ROTOR; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,RotorSwitchHandler 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// STM32F103RCT6单片机舵机打料 | |||||
/// </summary> | |||||
public void MakeIceCreamHandler(object sender,InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (e.obj_MessageObj is MakeIceCreamEvent) | |||||
{ | |||||
switch ((e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
ChipStatus.GetInstance().CompletedOpen_SE_1 = false; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
ChipStatus.GetInstance().CompletedOpen_SE_2 = false; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
ChipStatus.GetInstance().CompletedOpen_SE_3 = false; | |||||
break; | |||||
} | |||||
package.Cmd = IC_CMD.OPEN_SE; | |||||
package.Value = (byte)(e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
bool wait = true; | |||||
DateTime waitTimeout = DateTime.Now.AddSeconds(3); | |||||
while (wait) | |||||
{ | |||||
wait = DateTime.Now < waitTimeout; | |||||
if (wait) | |||||
{ | |||||
switch ((e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
wait = !ChipStatus.GetInstance().CompletedOpen_SE_1; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
wait = !ChipStatus.GetInstance().CompletedOpen_SE_2; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
wait = !ChipStatus.GetInstance().CompletedOpen_SE_3; | |||||
break; | |||||
} | |||||
} | |||||
Thread.Sleep(10); | |||||
} | |||||
Thread.Sleep(2000); | |||||
package.Cmd = IC_CMD.CLOSE_SE; | |||||
package.Value = (byte)(e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
wait = true; | |||||
waitTimeout = DateTime.Now.AddSeconds(3); | |||||
while (wait) | |||||
{ | |||||
wait = DateTime.Now < waitTimeout; | |||||
if (wait) | |||||
{ | |||||
switch ((e.obj_MessageObj as MakeIceCreamEvent).SteeringEngine) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
wait = !ChipStatus.GetInstance().CompletedClose_SE_1; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
wait = !ChipStatus.GetInstance().CompletedClose_SE_2; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
wait = !ChipStatus.GetInstance().CompletedClose_SE_3; | |||||
break; | |||||
} | |||||
} | |||||
Thread.Sleep(10); | |||||
} | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,MakeIceCreamHandler 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// STM32F103RCT6单片机下杯 | |||||
/// </summary> | |||||
public void TakeCupHandler(object sender,InnerMessageEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
if (e.obj_MessageObj is TakeCupEvent) | |||||
{ | |||||
switch ((e.obj_MessageObj as TakeCupEvent).Cup) | |||||
{ | |||||
case IC_CUP.CUP_ICECREAM: | |||||
ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM = false; | |||||
break; | |||||
case IC_CUP.CUP_COFFEE: | |||||
ChipStatus.GetInstance().CompletedTake_CPU_CUP_COFFEE = false; | |||||
break; | |||||
} | |||||
package.Cmd = IC_CMD.TAKE_CUP; | |||||
package.Value = (byte)(e.obj_MessageObj as TakeCupEvent).Cup; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
bool wait = true; | |||||
var waitTimeout = DateTime.Now.AddSeconds(3); | |||||
while (wait) | |||||
{ | |||||
wait = DateTime.Now < waitTimeout; | |||||
if (wait) | |||||
{ | |||||
switch ((e.obj_MessageObj as TakeCupEvent).Cup) | |||||
{ | |||||
case IC_CUP.CUP_ICECREAM: | |||||
wait = !ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM; | |||||
break; | |||||
case IC_CUP.CUP_COFFEE: | |||||
wait = !ChipStatus.GetInstance().CompletedTake_CPU_CUP_COFFEE; | |||||
break; | |||||
} | |||||
} | |||||
Thread.Sleep(10); | |||||
} | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,TakeCupHandler 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | |||||
private byte[] StructureToByte(ICChipPackage structure) | |||||
{ | |||||
structure.Header = 0xAA; | |||||
structure.Sender = IC_SENDER.CONSOLE; | |||||
structure.End = 0xBB; | |||||
int size = Marshal.SizeOf(typeof(ICChipPackage)); | |||||
byte[] buffer = new byte[size]; | |||||
IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); | |||||
try | |||||
{ | |||||
Marshal.StructureToPtr(structure, bufferIntPtr, true); | |||||
Marshal.Copy(bufferIntPtr, buffer, 0, size); | |||||
} | |||||
finally | |||||
{ | |||||
Marshal.FreeHGlobal(bufferIntPtr); | |||||
} | |||||
return buffer; | |||||
} | |||||
} | |||||
} |
@@ -1,59 +1,86 @@ | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.EventBus; | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.Message; | |||||
using BPASmartClient.Model; | |||||
using BPASmartClient.Model.单片机; | |||||
using BPASmartClient.Model.单片机.Enum; | |||||
using BPASmartClient.Peripheral; | using BPASmartClient.Peripheral; | ||||
using BPASmartClient.SerialPort; | using BPASmartClient.SerialPort; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
using System.Threading; | using System.Threading; | ||||
using static BPASmartClient.EventBus.EventBus; | |||||
namespace BPASmartClient.SCChip | namespace BPASmartClient.SCChip | ||||
{ | { | ||||
public class ICChipMachine: BasePeripheral | |||||
public class ICChipMachine :BasePeripheral | |||||
{ | { | ||||
//指令组装 | |||||
private CommandHandler commandHandler = new CommandHandler(); | |||||
//通讯代理 | //通讯代理 | ||||
SerialPortClient commProxy = null; | SerialPortClient commProxy = null; | ||||
//数据仓库 | //数据仓库 | ||||
private DataStorage<byte> dataStorage = new DataStorage<byte>(); | private DataStorage<byte> dataStorage = new DataStorage<byte>(); | ||||
//主线程运行标识 | |||||
private bool running = false; | |||||
//是否下发指令,主线程等待 | |||||
public Action<string> SendCallback; | |||||
public Action<string> ReciveCallback; | |||||
/// <summary> | |||||
/// 串口COM口 | |||||
/// </summary> | |||||
//单片机基础协议 | |||||
private ICChipPackage package = new ICChipPackage(); | |||||
//串口COM口 | |||||
public string PortName { get; set; } | public string PortName { get; set; } | ||||
//串口波特率 | |||||
public string BaudRate { get; set; } | |||||
//心跳时间 | |||||
private DateTime lastRefreshTime = DateTime.MinValue; | |||||
/// <summary> | /// <summary> | ||||
/// 串口波特率 | |||||
/// 是否在线 | |||||
/// </summary> | /// </summary> | ||||
public string BaudRate { get; set; } | |||||
public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } } | |||||
public ICChipMachine() | public ICChipMachine() | ||||
{ | { | ||||
//commProxy = new SerialPortClient(portName, baud); | |||||
//commProxy.SetDataStorage(dataStorage); | |||||
//commandHandler.Init(commProxy); | |||||
} | } | ||||
/// <summary> | |||||
/// 主线程开始运行 | |||||
/// </summary> | |||||
public override void Start() | public override void Start() | ||||
{ | { | ||||
commProxy.Start(); | |||||
running = true; | |||||
MainLoop(); | |||||
try | |||||
{ | |||||
commProxy.Start(); | |||||
IsConnected = true; | |||||
MainLoop(); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | } | ||||
/// <summary> | |||||
/// 停止运行 | |||||
/// </summary> | |||||
public override void Stop() | |||||
{ | |||||
try | |||||
{ | |||||
commProxy.Stop(); | |||||
IsConnected = false; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 主循环,循环询问状态 | |||||
/// </summary> | |||||
private void MainLoop() | private void MainLoop() | ||||
{ | { | ||||
ThreadManage.GetInstance.StartLong(new Action(() => | ThreadManage.GetInstance.StartLong(new Action(() => | ||||
{ | { | ||||
ResolveMsg(); | ResolveMsg(); | ||||
//Thread.Sleep(2000); | |||||
}), "单片机解析线程"); | |||||
}),"单片机解析线程"); | |||||
} | } | ||||
private void ResolveMsg() | private void ResolveMsg() | ||||
@@ -74,7 +101,7 @@ namespace BPASmartClient.SCChip | |||||
if (temp[4] == 0xBB) | if (temp[4] == 0xBB) | ||||
{ | { | ||||
var package = ByteToStructure(temp.ToArray()); | var package = ByteToStructure(temp.ToArray()); | ||||
ChipStatus.GetInstance().ProcessMsg(package); | |||||
ProcessMsg(package); | |||||
} | } | ||||
temp.Clear(); | temp.Clear(); | ||||
} | } | ||||
@@ -93,8 +120,8 @@ namespace BPASmartClient.SCChip | |||||
IntPtr allocIntPtr = Marshal.AllocHGlobal(size); | IntPtr allocIntPtr = Marshal.AllocHGlobal(size); | ||||
try | try | ||||
{ | { | ||||
Marshal.Copy(dataBuffer, 0, allocIntPtr, size); | |||||
structure = (ICChipPackage)Marshal.PtrToStructure(allocIntPtr, typeof(ICChipPackage)); | |||||
Marshal.Copy(dataBuffer,0,allocIntPtr,size); | |||||
structure = (ICChipPackage)Marshal.PtrToStructure(allocIntPtr,typeof(ICChipPackage)); | |||||
} | } | ||||
finally | finally | ||||
{ | { | ||||
@@ -103,16 +130,254 @@ namespace BPASmartClient.SCChip | |||||
return structure; | return structure; | ||||
} | } | ||||
protected override void InitStatus() | |||||
private byte[] StructureToByte(ICChipPackage structure) | |||||
{ | { | ||||
structure.Header = 0xAA; | |||||
structure.Sender = IC_SENDER.CONSOLE; | |||||
structure.End = 0xBB; | |||||
int size = Marshal.SizeOf(typeof(ICChipPackage)); | |||||
byte[] buffer = new byte[size]; | |||||
IntPtr bufferIntPtr = Marshal.AllocHGlobal(size); | |||||
try | |||||
{ | |||||
Marshal.StructureToPtr(structure,bufferIntPtr,true); | |||||
Marshal.Copy(bufferIntPtr,buffer,0,size); | |||||
} | |||||
finally | |||||
{ | |||||
Marshal.FreeHGlobal(bufferIntPtr); | |||||
} | |||||
return buffer; | |||||
} | } | ||||
public override void Stop() | |||||
public void ProcessMsg(ICChipPackage data) | |||||
{ | |||||
try | |||||
{ | |||||
switch (data.Cmd) | |||||
{ | |||||
case IC_CMD.HEART_BEAT: | |||||
lastRefreshTime = DateTime.Now; | |||||
status["OnLine"] = OnLine; | |||||
break; | |||||
case IC_CMD.TAKE_CUP: | |||||
switch ((IC_CUP)data.Value) | |||||
{ | |||||
case IC_CUP.CUP_COFFEE: | |||||
status["CompletedTake_CPU_CUP_COFFEE"] = true; | |||||
break; | |||||
case IC_CUP.CUP_ICECREAM: | |||||
status["CompletedTake_CPU_CUP_ICECREAM"] = true; | |||||
break; | |||||
} | |||||
break; | |||||
case IC_CMD.OPEN_SE: | |||||
switch ((IC_SE)data.Value) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
status["CompletedOpen_SE_1"] = true; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
status["CompletedOpen_SE_2"] = true; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
status["CompletedOpen_SE_3"] = true; | |||||
break; | |||||
} | |||||
break; | |||||
case IC_CMD.CLOSE_SE: | |||||
switch ((IC_SE)data.Value) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
status["CompletedClose_SE_1"] = true; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
status["CompletedClose_SE_2"] = true; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
status["CompletedClose_SE_3"] = true; | |||||
break; | |||||
} | |||||
break; | |||||
} | |||||
if(!OnLine) IsWork = false; | |||||
else IsWork = true; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
protected override void InitStatus() | |||||
{ | { | ||||
status["CompletedTake_CPU_CUP_ICECREAM"] = false; | |||||
status["CompletedTake_CPU_CUP_COFFEE"] = false; | |||||
status["CompletedOpen_SE_1"] = false; | |||||
status["CompletedOpen_SE_2"] = false; | |||||
status["CompletedOpen_SE_3"] = false; | |||||
status["CompletedClose_SE_1"] = false; | |||||
status["CompletedClose_SE_2"] = false; | |||||
status["CompletedClose_SE_3"] = false; | |||||
} | } | ||||
public override void Init() | public override void Init() | ||||
{ | { | ||||
commProxy = new SerialPortClient(PortName,(BaudRates)Enum.Parse(typeof(BaudRates),BaudRate)); | |||||
commProxy.SetDataStorage(dataStorage); | |||||
//STM32F103RCT6单片机下杯 | |||||
EventBus.EventBus.GetInstance().Subscribe<SCChip_TakeCupEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) | |||||
{ | |||||
try | |||||
{ | |||||
switch ((@event as SCChip_TakeCupEvent).Cup) | |||||
{ | |||||
case IC_CUP.CUP_ICECREAM: | |||||
status["CompletedTake_CPU_CUP_ICECREAM"] = false; | |||||
break; | |||||
case IC_CUP.CUP_COFFEE: | |||||
status["CompletedTake_CPU_CUP_COFFEE"] = false; | |||||
break; | |||||
} | |||||
package.Cmd = IC_CMD.TAKE_CUP; | |||||
package.Value = (byte)(@event as SCChip_TakeCupEvent).Cup; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
bool wait = true; | |||||
var waitTimeout = DateTime.Now.AddSeconds(3); | |||||
while (wait) | |||||
{ | |||||
wait = DateTime.Now < waitTimeout; | |||||
if (wait) | |||||
{ | |||||
switch ((@event as SCChip_TakeCupEvent).Cup) | |||||
{ | |||||
case IC_CUP.CUP_ICECREAM: | |||||
wait = !(bool)status["CompletedTake_CPU_CUP_ICECREAM"]; | |||||
break; | |||||
case IC_CUP.CUP_COFFEE: | |||||
wait = !(bool)status["CompletedTake_CPU_CUP_COFFEE"]; | |||||
break; | |||||
} | |||||
} | |||||
Thread.Sleep(10); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
}); | |||||
//STM32F103RCT6单片机舵机打料 | |||||
EventBus.EventBus.GetInstance().Subscribe<SCChip_MakeIceCreamEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) | |||||
{ | |||||
try | |||||
{ | |||||
switch ((IC_SE)(@event as SCChip_MakeIceCreamEvent).SteeringEngine) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
status["CompletedOpen_SE_1"] = false; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
status["CompletedOpen_SE_2"] = false; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
status["CompletedOpen_SE_3"] = false; | |||||
break; | |||||
} | |||||
package.Cmd = IC_CMD.OPEN_SE; | |||||
package.Value = (byte)(@event as SCChip_MakeIceCreamEvent).SteeringEngine; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
bool wait = true; | |||||
DateTime waitTimeout = DateTime.Now.AddSeconds(3); | |||||
while (wait) | |||||
{ | |||||
wait = DateTime.Now < waitTimeout; | |||||
if (wait) | |||||
{ | |||||
switch ((IC_SE)(@event as SCChip_MakeIceCreamEvent).SteeringEngine) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
wait = !(bool)status["CompletedOpen_SE_1"]; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
wait = !(bool)status["CompletedOpen_SE_2"]; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
wait = !(bool)status["CompletedOpen_SE_3"]; | |||||
break; | |||||
} | |||||
} | |||||
Thread.Sleep(10); | |||||
} | |||||
Thread.Sleep(2000); | |||||
package.Cmd = IC_CMD.CLOSE_SE; | |||||
package.Value = (byte)(@event as SCChip_MakeIceCreamEvent).SteeringEngine; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
wait = true; | |||||
waitTimeout = DateTime.Now.AddSeconds(3); | |||||
while (wait) | |||||
{ | |||||
wait = DateTime.Now < waitTimeout; | |||||
if (wait) | |||||
{ | |||||
switch ((IC_SE)(@event as SCChip_MakeIceCreamEvent).SteeringEngine) | |||||
{ | |||||
case IC_SE.SE_1: | |||||
wait = !(bool)status["CompletedClose_SE_1"]; | |||||
break; | |||||
case IC_SE.SE_2: | |||||
wait = !(bool)status["CompletedClose_SE_2"]; | |||||
break; | |||||
case IC_SE.SE_3: | |||||
wait = !(bool)status["CompletedClose_SE_3"]; | |||||
break; | |||||
} | |||||
} | |||||
Thread.Sleep(10); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
}); | |||||
//STM32F103RCT6单片机舵机打开或者关闭 | |||||
EventBus.EventBus.GetInstance().Subscribe<SCChip_SESwitchCreamEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) | |||||
{ | |||||
try | |||||
{ | |||||
package.Cmd = (@event as SCChip_SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE; | |||||
package.Value = (byte)(@event as SCChip_SESwitchCreamEvent).SteeringEngine; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeCommCmdHandler 类,描述:[{ex.Message}]"); | |||||
} | |||||
}); | |||||
//STM32F103RCT6单片机控制冰淇淋机器转 | |||||
EventBus.EventBus.GetInstance().Subscribe<SCChip_RotorSwitchEvent>(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack) | |||||
{ | |||||
try | |||||
{ | |||||
package.Cmd = IC_CMD.ROTOR; | |||||
package.Value = (@event as SCChip_RotorSwitchEvent).TurnOn ? (byte)IC_ROTOR.OPEN_ROTOR : (byte)IC_ROTOR.CLOSE_ROTOR; | |||||
commProxy.SendData(StructureToByte(package)); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
MessageLog.GetInstance.Show($"BPASmartClient.SCChip 中引发错误,ICChipMachine 类,描述:[{ex.Message}]"); | |||||
} | |||||
}); | |||||
} | } | ||||
} | } | ||||
@@ -10,6 +10,6 @@ | |||||
<Grid> | <Grid> | ||||
<Button Content="Button" HorizontalAlignment="Left" Margin="153,123,0,0" VerticalAlignment="Top" Click="Button_Click"/> | <Button Content="Button" HorizontalAlignment="Left" Margin="153,123,0,0" VerticalAlignment="Top" Click="Button_Click"/> | ||||
<pry:IcoButton IcoText=""/> | |||||
<!--<pry:IcoButton IcoText=""/>--> | |||||
</Grid> | </Grid> | ||||
</Window> | </Window> |
@@ -1,6 +1,8 @@ | |||||
using BPASmartClient.Business; | using BPASmartClient.Business; | ||||
using BPASmartClient.EventBus; | using BPASmartClient.EventBus; | ||||
using BPASmartClient.Model; | using BPASmartClient.Model; | ||||
using BPASmartClient.Model.冰淇淋.Enum; | |||||
using BPASmartClient.Model.咖啡机.Enum; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
@@ -32,6 +34,9 @@ namespace BPASmartClient | |||||
private void Button_Click(object sender, RoutedEventArgs e) | private void Button_Click(object sender, RoutedEventArgs e) | ||||
{ | { | ||||
new Demo_MakeCoffeeEvent() { Id = "1" }.Publish(); | new Demo_MakeCoffeeEvent() { Id = "1" }.Publish(); | ||||
new DRCoffee_MakeCoffeeEvent() { Id = "1", DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish(); | |||||
new DRCoffee_CoffeeCommCmdEvent() { Id = "1",CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish(); | |||||
} | } | ||||
} | } | ||||
} | } |