瀏覽代碼

修改IC

master
itachilee 2 年之前
父節點
當前提交
ec21cde147
共有 12 個文件被更改,包括 527 次插入135 次删除
  1. +1
    -1
      HBLConsole.Business/MessageServer/Base.cs
  2. +7
    -0
      HBLConsole.Communication/LebaiHelper.cs
  3. +232
    -79
      HBLConsole.Debug/Debug_MORKIC.xaml
  4. +2
    -0
      HBLConsole.Debug/HBLConsole.Debug.csproj
  5. +69
    -4
      HBLConsole.Debug/ViewModel/ViewModel_MORKIC.cs
  6. +103
    -33
      HBLConsole.MORKIC/Control_MORKIC.cs
  7. +10
    -8
      HBLConsole.MORKIC/PolymerBatching.cs
  8. +5
    -1
      HBLConsole.MainConsole/Main.cs
  9. +3
    -3
      HBLConsole/App.config
  10. +6
    -0
      HBLDevice.ICChip/CommandEvent.cs
  11. +87
    -3
      HBLDevice.ICChip/CommandHandler.cs
  12. +2
    -3
      HBLDevice.ICChip/ICChipMachine.cs

+ 1
- 1
HBLConsole.Business/MessageServer/Base.cs 查看文件

@@ -91,7 +91,7 @@ namespace HBLConsole.Business.MessageServer
MessageLog.GetInstance.Show("【物料信息】");
Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
{
MessageLog.GetInstance.Show($"{x.BatchingLoc}号位置:{x.BatchingCount}");
MessageLog.GetInstance.Show($"[{x.BatchingId}]{x.BatchingLoc}号位置:{x.BatchingCount}");
});
}



+ 7
- 0
HBLConsole.Communication/LebaiHelper.cs 查看文件

