Browse Source

tiaoshi

master
原川 张 2 years ago
parent
commit
0a78cad778
9 changed files with 266 additions and 145 deletions
  1. +43
    -9
      HBLConsole.MORKIC/Control_MORKIC.cs
  2. +2
    -2
      HBLConsole/App.config
  3. +15
    -0
      HBLConsole/View/DebugView.xaml
  4. +7
    -0
      HBLConsole/ViewModel/DebugViewModel.cs
  5. +85
    -37
      HBLDevice.Coffee/CoffeeMachine.cs
  6. +3
    -3
      HBLDevice.Coffee/MorkCStatus.cs
  7. +8
    -6
      HBLDevice.IceCream/CommandHandler.cs
  8. +100
    -86
      HBLDevice.IceCream/IceCreamMachine.cs
  9. +3
    -2
      HBLDevice.IceCream/MorkIStatus.cs

+ 43
- 9
HBLConsole.MORKIC/Control_MORKIC.cs View File

@@ -55,6 +55,24 @@ namespace HBLConsole.MORKIC
}
public void Init()
{
ActionOperate.GetInstance.Register(new Action(() =>
{
ThreadOperate.GetInstance.Start(new Action(()=>
{
DoIceCream();
}),"bqllllllll");
}), "bql");
ActionOperate.GetInstance.Register(new Action(() =>
{
ThreadOperate.GetInstance.Start(new Action(() =>
{
DoCoffee();
}), "cfjkkkkkkk");

}),"cfj");


mainMaterialLoc = "1";

//构建所有商品物料信息
@@ -79,7 +97,6 @@ namespace HBLConsole.MORKIC
coffeeMachine = new CoffeeMachine(com_Coffee, (BaudRates)Enum.Parse(typeof(BaudRates), baud_Coffee));
//冰淇淋机创建
iceCreamMachine = new IceCreamMachine(com_IceCream, (BaudRates)Enum.Parse(typeof(BaudRates), baud_IceCream));

Main();
ReadData();
}
@@ -152,9 +169,17 @@ namespace HBLConsole.MORKIC
//订单状态改变:开始制作
//SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
//todo:先调用机器人
LebaiHelper.GetInstance.Scene(10002);
ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(10002); }), "CCCCC");

while (!(lebai.Ok && lebai.Value == 2))
{
Thread.Sleep(5);
}
MessageLog.GetInstance.Show("机器人到达接咖啡口位置");
new MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish();
are.WaitOne(100 * 90);
are.WaitOne(1000 * 90);
MessageLog.GetInstance.Show("咖啡机制作咖啡完成");
LebaiHelper.GetInstance.SetValue(101);
//订单状态改变:完成
//SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_COOK);
@@ -168,8 +193,14 @@ namespace HBLConsole.MORKIC
//订单状态改变:开始制作
//SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
//todo:先调用机器人
LebaiHelper.GetInstance.Scene(10001);
ThreadOperate.GetInstance.Start(new Action(()=>{ LebaiHelper.GetInstance.Scene(10001); }),"CCCCC");

while (!(lebai.Ok&& lebai.Value==1))
{
Thread.Sleep(5);
}
new DischargeEvent().Publish();

//冰淇淋没有模式切换,强制等待10s
Thread.Sleep(10000);
LebaiHelper.GetInstance.SetValue(100);
@@ -185,7 +216,7 @@ namespace HBLConsole.MORKIC

private void IceCreamEndCookHandle(IEvent @event, EventBus.EventCallBackHandle callBack)
{
are.Set();
//are.Set();
}


@@ -195,6 +226,8 @@ namespace HBLConsole.MORKIC
coffeeMachine.Start();
//冰淇淋机开启主线程
iceCreamMachine.Start();
new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish();

//开始心跳刷新,根据咖啡机及冰淇淋机来判断
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
@@ -217,10 +250,11 @@ namespace HBLConsole.MORKIC

public void SimOrder<T>(T simOrder)
{
ThreadOperate.GetInstance.Start(new Action(() =>
{
DoIceCream();
}), "aaa");
//ThreadOperate.GetInstance.Start(new Action(() =>
//{
// DoIceCream();
// //DoCoffee();
//}), "aaa");

}
}


+ 2
- 2
HBLConsole/App.config View File

@@ -19,9 +19,9 @@
<add key="DeviceMS" value="成都银泰且时且多"/>

<add key="COM_Coffee" value=""/>
<add key="COM_Coffee" value="COM10"/>
<add key="BAUD_Coffee" value="115200"/>
<add key="COM_IceCream" value=""/>
<add key="COM_IceCream" value="COM12"/>
<add key="BAUD_IceCream" value="9600"/>
<add key="IceCream_CXB_Threshold" value="90"/>



+ 15
- 0
HBLConsole/View/DebugView.xaml View File

@@ -157,6 +157,7 @@
<RowDefinition Height="40" />
<RowDefinition Height="10" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>

@@ -243,7 +244,21 @@
Text="注意:【取面位置范围是:1 -- 5】, 【取浇头位置范围是:6 -- 10】, 【取碗位置范围是:11 -- 12】" />
</StackPanel>

<StackPanel Grid.Row="3" Orientation="Horizontal">
<Button
Margin="10,0,10,0"
Width="200"
Command="{Binding bql}"
Content="冰淇淋模拟"
Style="{StaticResource ButtonStyle}" />

<Button
Margin="10,0,10,0"
Width="200"
Command="{Binding cfj}"
Content="咖啡机模拟"
Style="{StaticResource ButtonStyle}" />
</StackPanel>





+ 7
- 0
HBLConsole/ViewModel/DebugViewModel.cs View File

@@ -23,6 +23,9 @@ namespace HBLConsole.ViewModel
public DebugViewModel()
{
WindowName = "调试模式";
bql = new RelayCommand(() => { ActionOperate.GetInstance.Send("bql"); });
cfj = new RelayCommand(() => { ActionOperate.GetInstance.Send("cfj"); });

SimOrderCommand = new RelayCommand(() =>
{
if (simOrderVisibleDatas.ElementAt(0).IsSelected)
@@ -86,6 +89,7 @@ namespace HBLConsole.ViewModel

static DebugViewModel()
{
simOrderVisibleDatas.Add(new SimOrderVisibleData() { Text = "取面位置:", IsEnable = false, IsSelected = true, Loc = 1 });
simOrderVisibleDatas.Add(new SimOrderVisibleData() { Text = "取浇头位置:", IsEnable = false, IsSelected = true, Loc = 6 });
simOrderVisibleDatas.Add(new SimOrderVisibleData() { Text = "取碗位置:", IsEnable = false, IsSelected = true, Loc = 11 });
@@ -103,6 +107,9 @@ namespace HBLConsole.ViewModel

public RelayCommand LoopSimOrderCommand { get; set; }

public RelayCommand bql { get; set; }
public RelayCommand cfj { get; set; }


public static ObservableCollection<SimOrderVisibleData> simOrderVisibleDatas { get; set; } = new ObservableCollection<SimOrderVisibleData>();



+ 85
- 37
HBLDevice.Coffee/CoffeeMachine.cs View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HBLConsole.Service;

namespace HBLDevice.Coffee
{
@@ -121,58 +122,105 @@ namespace HBLDevice.Coffee
/// </summary>
private void MainLoop()
{
Executer.GetInstance().Start(() =>
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
while (running)
if (free)
{
if (free)
{
commProxy.SendData(commandHandler.GetStatusAsk());
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetStatusAsk()));
}
Thread.Sleep(200);
commProxy.SendData(commandHandler.GetStatusAsk());
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetStatusAsk()));
}
}, "咖啡机询问线程");
Thread.Sleep(200);
}), "咖啡机询问线程");
//Executer.GetInstance().Start(() =>
//{
// while (running)
// {
// if (free)
// {
// commProxy.SendData(commandHandler.GetStatusAsk());
// SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetStatusAsk()));
// }
// Thread.Sleep(200);
// }
//}, "咖啡机询问线程");