@@ -15,6 +15,13 @@ namespace HBLConsole.Communication
public class LebaiHelper
{

public const int SENCE_自嗨 = 10014;
public const int SENCE_接冰淇淋1 = 10008;
public const int SENCE_接冰淇淋2 = 10009;
public const int SENCE_接冰淇淋3 = 10013;
public const int SENCE_咖啡 = 10002;
public const int SENCE_欢迎 = 10015;

private volatile static LebaiHelper _Instance;
public static LebaiHelper GetInstance => _Instance ?? (_Instance = new LebaiHelper());
private LebaiHelper() { }


+ 232
- 79
HBLConsole.Debug/Debug_MORKIC.xaml 查看文件

@@ -18,6 +18,64 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style.xaml" />
<ResourceDictionary>
<!--#region ComboBox 样式-->
<!-- ComBoBox项选中背景色 -->
<SolidColorBrush x:Key="ComboBoxSelectdBackground" Color="#AA3ba7f2" />
<!-- ComBoBox项鼠标经过背景色 -->
<SolidColorBrush x:Key="ComboBoxMouseOverBackground" Color="#553ba7f2" />
<!-- ComBoBox项选中前景色 -->
<SolidColorBrush x:Key="ComboBoxSelectedForeground" Color="#DDD" />
<!-- ComBoBox项鼠标经过前景色 -->
<SolidColorBrush x:Key="ComboBoxMouseOverForegrond" Color="#DDD" />
<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
<Grid Height="25" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Border
Grid.ColumnSpan="2"
Background="White"
Opacity="0" />
<TextBlock
Grid.Column="1"
Margin="0,0,5,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontFamily="../Fonts/#iconfont"
FontSize="14"
Foreground="#FF23CACA"
Text="&#xe64d;" />
<!--<Path
x:Name="Arrow"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 6 6 12 0 Z"
Fill="#aa20FDFA"
Stretch="None">
<Path.Effect>
<DropShadowEffect
BlurRadius="10"
Direction="90"
Opacity="1"
RenderingBias="Quality"
ShadowDepth="0"
Color="#aa20FDFA" />
</Path.Effect>
</Path>-->
</Grid>
<!--<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="Arrow" Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" CenterX="6" CenterY="3" />
</Setter.Value>
</Setter>
<Setter TargetName="Arrow" Property="Margin" Value="0,0,0,2" />
</Trigger>
</ControlTemplate.Triggers>-->
</ControlTemplate>
<!--#region 按钮样式-->
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="#00c2f4" />
@@ -46,6 +104,145 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ComboBoxItem">
<Setter Property="Height" Value="25" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Border x:Name="_borderbg" Background="Transparent" />

<TextBlock
x:Name="_txt"
Margin="3,0,3,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#DDD"
Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" />

<Border
x:Name="_border"
Background="#103153"
Opacity="0" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="_txt" Property="Foreground" Value="{StaticResource ComboBoxSelectedForeground}" />
<Setter TargetName="_borderbg" Property="Background" Value="{StaticResource ComboBoxSelectdBackground}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="false" />
<Condition Property="IsMouseOver" Value="true" />
</MultiTrigger.Conditions>
<Setter TargetName="_borderbg" Property="Background" Value="{StaticResource ComboBoxMouseOverBackground}" />
<Setter TargetName="_txt" Property="Foreground" Value="{StaticResource ComboBoxMouseOverForegrond}" />
</MultiTrigger>

</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*" />
<ColumnDefinition Width="0.3*" MaxWidth="30" />
</Grid.ColumnDefinitions>
<Border
x:Name="_prybr"
Grid.Column="0"
Grid.ColumnSpan="2"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="0" />
<ContentPresenter
x:Name="ContentSite"
Margin="3,3,0,3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False" />

<!-- ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen -->
<ToggleButton
x:Name="ToggleButton"
Grid.Column="0"
Grid.ColumnSpan="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Template="{StaticResource ComboBoxToggleButton}" />
<!-- 必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它 -->
<TextBox
x:Name="PART_EditableTextBox"
Margin="2,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Focusable="True"
IsReadOnly="{TemplateBinding IsReadOnly}"
Visibility="Hidden" />

<!-- Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen -->
<Popup
x:Name="Popup"
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="Slide">
<Grid
x:Name="DropDown"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="150"
SnapsToDevicePixels="True">
<Border
x:Name="DropDownBorder"
BorderBrush="#3ba7f2"
BorderThickness="0" />
<ScrollViewer
Margin="1"
CanContentScroll="True"
HorizontalScrollBarVisibility="Auto"
SnapsToDevicePixels="True"
VerticalScrollBarVisibility="Auto">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<!-- 一下可以设置列表背景色 -->
<StackPanel
Background="#103153"
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="_prybr" Property="BorderBrush" Value="#aa3ba7f2" />
<!--<Setter Property="Background" Value="#553ba7f2" TargetName="_prybr"/>-->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--#endregion-->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
@@ -85,15 +282,16 @@
<Button
Width="130"
Margin="10,0,10,0"
Command="{Binding bql}"
Command="{s:Action SimIceCream}"
Content="冰淇淋模拟"
Style="{StaticResource ButtonStyle}" />

<Button
Width="130"
Margin="10,0,10,0"
Command="{Binding bql}"
Content="冰淇淋模拟"
s:View.ActionTarget="{Binding}"
Command="{s:Action SimCoffee}"
Content="咖啡模拟"
Style="{StaticResource ButtonStyle}" />
</StackPanel>
<StackPanel Grid.Row="1" Margin="0,10,0,0" Orientation="Vertical">
@@ -136,80 +334,32 @@
Foreground="Aqua"
Header=" 冰淇淋控制 "
Style="{DynamicResource GroupBoxStyle1}">
<Grid>

<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<StackPanel HorizontalAlignment="Right">
<TextBlock Text="预冷温度:" />
<TextBlock Text="环境温度:" />
<TextBlock HorizontalAlignment="Right" Text="电流:" />
<TextBlock HorizontalAlignment="Right" Text="成型比:" />
<TextBlock HorizontalAlignment="Right" Text="打料完成:" />
</StackPanel>

<StackPanel Grid.Column="1" Margin="10,0,0,0">
<TextBlock Text="{Binding YLWD}" />
<TextBlock Text="{Binding HJWD}" />
<TextBlock Text="{Binding DL}" />
<TextBlock Text="{Binding CXB}" />
<TextBlock Text="{Binding DLCompleted}" />
</StackPanel>

<StackPanel Grid.Column="2" HorizontalAlignment="Right">
<TextBlock Text="回气温度:" />
<TextBlock Text="当前模式:" />
<TextBlock HorizontalAlignment="Right" Text="电压:" />
<TextBlock HorizontalAlignment="Right" Text="故障:" />
</StackPanel>


<StackPanel Grid.Column="3" Margin="10,0,0,0">
<TextBlock Text="{Binding YLWD}" />
<TextBlock Text="{Binding HQWD}" />
<TextBlock Text="{Binding HJWD}" />
<TextBlock Text="{Binding YLWD}" />
</StackPanel>

</Grid>

<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
</Grid.RowDefinitions>

<StackPanel Margin="5,5" Orientation="Horizontal">
<Button
s:View.ActionTarget="{Binding}"
Command="{s:Action MakeIceCream}"
Content="开始制作"
Style="{StaticResource ButtonStyle}" />

<ComboBox
Width="150"
Margin="5"
ItemsSource="{Binding IceCreamModes}"
SelectedItem="{Binding SelecteIceCreamdMode}" />

<Button
s:View.ActionTarget="{Binding}"
Command="{s:Action SetIceCreamModel}"
Content="设置模式"
Style="{StaticResource ButtonStyle}" />
</StackPanel>
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="StackPanel">
<Setter Property="Margin" Value="5"></Setter>
</Style>
</StackPanel.Resources>

</Grid>
<StackPanel Orientation="Horizontal">
<Button Content="1号口开" s:View.ActionTarget="{Binding}" Command="{s:Action OpenSE1}" Style="{StaticResource ButtonStyle}"></Button>
<Button Content="1号口关" s:View.ActionTarget="{Binding}" Command="{s:Action CloseSE1}" Style="{StaticResource ButtonStyle}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="2号口开" s:View.ActionTarget="{Binding}" Command="{s:Action OpenSE2}" Style="{StaticResource ButtonStyle}"></Button>
<Button Content="2号口关" s:View.ActionTarget="{Binding}" Command="{s:Action CloseSE2}" Style="{StaticResource ButtonStyle}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="3号口开" s:View.ActionTarget="{Binding}" Command="{s:Action OpenSE3}" Style="{StaticResource ButtonStyle}"></Button>
<Button Content="3号口关" s:View.ActionTarget="{Binding}" Command="{s:Action CloseSE3}" Style="{StaticResource ButtonStyle}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="转筒转动" s:View.ActionTarget="{Binding}" Command="{s:Action TurnRoll}" Style="{StaticResource ButtonStyle}"></Button>
<Button Content="停止转筒转动" s:View.ActionTarget="{Binding}" Command="{s:Action StopTurnRoll}" Style="{StaticResource ButtonStyle}"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="完整制作流程" s:View.ActionTarget="{Binding}" Command="{s:Action MakeIceCreamBySE1}" Style="{StaticResource ButtonStyle}"></Button>
</StackPanel>

<!--<Grid.RowDefinitions>
<RowDefinition />
@@ -293,7 +443,7 @@
Content="设置" />
</StackPanel>
</StackPanel>-->
</Grid>
</StackPanel>
</GroupBox>
<!--#endregion-->

@@ -356,14 +506,16 @@
<ComboBox
Width="100"
ItemsSource="{Binding Coffees}"
SelectedItem="{Binding SelectedCoffee}" />
SelectedItem="{Binding SelectedCoffee}" Style="{DynamicResource ComboBoxStyle}" />
<Button
s:View.ActionTarget="{Binding}"
Command="{s:Action MakeCoffee}"
Style="{StaticResource ButtonStyle}"
Content="制作" />
<Button
s:View.ActionTarget="{Binding}"
Command="{s:Action StopMakeCoffee}"
Style="{StaticResource ButtonStyle}"
Content="停止制作" />
</StackPanel>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
@@ -371,10 +523,11 @@
<ComboBox
Width="100"
ItemsSource="{Binding CoffeeCmds}"
SelectedItem="{Binding SelectedCoffeeCmd}" />
SelectedItem="{Binding SelectedCoffeeCmd}" Style="{DynamicResource ComboBoxStyle}" />
<Button
s:View.ActionTarget="{Binding}"
Command="{s:Action SetCoffeeModel}"
Style="{StaticResource ButtonStyle}"
Content="设置" />
</StackPanel>
</StackPanel>


+ 2
- 0
HBLConsole.Debug/HBLConsole.Debug.csproj 查看文件

@@ -14,7 +14,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
<ProjectReference Include="..\HBLDevice.Coffee\HBLDevice.Coffee.csproj" />
<ProjectReference Include="..\HBLDevice.ICChip\HBLDevice.ICChip.csproj" />
<ProjectReference Include="..\HBLDevice.IceCream\HBLDevice.IceCream.csproj" />
</ItemGroup>



+ 69
- 4
HBLConsole.Debug/ViewModel/ViewModel_MORKIC.cs 查看文件

@@ -2,6 +2,7 @@
using HBLConsole.Communication;
using HBLConsole.Service;
using HBLDevice.Coffee;
using HBLDevice.ICChip;
using HBLDevice.IceCream;
using PropertyChanged;
using System;
@@ -10,6 +11,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HBLConsole.Service;

namespace HBLConsole.Debug
{
@@ -20,6 +22,20 @@ namespace HBLConsole.Debug
public string IceCreamConnected { get; set; }
public string CoffeeConnected { get; set; }

public void SimCoffee()
{
Task.Run(new Action(() =>
{
ActionOperate.GetInstance.Send("SimCoffee", (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee));
}));
}

public void SimIceCream()
{
ActionOperate.GetInstance.Send("SimIceCream");
}

#region 咖啡机
/// <summary>
/// 咖啡机状态
@@ -107,9 +123,9 @@ namespace HBLConsole.Debug

ThreadOperate.GetInstance.StartLong(new Action(() =>
{
RobotConnected = LebaiHelper.GetInstance.IsConnected?"已连接":"未连接";
IceCreamConnected = MorkIStatus.GetInstance().OnLine ? "已连接":"未连接";
CoffeeConnected = MorkCStatus.GetInstance().OnLine ? "已连接": "未连接";
RobotConnected = LebaiHelper.GetInstance.IsConnected ? "已连接" : "未连接";
IceCreamConnected = MorkIStatus.GetInstance().OnLine ? "已连接" : "未连接";
CoffeeConnected = MorkCStatus.GetInstance().OnLine ? "已连接" : "未连接";



@@ -126,7 +142,7 @@ namespace HBLConsole.Debug
CurrentMode = MorkIStatus.GetInstance().CurrentMode;
IceCreamFault = MorkIStatus.GetInstance().Fault;
CXB = MorkIStatus.GetInstance().CXB;
DLCompleted = MorkIStatus.GetInstance().DLCompleted?"打料完成":"打料中";
DLCompleted = MorkIStatus.GetInstance().DLCompleted ? "打料完成" : "打料中";
Thread.Sleep(500);
}), "MORK IC-状态刷新");
}
@@ -158,5 +174,54 @@ namespace HBLConsole.Debug
{
new CoffeeCommCmdEvent() { CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd) }.Publish();
}