Executer.GetInstance().Start(() =>
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
while (running)
List<byte> temp = new List<byte>();
//一系列解包
while (dataStorage.GetSize() > 0)
{
List<byte> temp = new List<byte>();
//一系列解包
while (dataStorage.GetSize() > 0)
byte item = dataStorage.GetData();
if (DrCoffee.HEADER == item)
{
byte item = dataStorage.GetData();
if (DrCoffee.HEADER == item)
if (temp.Count == DrCoffee.LENGTH - 1)
{
if (temp.Count == DrCoffee.LENGTH - 1)
{
temp.Add(item);
var package = DrCoffee.UnPack(temp.ToArray());
ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray()));
temp.Clear();
MorkCStatus.GetInstance().ProcessPackage(package);
}
else
{
temp.Clear();
temp.Add(item);
}
continue;
temp.Add(item);
var package = DrCoffee.UnPack(temp.ToArray());
ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray()));
temp.Clear();
MorkCStatus.GetInstance().ProcessPackage(package);
}
else
{
if (temp.Count == 1 && item != DrCoffee.LENGTH)
{
temp.Clear();
continue;
}
temp.Clear();
temp.Add(item);
}
continue;
}
else
{
if (temp.Count == 1 && item != DrCoffee.LENGTH)
{
temp.Clear();
continue;
}
temp.Add(item);
}
Thread.Sleep(5);
}
}, "咖啡机解析线程");
Thread.Sleep(5);
}), "咖啡机解析线程");

//Executer.GetInstance().Start(() =>
//{
// while (running)
// {
// List<byte> temp = new List<byte>();
// //一系列解包
// while (dataStorage.GetSize() > 0)
// {
// byte item = dataStorage.GetData();
// if (DrCoffee.HEADER == item)
// {
// if (temp.Count == DrCoffee.LENGTH - 1)
// {
// temp.Add(item);
// var package = DrCoffee.UnPack(temp.ToArray());
// ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray()));
// temp.Clear();
// MorkCStatus.GetInstance().ProcessPackage(package);
// }
// else
// {
// temp.Clear();
// temp.Add(item);
// }
// continue;
// }
// else
// {
// if (temp.Count == 1 && item != DrCoffee.LENGTH)
// {
// temp.Clear();
// continue;
// }
// temp.Add(item);
// }
// }
// Thread.Sleep(5);
// }
//}, "咖啡机解析线程");
}



+ 3
- 3
HBLDevice.Coffee/MorkCStatus.cs View File

@@ -9,7 +9,7 @@ namespace HBLDevice.Coffee
{
public class MorkCStatus : Singleton<MorkCStatus>
{
private CoffeBeginCook coffeBeginCook = new CoffeBeginCook();
private CoffeEndCook coffeEndCook = new CoffeEndCook();
private DateTime lastRefreshTime = DateTime.MinValue;
/// <summary>
/// 是否在线
@@ -52,10 +52,10 @@ namespace HBLDevice.Coffee
/// <param name="package"></param>
public void ProcessPackage(DrCoffeePackage package)
{
if (CoffeeStatus != DrCoffeeStatus.Running && package.Status == DrCoffeeStatus.Running)
if (CoffeeStatus == DrCoffeeStatus.Running && package.Status != DrCoffeeStatus.Running)
{
CoffeeStatus = package.Status;
coffeBeginCook.Publish();
coffeEndCook.Publish();
}
else {
CoffeeStatus = package.Status;


+ 8
- 6
HBLDevice.IceCream/CommandHandler.cs View File

@@ -1,5 +1,6 @@
using BPA.Utility;
using HBLConsole.Communication;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -43,19 +44,20 @@ namespace HBLDevice.IceCream
{
var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(((ModeSetEvent)@event).Mode));
commProxy.SendData(data);
Noticer.ShowEx(string.Format("设置模式[{0}]", ((ModeSetEvent)@event).Mode));
MessageLog.GetInstance.Show(string.Format("设置模式[{0}]", ((ModeSetEvent)@event).Mode));
}

public void DischargeEventHandle(IEvent @event, EventCallBackHandle callBack = null)
{
if (MorkIStatus.GetInstance().Fault != MORKI_FAULT.未发生故障)
{
Noticer.ShowEx(string.Format("当前存在故障[{0}%],不允许制作", MorkIStatus.GetInstance().Fault));
MessageLog.GetInstance.Show(string.Format("当前存在故障[{0}%],不允许制作", MorkIStatus.GetInstance().Fault));
return;
}
if (MorkIStatus.GetInstance().CXB <= 86)
{
Noticer.ShowEx(string.Format("当前成型比[{0}%],低于86%,不允许制作", MorkIStatus.GetInstance().CXB));
MessageLog.GetInstance.Show(string.Format("当前成型比[{0}%],低于86%,不允许制作", MorkIStatus.GetInstance().CXB));
return;
}

@@ -65,7 +67,7 @@ namespace HBLDevice.IceCream
{
var temp = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.制冷模式));
commProxy.SendData(temp);
Noticer.ShowEx(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.制冷模式));
MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.制冷模式));

DateTime freeTime = DateTime.Now.AddSeconds(5);
while (DateTime.Now < freeTime)
@@ -82,11 +84,11 @@ namespace HBLDevice.IceCream
var data = IcPack.StructureToByte(ICMSG_MODE_DW.Build(MORKI_MODE.打料));
commProxy.SendData(data);
iceCreamEndCook.Publish();
Noticer.ShowEx(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.打料));
MessageLog.GetInstance.Show(string.Format("出料操作->设置模式[{0}]", MORKI_MODE.打料));
}
else
{
Noticer.ShowEx(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料", MorkIStatus.GetInstance().CurrentMode));
MessageLog.GetInstance.Show(string.Format("出料操作->模式切换失败,当前模式[{0}],不允许出料", MorkIStatus.GetInstance().CurrentMode));
}
}
}


+ 100
- 86
HBLDevice.IceCream/IceCreamMachine.cs View File

@@ -4,10 +4,11 @@ using System;
using System.Collections.Generic;
using System.Threading;
using static HBLDevice.IceCream.MessageDefine;
using HBLConsole.Service;

namespace HBLDevice.IceCream
{
public class IceCreamMachine
public class IceCreamMachine
{
//指令组装
private CommandHandler commandHandler = new CommandHandler();
@@ -45,107 +46,120 @@ namespace HBLDevice.IceCream
private MSG_RESOLVE_STEP currentStep;
private void MainLoop()
{
Executer.GetInstance().Start(() =>
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
while (running)
{
commProxy.SendData(commandHandler.GetHeartDW());
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW()));
Thread.Sleep(2000);
}
}, "冰淇淋询问线程");
commProxy.SendData(commandHandler.GetHeartDW());
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW()));
Thread.Sleep(2000);
}), "冰淇淋询问线程");

Executer.GetInstance().Start(() =>
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
ResolveMsg();
}, "冰淇淋解析线程");
}
//Thread.Sleep(2000);
}), "冰淇淋解析线程");

//Executer.GetInstance().Start(() =>
//{
// while (running)
// {
// commProxy.SendData(commandHandler.GetHeartDW());
// SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW()));
// Thread.Sleep(2000);
// }
//}, "冰淇淋询问线程");