public void OpenSE1()
{
new SESwitchCreamEvent() { SteeringEngine = IC_SE.SE_1, IsOpen = true }.Publish();
}

public void CloseSE1()
{
new SESwitchCreamEvent() { SteeringEngine = IC_SE.SE_1, IsOpen = false }.Publish();
}

public void OpenSE2()
{
new SESwitchCreamEvent() { SteeringEngine = IC_SE.SE_2, IsOpen = true }.Publish();

}

public void CloseSE2()
{
new SESwitchCreamEvent() { SteeringEngine = IC_SE.SE_2, IsOpen = false }.Publish();

}

public void OpenSE3()
{
new SESwitchCreamEvent() { SteeringEngine = IC_SE.SE_3, IsOpen = true }.Publish();

}

public void CloseSE3()
{
new SESwitchCreamEvent() { SteeringEngine = IC_SE.SE_3,IsOpen=false }.Publish();

}

public void TurnRoll()
{
new RotorSwitchEvent() { TurnOn = true }.Publish();
}

public void StopTurnRoll()
{
new RotorSwitchEvent() { TurnOn = false }.Publish();
}

public void MakeIceCreamBySE1()
{
new MakeIceCreamEvent() {SteeringEngine=IC_SE.SE_1 }.Publish();
}
}
}