//Executer.GetInstance().Start(() =>
//{
// ResolveMsg();
//}, "冰淇淋解析线程");
}
int contentLength = 0;
int currentContentOffset = 0;
private void ResolveMsg()
{
int contentLength = 0;
int currentContentOffset = 0;
while (running)

//while (running)
//{
List<byte> temp = new List<byte>();
//一系列解包
while (dataStorage.GetSize() > 0)
{
List<byte> temp = new List<byte>();
//一系列解包
while (dataStorage.GetSize() > 0)
byte item = dataStorage.GetData();
switch (currentStep)
{
byte item = dataStorage.GetData();
switch (currentStep)
{
case MSG_RESOLVE_STEP.NONE:
if (item == MessageDefine.HEADER1)
{
temp.Add(item);
currentStep = MSG_RESOLVE_STEP.HEADER1;
continue;
}
break;
case MSG_RESOLVE_STEP.HEADER1:
if (item == MessageDefine.HEADER2_UP)
{
case MSG_RESOLVE_STEP.NONE:
if (item == MessageDefine.HEADER1)
{
temp.Add(item);
currentStep = MSG_RESOLVE_STEP.HEADER1;
continue;
}
break;
case MSG_RESOLVE_STEP.HEADER1:
if (item == MessageDefine.HEADER2_UP)
{
temp.Add(item);
currentStep = MSG_RESOLVE_STEP.HEADER2;
continue;
}
else
{
temp.Clear();
currentStep = MSG_RESOLVE_STEP.NONE;
continue;
}
case MSG_RESOLVE_STEP.HEADER2:
switch ((IC_CMD)item)
{
case IC_CMD.HEART:
temp.Add(item);
currentStep = MSG_RESOLVE_STEP.HEADER2;
continue;
}
else
{
contentLength = MessageDefine.MSG_LENGTH[(IC_CMD)item];
currentContentOffset = 0;
currentStep = MSG_RESOLVE_STEP.CMD;
break;
default:
temp.Clear();
currentStep = MSG_RESOLVE_STEP.NONE;
continue;
}
case MSG_RESOLVE_STEP.HEADER2:
switch ((IC_CMD)item)
{
case IC_CMD.HEART:
temp.Add(item);
contentLength = MessageDefine.MSG_LENGTH[(IC_CMD)item];
currentContentOffset = 0;
currentStep = MSG_RESOLVE_STEP.CMD;
break;
default:
temp.Clear();
currentStep = MSG_RESOLVE_STEP.NONE;
break;
}
break;
}
int retry = 3;
while (dataStorage.GetSize() < contentLength + 2 && retry >= 0)
{
retry--;
Thread.Sleep(100);
}
if (retry < 0)
{
currentStep = MSG_RESOLVE_STEP.NONE;
currentContentOffset = 0;
contentLength = 0;
continue;
}
while (currentContentOffset < contentLength)
{
item = dataStorage.GetData();
temp.Add(item);
currentContentOffset++;
}

retry = 3;
while (dataStorage.GetSize() < 2 && retry >= 0)
{
retry--;
Thread.Sleep(100);
}
temp.Add(dataStorage.GetData());
temp.Add(dataStorage.GetData());
ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray()));
MorkIStatus.GetInstance().ProcessMsg(temp.ToArray());
break;
}
break;
}
int retry = 3;
while (dataStorage.GetSize() < contentLength + 2 && retry >= 0)
{
retry--;
Thread.Sleep(100);
}
if (retry < 0)
{
currentStep = MSG_RESOLVE_STEP.NONE;
currentContentOffset = 0;
contentLength = 0;
continue;
}
Thread.Sleep(5);
while (currentContentOffset < contentLength)
{
item = dataStorage.GetData();
temp.Add(item);
currentContentOffset++;
}

retry = 3;
while (dataStorage.GetSize() < 2 && retry >= 0)
{
retry--;
Thread.Sleep(100);
}
temp.Add(dataStorage.GetData());
temp.Add(dataStorage.GetData());
ReciveCallback?.Invoke(BitConverter.ToString(temp.ToArray()));
MorkIStatus.GetInstance().ProcessMsg(temp.ToArray());
currentStep = MSG_RESOLVE_STEP.NONE;
continue;
}
Thread.Sleep(5);
//}
}
}



+ 3
- 2
HBLDevice.IceCream/MorkIStatus.cs View File

@@ -1,4 +1,5 @@
using BPA.Utility;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -76,12 +77,12 @@ namespace HBLDevice.IceCream
Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0);
CXB = heartUpMsg.CXB;

Noticer.ShowEx(string.Format("当前模式为:{0}", CurrentMode));
MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode));
}

private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg)
{
Noticer.ShowEx(string.Format("模式返回为:{0}", modeUpMsg.Mode));
MessageLog.GetInstance.Show(string.Format("模式返回为:{0}", modeUpMsg.Mode));
}

public void ProcessMsg(byte[] data)


Loading…
Cancel
Save