+ 103
- 33
HBLConsole.MORKIC/Control_MORKIC.cs 查看文件

@@ -51,6 +51,10 @@ namespace HBLConsole.MORKIC
/// </summary>
SignalResult lebai = new SignalResult();

private bool enableFunny = false;
private DateTime lastRecvdOrder = DateTime.Now;
private bool working = false;

public void ConnectOk()
{

@@ -60,6 +64,16 @@ namespace HBLConsole.MORKIC
ConcurrentQueue<MorkOrderPush> morkOrderPushes = new ConcurrentQueue<MorkOrderPush>();
public void Init()
{

ActionOperate.GetInstance.Register(new Action<object>((s) =>
{
if (s is DrCoffeeDrinksCode cf)
{
mainMaterialLoc = ((int)cf).ToString();
DoCoffee();
}
}), "SimCoffee");

//构建所有商品物料信息
batchings = PolymerBatching.BuildAll();

@@ -87,15 +101,20 @@ namespace HBLConsole.MORKIC
//冰淇淋机创建
iceCreamMachine = new IceCreamMachine(com_IceCream, (BaudRates)Enum.Parse(typeof(BaudRates), baud_IceCream));
icchipMachine = new ICChipMachine(com_ICChip, (BaudRates)Enum.Parse(typeof(BaudRates), baud_ICChip));
Main();
ReadData();
Main();

ThreadOperate.GetInstance.StartLong(new Action(() =>
{
while (morkOrderPushes.Count > 0)
{
while (enableFunny) { Thread.Sleep(10); }
MessageLog.GetInstance.Show("当前非自嗨模式,允许开工");
working = true;
if (morkOrderPushes.TryDequeue(out MorkOrderPush order))
{
MessageLog.GetInstance.Show($"开始制作订单[{order.SortNum}]");

//Thread.Sleep(5000);
//SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_COOK);

@@ -139,12 +158,75 @@ namespace HBLConsole.MORKIC
break;
}
}
working = false;
lastRecvdOrder = DateTime.Now;
}
Thread.Sleep(1000);
}), "订单制作");
}

public void Main()
{
//咖啡机开启主线程
coffeeMachine.Start();
//冰淇淋机开启主线程
iceCreamMachine.Start();
icchipMachine.Start();
new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish();

//开始心跳刷新,根据咖啡机及冰淇淋机来判断
ThreadOperate.GetInstance.StartLong(new Action(() =>
{

//GeneralConfig.Healthy = true;
//GeneralConfig.Healthy =
// LebaiHelper.GetInstance.IsConnected &&
// MorkIStatus.GetInstance().CanDo &&
// MorkCStatus.GetInstance().CanDo;
GeneralConfig.Healthy =
LebaiHelper.GetInstance.IsConnected &&
MorkCStatus.GetInstance().CanDo;
//GeneralConfig.Healthy = true;
Thread.Sleep(100);
}), "MORK-IC心跳刷新");
ThreadOperate.GetInstance.Start(new Action(() =>
{
while (!LebaiHelper.GetInstance.IsConnected) {
Thread.Sleep(10);
}
LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_欢迎);
}), "MORK-IC欢迎");
//ThreadOperate.GetInstance.StartLong(new Action(() =>
//{
// if (null != lebai)
// {
// if (!working)
// {
// if (DateTime.Now.Subtract(lastRecvdOrder).TotalSeconds >= 30)
// {
// MessageLog.GetInstance.Show("进入自嗨模式");
// enableFunny = true;
// //ThreadOperate.GetInstance.Start(new Action(() =>
// //{
// //}), "调用乐百机器人做咖啡场景");


// LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_自嗨);
// Thread.Sleep(2000);
// while (lebai.Ok && lebai.Value != 10)
// {
// Thread.Sleep(5);
// }

// enableFunny = false;
// MessageLog.GetInstance.Show("退出自嗨模式");
// Thread.Sleep(60*1000);
// }
// }
// }
// Thread.Sleep(100);
//}), "MORK-IC自嗨");
}

public void DataParse<T>(T order)
{
@@ -172,19 +254,25 @@ namespace HBLConsole.MORKIC
/// </summary>
private void DoCoffee()
{
are.Reset();
LebaiHelper.GetInstance.SetValue(0);
//订单状态改变:开始制作
SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
//todo:先调用机器人

LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_咖啡);
//ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_咖啡); }), "调用乐百机器人做咖啡场景");
Thread.Sleep(2000);

ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(10002); }), "调用乐百机器人做咖啡场景");
while (!(lebai.Ok && lebai.Value == 1))
{
Thread.Sleep(5);
}
//todo:咖啡杯下杯
new TakeCupEvent() { Cup = IC_CUP.CUP_COFFEE }.Publish();
while (!ChipStatus.GetInstance().CompletedTake_CPU_CUP_COFFEE) { Thread.Sleep(5); }
Thread.Sleep(500);

//while (!ChipStatus.GetInstance().CompletedTake_CPU_CUP_COFFEE) { Thread.Sleep(5); }
MessageLog.GetInstance.Show("咖啡杯取杯完成");
LebaiHelper.GetInstance.SetValue(100);

@@ -196,6 +284,8 @@ namespace HBLConsole.MORKIC
MessageLog.GetInstance.Show("机器人到达接咖啡口位置");
new MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)int.Parse(mainMaterialLoc) }.Publish();
are.WaitOne(1000 * 180);

//are.WaitOne(1 * 180);
MessageLog.GetInstance.Show("咖啡机制作咖啡完成");
LebaiHelper.GetInstance.SetValue(101);
while (!(lebai.Ok && lebai.Value == 3))
@@ -212,21 +302,25 @@ namespace HBLConsole.MORKIC
/// </summary>
private void DoIceCream()
{
LebaiHelper.GetInstance.SetValue(0);
new RotorSwitchEvent() { TurnOn = true }.Publish();
int scene = 10009;
int scene = LebaiHelper.SENCE_接冰淇淋2;
var se = IC_SE.SE_2;
se = PolymerBatching.GetIceCreamSE(mainMaterialLoc, out scene);

//订单状态改变:开始制作
SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
//todo:先调用机器人
ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(scene); }), "调用乐百机器人做冰淇淋场景");

LebaiHelper.GetInstance.Scene(scene);
MessageLog.GetInstance.Show("调用乐百机器人做冰淇淋场景");
Thread.Sleep(2000);
while (!(lebai.Ok && lebai.Value == 1))
{
Thread.Sleep(5);
}
new TakeCupEvent() { Cup = IC_CUP.CUP_ICECREAM }.Publish();
while (!ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM) { Thread.Sleep(5); }
Thread.Sleep(500);
//while (!ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM) { Thread.Sleep(5); }
LebaiHelper.GetInstance.SetValue(100);

while (!(lebai.Ok && lebai.Value == 2))
@@ -234,10 +328,11 @@ namespace HBLConsole.MORKIC
Thread.Sleep(5);
}
new MakeIceCreamEvent() { SteeringEngine = se }.Publish();
Thread.Sleep(1000);
LebaiHelper.GetInstance.SetValue(101);
new RotorSwitchEvent() { TurnOn = false }.Publish();

while (!(lebai.Ok && lebai.Value ==3))
while (!(lebai.Ok && lebai.Value == 3))
{
Thread.Sleep(5);
}
@@ -249,32 +344,7 @@ namespace HBLConsole.MORKIC
are.Set();
}

public void Main()
{
//咖啡机开启主线程
coffeeMachine.Start();
//冰淇淋机开启主线程
iceCreamMachine.Start();
icchipMachine.Start();
new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish();

//开始心跳刷新,根据咖啡机及冰淇淋机来判断
ThreadOperate.GetInstance.StartLong(new Action(() =>
{

//GeneralConfig.Healthy = true;
//GeneralConfig.Healthy =
// LebaiHelper.GetInstance.IsConnected &&
// MorkIStatus.GetInstance().CanDo &&
// MorkCStatus.GetInstance().CanDo;
GeneralConfig.Healthy =
LebaiHelper.GetInstance.IsConnected &&
MorkCStatus.GetInstance().CanDo;
GeneralConfig.Healthy = true;
Thread.Sleep(100);
}), "MORK-IC心跳刷新");

}


public void ReadData()


+ 10
- 8
HBLConsole.MORKIC/PolymerBatching.cs 查看文件

@@ -1,4 +1,5 @@
using HBLDevice.ICChip;
using HBLConsole.Communication;
using HBLDevice.ICChip;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -25,6 +26,8 @@ namespace HBLConsole.MORKIC
internal const string ICE_MAIN_BATCHIN1_LOC = "52";
internal const string ICE_MAIN_BATCHIN2_LOC = "53";
internal const string ICE_MAIN_BATCHIN3_LOC = "54";
internal const string COFFEE_HOLDER_LOC = "30";
internal const string ICE_HOLDER_LOC = "51";
public static Dictionary<string, GOODS_TYPE> GOODS_TYPES = new Dictionary<string, GOODS_TYPE>() {
{"1", GOODS_TYPE.COFFEE},
{"2", GOODS_TYPE.COFFEE},
@@ -72,9 +75,8 @@ namespace HBLConsole.MORKIC
GoodsType = GOODS_TYPES[loc];
switch (loc)
{
case "30":
case "51":
case "52":
case COFFEE_HOLDER_LOC:
case ICE_HOLDER_LOC:
BatchingClass = BATCHING_CLASS.HOLDER;
break;
default:
@@ -99,16 +101,16 @@ namespace HBLConsole.MORKIC
switch (loc)
{
case ICE_MAIN_BATCHIN1_LOC:
sence = 10008;
sence = LebaiHelper.SENCE_接冰淇淋1;
return IC_SE.SE_1;
case ICE_MAIN_BATCHIN2_LOC:
sence = 10013;
sence = LebaiHelper.SENCE_接冰淇淋3;
return IC_SE.SE_3;
case ICE_MAIN_BATCHIN3_LOC:
sence = 10009;
sence = LebaiHelper.SENCE_接冰淇淋2;
return IC_SE.SE_2;
default:
sence = 10011;
sence = LebaiHelper.SENCE_接冰淇淋2;
return IC_SE.SE_2;
}
}


+ 5
- 1
HBLConsole.MainConsole/Main.cs 查看文件

@@ -65,15 +65,19 @@ namespace HBLConsole.MainConsole
{
ThreadOperate.GetInstance.Start(new Action(() =>
{
SimpleFactory.GetInstance.DeviceInit();//设备初始化

InternetInfo.ConfigInit();//从 consul 获取配置数据
Topics.Clear();
Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));


//MQTT 连接成功
MqttHelper.GetInstance.ConnectOk = new Action(() =>
{
SimpleFactory.GetInstance.DeviceInit();//设备初始化
//SimpleFactory.GetInstance.DeviceInit();//设备初始化

MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅



+ 3
- 3
HBLConsole/App.config 查看文件

@@ -4,14 +4,14 @@
<!--通用配置-->

<!--测试服务 Consul 地址-->
<add key="ConsulAddress" value="http://114.117.161.250:9011" />
<add key="ConsulAddress" value="http://1.14.74.54" />

<!--正式服务 Consul 地址-->
<!--<add key="ConsulAddress" value="http://162.14.105.138:9005" />-->

<!--客户端ID-->
<!--MorkD = 2,MorkS 且时且多 = 8,MorkS 珠海 = 9,冰淇淋 = 4,咖啡机 = 13-->
<add key="ClientId" value="4"/>
<add key="ClientId" value="5"/>
<!--IOT大屏上报-->
<add key="ProductKey" value="grgpECHSL7q"/>
<add key="DeviceName" value="test"/>
@@ -24,7 +24,7 @@
<add key="COM_IceCream" value="COM5"/>
<add key="BAUD_IceCream" value="9600"/>
<add key="IceCream_CXB_Threshold" value="90"/>
<add key="COM_ICChip" value="COM10"/>
<add key="COM_ICChip" value="COM11"/>
<add key="BAUD_IChip" value="9600"/>

</appSettings>

+ 6
- 0
HBLDevice.ICChip/CommandEvent.cs 查看文件

@@ -20,6 +20,12 @@ namespace HBLDevice.ICChip
public IC_SE SteeringEngine { get; set; }
}

public class SESwitchCreamEvent : IEvent
{
public IC_SE SteeringEngine { get; set; }
public bool IsOpen { get; set; }
}

public class RotorSwitchEvent : IEvent
{
public bool TurnOn { get; set; }


+ 87
- 3
HBLDevice.ICChip/CommandHandler.cs 查看文件

@@ -28,27 +28,91 @@ namespace HBLDevice.ICChip
this.commProxy = commProxy;
EventBus.GetInstance().Subscribe<TakeCupEvent>(TakeCupEventHandle);
EventBus.GetInstance().Subscribe<MakeIceCreamEvent>(MakeIceCreamEventHandle);
EventBus.GetInstance().Subscribe<SESwitchCreamEvent>(StopMakeIceCreamEventHandle);
EventBus.GetInstance().Subscribe<RotorSwitchEvent>(RotorSwitchEventHandle);
}

private void StopMakeIceCreamEventHandle(IEvent @event, EventCallBackHandle callBack)
{
package.Cmd = (@event as SESwitchCreamEvent).IsOpen ? IC_CMD.OPEN_SE : IC_CMD.CLOSE_SE;
package.Value = (byte)(@event as SESwitchCreamEvent).SteeringEngine;
commProxy.SendData(StructureToByte(package));
}

private void RotorSwitchEventHandle(IEvent @event, EventCallBackHandle callBack)
{
package.Cmd = IC_CMD.ROTOR;
package.Value = (@event as RotorSwitchEvent).TurnOn ? (byte)IC_ROTOR.OPEN_ROTOR : (byte)IC_ROTOR.OPEN_ROTOR;
package.Value = (@event as RotorSwitchEvent).TurnOn ? (byte)IC_ROTOR.OPEN_ROTOR : (byte)IC_ROTOR.CLOSE_ROTOR;
commProxy.SendData(StructureToByte(package));
}

private void MakeIceCreamEventHandle(IEvent @event, EventCallBackHandle callBack)
{
switch ((@event 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)(@event as MakeIceCreamEvent).SteeringEngine;
commProxy.SendData(StructureToByte(package));

Thread.Sleep(3000);

bool wait = true;
DateTime waitTimeout = DateTime.Now.AddSeconds(3);
while (wait)
{
wait = DateTime.Now < waitTimeout;
if (wait)
{
switch ((@event 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(1000);
package.Cmd = IC_CMD.CLOSE_SE;
package.Value = (byte)(@event as MakeIceCreamEvent).SteeringEngine;
commProxy.SendData(StructureToByte(package));

wait = true;
waitTimeout = DateTime.Now.AddSeconds(3);
while (wait)
{
wait = DateTime.Now < waitTimeout;
if (wait)
{
switch ((@event 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);
}
}

private void TakeCupEventHandle(IEvent @event, EventCallBackHandle callBack)
@@ -65,6 +129,26 @@ namespace HBLDevice.ICChip
package.Cmd = IC_CMD.TAKE_CUP;
package.Value = (byte)(@event 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 ((@event 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);
}
}




+ 2
- 3
HBLDevice.ICChip/ICChipMachine.cs 查看文件

@@ -48,10 +48,9 @@ namespace HBLDevice.ICChip
{
ResolveMsg();
//Thread.Sleep(2000);
}), "冰淇淋解析线程");
}), "单片机解析线程");
}
int contentLength = 0;
int currentContentOffset = 0;

private void ResolveMsg()
{
List<byte> temp = new List<byte>();


Loading…
取消
儲存