itachilee 2 years ago
parent
commit
a32c14074c
34 changed files with 851 additions and 123 deletions
  1. +9
    -3
      HBLConsole.Business/AlarmHelper.cs
  2. +1
    -0
      HBLConsole.MORKD/Alarm_MORKD.cs
  3. +1
    -21
      HBLConsole.MORKD/Control_MORKD.cs
  4. +14
    -13
      HBLConsole.MORKIC/Control_MORKIC.cs
  5. +1
    -0
      HBLConsole.MORKIC/HBLConsole.MORKIC.csproj
  6. +14
    -7
      HBLConsole.MainConsole/Main.cs
  7. +9
    -0
      HBLConsole.Model/ViewModel/Alarm.cs
  8. +4
    -4
      HBLConsole.Model/ViewModel/SimOrderVisibleData.cs
  9. +5
    -2
      HBLConsole.Service/Json.cs
  10. +24
    -0
      HBLConsole.Service/TextHelper.cs
  11. +8
    -1
      HBLConsole.sln
  12. +2
    -0
      HBLConsole/App.config
  13. +2
    -1
      HBLConsole/App.xaml.cs
  14. +4
    -1
      HBLConsole/DialogWindow/View/SimOrderConfitView.xaml
  15. +17
    -3
      HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs
  16. +46
    -11
      HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs
  17. +2
    -2
      HBLConsole/View/AlarmView.xaml
  18. +29
    -16
      HBLConsole/View/DebugView.xaml
  19. +1
    -1
      HBLConsole/View/MainView.xaml
  20. +3
    -11
      HBLConsole/ViewModel/AlarmViewModel.cs
  21. +36
    -10
      HBLConsole/ViewModel/DebugViewModel.cs
  22. +49
    -14
      HBLConsole/ViewModel/MainViewModel.cs
  23. +2
    -2
      HBLConsole/ViewModel/ViewModelBase.cs
  24. +116
    -0
      HBLDevice.ICChip/ChipStatus.cs
  25. +22
    -0
      HBLDevice.ICChip/CommandEvent.cs
  26. +149
    -0
      HBLDevice.ICChip/CommandHandler.cs
  27. +17
    -0
      HBLDevice.ICChip/HBLDevice.ICChip.csproj
  28. +102
    -0
      HBLDevice.ICChip/ICChipMachine.cs
  29. +37
    -0
      HBLDevice.ICChip/Protocal/ICChipPackage.cs
  30. +35
    -0
      HBLDevice.ICChip/Protocal/IC_CMD.cs
  31. +23
    -0
      HBLDevice.ICChip/Protocal/IC_CUP.cs
  32. +27
    -0
      HBLDevice.ICChip/Protocal/IC_SE.cs
  33. +23
    -0
      HBLDevice.ICChip/Protocal/IC_SENDER.cs
  34. +17
    -0
      HBLDevice.IceCreamV1/HBLDevice.ICChip.csproj

+ 9
- 3
HBLConsole.Business/AlarmHelper.cs View File

@@ -36,7 +36,7 @@ namespace HBLConsole.Business
{
if (edgeType == AlarmTriggerType.Rising ? !flagbit[text] : flagbit[text])
{
AddAlarm(text, alarmLevel);
AddAlarm(Trigger, text, alarmLevel);
flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false;
}
}
@@ -51,16 +51,18 @@ namespace HBLConsole.Business
/// 添加报警信息
/// </summary>
/// <param name="AlarmInfo">报警信息</param>
private void AddAlarm(string AlarmInfo, AlarmLevel alarmLevel)
private void AddAlarm(object value, string AlarmInfo, AlarmLevel alarmLevel)
{
Alarm tempAlarm = new Alarm()
{
NumId = Alarms.Count,
Date = DateTime.Now.ToString("yyyy/MM/dd"),
Grade = alarmLevel.ToString(),
Info = AlarmInfo,
Value = value.ToString(),
Time = DateTime.Now.ToString("HH:mm:ss"),
};
Sqlite<Alarm>.GetInstance.Add(tempAlarm);
Sqlite<Alarm>.GetInstance.Base.Add(tempAlarm);

if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null)
{
@@ -80,6 +82,10 @@ namespace HBLConsole.Business
if (result != null)
{
Alarms.Remove(result);
for (int i = 0; i < Alarms.Count; i++)
{
Alarms.ElementAt(i).NumId = i + 1;
}
if (RemoveAction != null) RemoveAction(AlarmInfo);
if (ChangeAction != null) ChangeAction();
}


+ 1
- 0
HBLConsole.MORKD/Alarm_MORKD.cs View File

@@ -13,5 +13,6 @@ namespace HBLConsole.MORKD
/// </summary>
public class Alarm_MORKD : IAlarm
{

}
}

+ 1
- 21
HBLConsole.MORKD/Control_MORKD.cs View File

@@ -15,22 +15,6 @@ namespace HBLConsole.MORKD
{
public class Control_MORKD : IControl
{
#region 单例模式
//private static Control_MORKD _instance;
//public static Control_MORKD Instance
//{
// get
// {
// if (_instance == null)
// _instance = new Control_MORKD();
// return _instance;
// }
//}
//public Control_MORKD()
//{

//}
#endregion
GVL_MORKD mORKD = new GVL_MORKD();
Alarm_MORKD alarm = new Alarm_MORKD();
public void ConnectOk()
@@ -40,11 +24,6 @@ namespace HBLConsole.MORKD
ResetProgram();
}

//public object GetT()
//{
// return mORKD;
//}

public void DataParse<T>(T order)
{
if (order is MorkOrderPush morkOrderPush)
@@ -77,6 +56,7 @@ namespace HBLConsole.MORKD
public void Init()
{
ActionOperate.GetInstance.Register(new Action(() => { mORKD.InitControl(); }), "InitCommand");

}

bool Initing = false;


+ 14
- 13
HBLConsole.MORKIC/Control_MORKIC.cs View File

@@ -17,6 +17,8 @@ using Robotc;
using System.Collections.Concurrent;
using System.Diagnostics;
using BPA.Message.IOT;
using HBLDevice.ICChip;

namespace HBLConsole.MORKIC
{
/*
@@ -33,6 +35,7 @@ namespace HBLConsole.MORKIC
GVL_MORIC mORKD = new GVL_MORIC();
//咖啡机主控程序
private CoffeeMachine coffeeMachine;
private ICChipMachine icchipMachine;
//冰淇淋主控程序
private IceCreamMachine iceCreamMachine;
//物料存放位置
@@ -60,7 +63,6 @@ namespace HBLConsole.MORKIC
//构建所有商品物料信息
batchings = PolymerBatching.BuildAll();

EventBus.GetInstance().Subscribe<IceCreamEndCook>(IceCreamEndCookHandle);
EventBus.GetInstance().Subscribe<CoffeEndCook>(CoffeEndCookHandle);

System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
@@ -70,6 +72,11 @@ namespace HBLConsole.MORKIC
var com_IceCream = config.AppSettings.Settings["COM_IceCream"].Value;
var baud_IceCream = config.AppSettings.Settings["BAUD_IceCream"].Value;
var iceCreamCXBThreshold = int.Parse(config.AppSettings.Settings["IceCream_CXB_Threshold"].Value);

var com_ICChip = config.AppSettings.Settings["COM_ICChip"].Value;
var baud_ICChip = config.AppSettings.Settings["BAUD_IChip"].Value;


if (iceCreamCXBThreshold > 0)
{
//设置冰淇淋成型比
@@ -79,6 +86,7 @@ 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));
icchipMachine = new ICChipMachine(com_ICChip, (BaudRates)Enum.Parse(typeof(BaudRates), baud_ICChip));
Main();
ReadData();

@@ -167,7 +175,7 @@ namespace HBLConsole.MORKIC
//订单状态改变:开始制作
SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
//todo:先调用机器人

ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(10002); }), "调用乐百机器人做咖啡场景");
while (!(lebai.Ok && lebai.Value == 1))
@@ -211,10 +219,9 @@ namespace HBLConsole.MORKIC
{
Thread.Sleep(5);
}
new DischargeEvent().Publish();

//冰淇淋没有模式切换,强制等待10s
Thread.Sleep(10000);
new TakeCupEvent() { Cup = IC_CUP.CUP_ICECREAM }.Publish();
while (!ChipStatus.GetInstance().CompletedTake_CPU_CUP_ICECREAM) { Thread.Sleep(5); }
new MakeIceCreamEvent() { SteeringEngine = IC_SE.SE_1 }.Publish();
LebaiHelper.GetInstance.SetValue(100);
//are.WaitOne(100 * 90);
//订单状态改变:完成
@@ -226,12 +233,6 @@ namespace HBLConsole.MORKIC
are.Set();
}

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


public void Main()
{
//咖啡机开启主线程
@@ -250,7 +251,7 @@ namespace HBLConsole.MORKIC
// MorkIStatus.GetInstance().CanDo &&
// MorkCStatus.GetInstance().CanDo;
GeneralConfig.Healthy =
LebaiHelper.GetInstance.IsConnected &&
LebaiHelper.GetInstance.IsConnected &&
MorkCStatus.GetInstance().CanDo;
Thread.Sleep(100);
}), "MORK-IC心跳刷新");


+ 1
- 0
HBLConsole.MORKIC/HBLConsole.MORKIC.csproj View File

@@ -13,6 +13,7 @@
<ProjectReference Include="..\HBLConsole.Interface\HBLConsole.Interface.csproj" />
<ProjectReference Include="..\HBLConsole.Model\HBLConsole.Model.csproj" />
<ProjectReference Include="..\HBLDevice.Coffee\HBLDevice.Coffee.csproj" />
<ProjectReference Include="..\HBLDevice.ICChip\HBLDevice.ICChip.csproj" />
<ProjectReference Include="..\HBLDevice.IceCream\HBLDevice.IceCream.csproj" />
<ProjectReference Include="..\Lebai.SDK\Lebai.SDK.csproj" />
</ItemGroup>


+ 14
- 7
HBLConsole.MainConsole/Main.cs View File

@@ -19,19 +19,25 @@ namespace HBLConsole.MainConsole

private volatile static Main _Instance;
public static Main GetInstance => _Instance ?? (_Instance = new Main());
private Main() { }
private Main()
{
ActionOperate.GetInstance.Register(new Func<object>(() => { return GeneralConfig.DeviceType.ToString(); }), "GetDeviceType");
}

List<string> Topics = new List<string>();

public void DataInit()
{
string deviceType = TextHelper.GetInstance.ReadTextInfo();
GeneralConfig.DeviceType = DeviceClientType.MORKS;
if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct;
ThreadOperate.GetInstance.Start(new Action(() => { Sqlite<Alarm>.GetInstance.GetData(); }), "GetAlarm");
Json<SetPar>.Read();
if (Enum.TryParse(Json<SetPar>.Data.ClientDeviceType, out DeviceClientType dct))
{
GeneralConfig.DeviceType = dct;
}
else { GeneralConfig.DeviceType = DeviceClientType.MORKS; }
//Json<SetPar>.Read();
//if (Enum.TryParse(Json<SetPar>.Data.ClientDeviceType, out DeviceClientType dct))
//{
// GeneralConfig.DeviceType = dct;
//}
//else { GeneralConfig.DeviceType = DeviceClientType.MORKS; }
Json<MorkOrderPushPar>.Read();
Json<BatchingInfoPar>.Read();
Json<SimOrderConfig>.Read();
@@ -49,6 +55,7 @@ namespace HBLConsole.MainConsole
Json<KeepDataBase>.Save();
Sqlite<Alarm>.GetInstance.Save();
TextHelper.GetInstance.SaveLogInfo(MessageLog.GetInstance.LogInfo, "LogInfo");
TextHelper.GetInstance.WriteTextInfo(GVL.GeneralConfig.DeviceType.ToString());
}

public void BusinessInit()


+ 9
- 0
HBLConsole.Model/ViewModel/Alarm.cs View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -12,9 +13,17 @@ namespace HBLConsole.Model
/// <summary>
/// ID
/// </summary>
[Key]
public int Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } }
private int _mId;

/// <summary>
/// 编号ID
/// </summary>
public int NumId { get { return _mNumId; } set { _mNumId = value; OnPropertyChanged(); } }
private int _mNumId;


/// <summary>
/// 日期
/// </summary>


+ 4
- 4
HBLConsole.Model/ViewModel/SimOrderVisibleData.cs View File

@@ -25,11 +25,11 @@ namespace HBLConsole.Model
public string Text { get { return _mText; } set { _mText = value; OnPropertyChanged(); } }
private string _mText;

public int MinValue { get { return _mMinValue; } set { _mMinValue = value; OnPropertyChanged(); } }
private int _mMinValue;
public ushort MinValue { get { return _mMinValue; } set { _mMinValue = value; OnPropertyChanged(); } }
private ushort _mMinValue;

public int MaxValue { get { return _mMaxValue; } set { _mMaxValue = value; OnPropertyChanged(); } }
private int _mMaxValue;
public ushort MaxValue { get { return _mMaxValue; } set { _mMaxValue = value; OnPropertyChanged(); } }
private ushort _mMaxValue;





+ 5
- 2
HBLConsole.Service/Json.cs View File

@@ -11,12 +11,15 @@ namespace HBLConsole.Service
/// </summary>
public class Json<T> where T : class, new()
{

private static string DeviceType = ActionOperate.GetInstance.SendResult("GetDeviceType").ToString();

static string path
{
get
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\JSON"));
return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\{typeof(T).Name}.json";
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\{DeviceType}\\JSON"));
return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\{DeviceType}\\JSON\\{typeof(T).Name}.json";
}
}



+ 24
- 0
HBLConsole.Service/TextHelper.cs View File

@@ -36,5 +36,29 @@ namespace HBLConsole.Service
}
}

public string ReadTextInfo()
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile"));
string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceType.txt";
FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
StreamReader sr = new StreamReader(fs);
string GetStr = sr.ReadLine();
if (GetStr == null) GetStr = string.Empty;
sr.Close();
fs.Close();
return GetStr;
}

public void WriteTextInfo(string info)
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile"));
string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DeviceType.txt";
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(info);
sw.Close();
fs.Close();
}

}
}

+ 8
- 1
HBLConsole.sln View File

@@ -41,7 +41,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLDevice.Coffee", "HBLDevi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLDevice.IceCream", "HBLDevice.IceCream\HBLDevice.IceCream.csproj", "{6F9FD1DA-D17A-4243-83F3-E24ADC0B8CF7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Debug", "HBLConsole.Debug\HBLConsole.Debug.csproj", "{8F75DF03-50F7-4ECF-8535-E59E6486B652}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Debug", "HBLConsole.Debug\HBLConsole.Debug.csproj", "{8F75DF03-50F7-4ECF-8535-E59E6486B652}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLDevice.ICChip", "HBLDevice.ICChip\HBLDevice.ICChip.csproj", "{4A451647-FB80-4D19-85CF-C04A9548A17E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -125,6 +127,10 @@ Global
{8F75DF03-50F7-4ECF-8535-E59E6486B652}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F75DF03-50F7-4ECF-8535-E59E6486B652}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F75DF03-50F7-4ECF-8535-E59E6486B652}.Release|Any CPU.Build.0 = Release|Any CPU
{4A451647-FB80-4D19-85CF-C04A9548A17E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A451647-FB80-4D19-85CF-C04A9548A17E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A451647-FB80-4D19-85CF-C04A9548A17E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A451647-FB80-4D19-85CF-C04A9548A17E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -132,6 +138,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{1E33FFE0-3B82-47F9-9E48-6FC870F36FF0} = {CFF94828-163A-4907-B951-081B18F3CBBD}
{6F9FD1DA-D17A-4243-83F3-E24ADC0B8CF7} = {CFF94828-163A-4907-B951-081B18F3CBBD}
{4A451647-FB80-4D19-85CF-C04A9548A17E} = {CFF94828-163A-4907-B951-081B18F3CBBD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1968105D-1913-4F0B-A03E-7C18AFA58912}


+ 2
- 0
HBLConsole/App.config View File

@@ -24,6 +24,8 @@
<add key="COM_IceCream" value="COM5"/>
<add key="BAUD_IceCream" value="9600"/>
<add key="IceCream_CXB_Threshold" value="90"/>
<add key="COM_ICChip" value="COM5"/>
<add key="BAUD_IChip" value="9600"/>

</appSettings>
</configuration>

+ 2
- 1
HBLConsole/App.xaml.cs View File

@@ -22,7 +22,7 @@ namespace HBLConsole
/// </summary>
public partial class App : Application
{
MainView mainView = new MainView();
MainView mainView;
ListDialogView listDialogView;
protected override void OnStartup(StartupEventArgs e)
{
@@ -32,6 +32,7 @@ namespace HBLConsole
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
MainConsole.Main.GetInstance.DataInit();
ThreadOperate.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData");
mainView = new MainView();
mainView.Show();
NoCompleteOrderInit();
MainConsole.Main.GetInstance.BusinessInit();


+ 4
- 1
HBLConsole/DialogWindow/View/SimOrderConfitView.xaml View File

@@ -110,7 +110,7 @@
<!--#endregion-->

<!--#region 内容显示区-->
<Grid Grid.Row="1" Margin="10">
<Grid KeyDown="Grid_KeyDown" Grid.Row="1" Margin="10">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
@@ -139,6 +139,7 @@
FontFamily="楷体"
FontSize="21"
Foreground="#ff34f7f7"
TabIndex="0"
Text="{Binding Name}" />

<TextBlock
@@ -160,6 +161,7 @@
FontFamily="楷体"
FontSize="21"
Foreground="#ff34f7f7"
TabIndex="1"
Text="{Binding Min}" />

<TextBlock
@@ -181,6 +183,7 @@
FontFamily="楷体"
FontSize="21"
Foreground="#ff34f7f7"
TabIndex="2"
Text="{Binding Max}" />




+ 17
- 3
HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs View File

@@ -1,4 +1,5 @@
using HBLConsole.Service;
using HBLConsole.Model;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,6 +13,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HBLConsole.DialogWindow.ViewModel;

namespace HBLConsole.DialogWindow.View
{
@@ -26,17 +28,29 @@ namespace HBLConsole.DialogWindow.View
this.MoveBorder.MouseLeftButtonDown += (o, e) => { this.DragMove(); };
this.ButMin.Click += (o, e) => { this.WindowState = WindowState.Minimized; };
this.ButMax.Click += (o, e) => { this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; };
this.ButClose.Click += (o, e) => { this.DialogResult = false; };
this.ButClose.Click += (o, e) => { this.Close(); ActionOperate.GetInstance.CancelRegister("SendSimData"); };
this.MaxWidth = SystemParameters.WorkArea.Width;
this.MaxHeight = SystemParameters.WorkArea.Height;

ActionOperate.GetInstance.Register(new Action(() =>
{
this.DialogResult = true;
this.Close();
ActionOperate.GetInstance.CancelRegister("SimOrderConfitViewModelExit");
ActionOperate.GetInstance.CancelRegister("SendSimData");
}), "SimOrderConfitViewModelExit");
}

private void Grid_KeyDown(object sender, KeyEventArgs e)
{
var uie = e.OriginalSource as TextBox;
if (uie != null)
{
if (e.Key == Key.Enter)
{
uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
e.Handled = true;
}
}
}
}
}

+ 46
- 11
HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs View File

@@ -13,24 +13,59 @@ namespace HBLConsole.DialogWindow.ViewModel
{
public class SimOrderConfitViewModel : ViewModelBase
{
bool IsEdit = false;
SimOrderVisibleData simOrderVisibleData;
string DeviceType = string.Empty;
public SimOrderConfitViewModel()
{
DeviceType = GVL.GeneralConfig.DeviceType.ToString();
ActionOperate.GetInstance.Register(new Action<object>((o) =>
{
if (o != null)
{
if (o is SimOrderVisibleData sim)
{
Name = sim.Text;
Max = sim.MaxValue;
Min = sim.MinValue;
IsEdit = true;
simOrderVisibleData = sim;
}
}
}), "SendSimData");

ConfirmCommand = new RelayCommand(() =>
{
if (!Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString()))
if (!Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(DeviceType))
{
Json<KeepDataBase>.Data.simOrderConfig.TryAdd(GVL.GeneralConfig.DeviceType.ToString(), new ObservableCollection<SimOrderVisibleData>());
Json<KeepDataBase>.Data.simOrderConfig.TryAdd(DeviceType, new ObservableCollection<SimOrderVisibleData>());
}
Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].Add(new SimOrderVisibleData()

if (!IsEdit)
{
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].Add(new SimOrderVisibleData()
{
ClientDeviceType = GVL.GeneralConfig.DeviceType.ToString(),
IsEnable = true,
IsSelected = true,
Text = Name,
Loc = Min,
MaxValue = Max,
MinValue = Min,
});
}
else
{
ClientDeviceType = GVL.GeneralConfig.DeviceType.ToString(),
IsEnable = true,
IsSelected = true,
Text = Name,
Loc = Min,
MaxValue = Max,
MinValue = Min,
});
int index = Array.FindIndex(Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ToArray(), p => p.Text == simOrderVisibleData.Text);
if (index >= 0 && index < Json<KeepDataBase>.Data.simOrderConfig[DeviceType].Count())
{
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).Text = Name;
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).MinValue = Min;
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).MaxValue = Max;
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).IsEnable = simOrderVisibleData.IsEnable;
Json<KeepDataBase>.Data.simOrderConfig[DeviceType].ElementAt(index).IsSelected = simOrderVisibleData.IsSelected;
}
}
ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit");
});
CancelCommand = new RelayCommand(() => { ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); });


+ 2
- 2
HBLConsole/View/AlarmView.xaml View File

@@ -58,7 +58,7 @@
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="#FFAF0D0D" />
<Setter Property="Foreground" Value="Red" />
<Setter Property="FontSize" Value="14" />
</Style>

@@ -260,7 +260,7 @@
<TextBlock
Grid.Column="0"
Style="{StaticResource DataTextBlockStyle}"
Text="{Binding Id}" />
Text="{Binding NumId}" />

<Grid Grid.Column="1">
<TextBlock Style="{StaticResource DataTextBlockStyle}" Text="{Binding Date}" />


+ 29
- 16
HBLConsole/View/DebugView.xaml View File

@@ -11,19 +11,14 @@
d:DesignWidth="1000"
mc:Ignorable="d">

<UserControl.DataContext>
<vm:DebugViewModel />
</UserControl.DataContext>

<UserControl.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml">

<Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="FontFamily" Value="楷体" />
<Setter Property="FontSize" Value="22" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="#9934F7F7" />
<Setter Property="BorderBrush" Value="#00c2f4" />
@@ -151,6 +146,10 @@
</ResourceDictionary>
</UserControl.Resources>

<UserControl.DataContext>
<vm:DebugViewModel />
</UserControl.DataContext>

<Grid>

<Grid.ColumnDefinitions>
@@ -173,12 +172,14 @@
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="150" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="16"
FontSize="14"
Foreground="#00c2f4"
Text="{Binding Text}" />

@@ -195,10 +196,28 @@
VerticalAlignment="Center"
Background="#FF2AB2E7"
Content="启用随机数"
FontSize="16"
FontSize="14"
Foreground="#00c2f4"
IsChecked="{Binding IsSelected}"
Template="{StaticResource CbTemplate}" />

<Button
Style="{StaticResource ButtonStyle}"
Grid.Column="3"
FontSize="14"
Margin="10 0 0 0"
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
CommandParameter="{Binding Text}"
Content="编辑" />

<Button
Grid.Column="4"
Margin="5 0 0 0"
FontSize="14"
Style="{StaticResource ButtonStyle}"
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
CommandParameter="{Binding Text}"
Content="删除" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
@@ -217,15 +236,9 @@
Style="{StaticResource ButtonStyle}" />
</UniformGrid>
</StackPanel>



</Grid>




<Grid Grid.Column="1">
<Grid Margin="20 0 0 0" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="10" />


+ 1
- 1
HBLConsole/View/MainView.xaml View File

@@ -235,7 +235,7 @@
Grid.RowSpan="2"
Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="{Binding ContentHeight}" />
<RowDefinition />
</Grid.RowDefinitions>



+ 3
- 11
HBLConsole/ViewModel/AlarmViewModel.cs View File

@@ -17,15 +17,6 @@ namespace HBLConsole.ViewModel
public AlarmViewModel()
{
WindowName = "实时报警";


//AlarmHelper.GetInstance.EdgeAlarm(true, "测试报警信息33");
//AlarmHelper.GetInstance.EdgeAlarm(true, "测试报警信息33");
//AlarmHelper.GetInstance.EdgeAlarm(true, "测试报警信息33");
//AlarmHelper.GetInstance.EdgeAlarm(true, "测试报警信息33");
//AlarmHelper.GetInstance.EdgeAlarm(true, "测试报警信息33");
//AlarmHelper.GetInstance.EdgeAlarm(true, "测试报警信息");

ControlCommand = new RelayCommand(() =>
{
if (ControlButText == "报警复位")
@@ -52,6 +43,7 @@ namespace HBLConsole.ViewModel
{
if (ButContent == "历史报警")
{
GetHistoryAlarm();
CurrentDataVis = Visibility.Hidden;
HistoryDataVis = Visibility.Visible;
IsVisibility = Visibility.Visible;
@@ -73,11 +65,12 @@ namespace HBLConsole.ViewModel

}

static AlarmViewModel()
private void GetHistoryAlarm()
{
var data = Sqlite<Alarm>.GetInstance.Base.ToList();
if (data != null)
{
AlarmHelper.GetInstance.HistoryAlarms.Clear();
foreach (var item in data)
{
int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
@@ -87,7 +80,6 @@ namespace HBLConsole.ViewModel
}
}
}

}

public RelayCommand SwitchCommand { get; set; }


+ 36
- 10
HBLConsole/ViewModel/DebugViewModel.cs View File

@@ -28,7 +28,7 @@ namespace HBLConsole.ViewModel
AddSimDataCommand = new RelayCommand(() =>
{
SimOrderConfitView simOrderConfitView = new SimOrderConfitView();
simOrderConfitView.ShowDialog();
simOrderConfitView.Show();
});

SimOrderCommand = new RelayCommand(() =>
@@ -43,7 +43,7 @@ namespace HBLConsole.ViewModel
}
if (locs.Count == 0)
{
locs.Add((ushort)(new Random().Next(1,5)));
locs.Add((ushort)(new Random().Next(1, 5)));
locs.Add(10);

}
@@ -91,6 +91,36 @@ namespace HBLConsole.ViewModel
// //}
// Thread.Sleep(1000);
//}), "循环订单");

EditCommand = new RelayCommand<object>((o) =>
{
if (o != null)
{
if (Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString()))
{
var res = Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].FirstOrDefault(p => p.Text == o.ToString());
if (res != null)
{
SimOrderConfitView simOrderConfitView = new SimOrderConfitView();
simOrderConfitView.Show();
ActionOperate.GetInstance.Send("SendSimData", res);
}
}
}

});

RemoveCommand = new RelayCommand<object>((o) =>
{
if (o != null)
{
if (Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(GVL.GeneralConfig.DeviceType.ToString()))
{
var res = Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].FirstOrDefault(p => p.Text == o.ToString());
if (res != null) Json<KeepDataBase>.Data.simOrderConfig[GVL.GeneralConfig.DeviceType.ToString()].Remove(res);
}
}
});
}

public ObservableCollection<SimOrderVisibleData> simOrderConfig
@@ -113,14 +143,6 @@ namespace HBLConsole.ViewModel
}
}



public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName));
}

public RelayCommand AddSimDataCommand { get; set; }

public RelayCommand SimOrderCommand { get; set; }
@@ -129,6 +151,10 @@ namespace HBLConsole.ViewModel

public RelayCommand LoopSimOrderCommand { get; set; }

public RelayCommand<object> EditCommand { get; set; }

public RelayCommand<object> RemoveCommand { get; set; }

public static bool IsLoop = false;
public static bool IsLoopzc = false;



+ 49
- 14
HBLConsole/ViewModel/MainViewModel.cs View File

@@ -1,5 +1,4 @@
//using BPA.Message.Kafka;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -13,6 +12,9 @@ using System.Reflection;
using HBLConsole.Service;
using HBLConsole.GVL;
using HBLConsole.Model;
using HBLConsole.Business;
using HBLConsole.Factory;
using HBLConsole.Attributes;

namespace HBLConsole.ViewModel
{
@@ -30,26 +32,59 @@ namespace HBLConsole.ViewModel
OrderCount = orderStatusLists.Count;
Thread.Sleep(1000);
}), "界面状态监控");
AlarmMonitoring();
}

private void AlarmMonitoring()
{
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
if (SimpleFactory.GetInstance.Alarm != null)
{
foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties())
{
var res = item.GetValue(SimpleFactory.GetInstance.Alarm);
if (res != null)
{
if (res is bool blen)
{
if (item.CustomAttributes.Count() > 0)
{
if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0)
{
var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value;
if (info != null)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString());
}));
}
}
}
}
}
}
}
Thread.Sleep(500);
}), "报警检测监控");
}

#region Command
public RelayCommand<object> NavChangedCommand { get; set; }
#endregion

#region 导航栏界面切换
private void DoNavChanged(object obj)
{
Type type = Type.GetType($"HBLConsole.View.{obj.ToString()}");
//if (type != null)
//{
ConstructorInfo cti = type?.GetConstructor(Type.EmptyTypes);
MainContent = (FrameworkElement)cti?.Invoke(null);
//WinNameDisplay = WinNameVisible(obj.ToString());
//}

if (obj != null)
{
Type type = Type.GetType($"HBLConsole.View.{obj.ToString()}");
if (type != null)
{
ConstructorInfo cti = type.GetConstructor(Type.EmptyTypes);
if (cti != null)
MainContent = (FrameworkElement)cti.Invoke(null);
}
}
}
#endregion

}
}

+ 2
- 2
HBLConsole/ViewModel/ViewModelBase.cs View File

@@ -33,7 +33,7 @@ namespace HBLConsole.ViewModel
#region 静态通知属性

public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
private static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
public static void OnStaticPropertyChanged([CallerMemberName] string PropName = "")
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName));
}
@@ -59,7 +59,7 @@ namespace HBLConsole.ViewModel
/// 内容高度显示
/// </summary>
public static int ContentHeight { get { return _mContentHeight; } set { _mContentHeight = value; OnStaticPropertyChanged(); } }
private static int _mContentHeight = 0;
private static int _mContentHeight = 50;


/// <summary>


+ 116
- 0
HBLDevice.ICChip/ChipStatus.cs View File

@@ -0,0 +1,116 @@
using BPA.Utility;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
public class ChipStatus : Singleton<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; }

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;
}
}
catch (Exception ex)
{

}
}
}
}

+ 22
- 0
HBLDevice.ICChip/CommandEvent.cs View File

@@ -0,0 +1,22 @@
using BPA.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
public class TakeCupEvent : IEvent
{
/// <summary>
/// 杯
/// </summary>
public IC_CUP Cup { get; set; }
}

public class MakeIceCreamEvent : IEvent
{
public IC_SE SteeringEngine { get; set; }
}
}

+ 149
- 0
HBLDevice.ICChip/CommandHandler.cs View File

@@ -0,0 +1,149 @@
using BPA.Utility;
using HBLConsole.Communication;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static BPA.Utility.EventBus;

namespace HBLDevice.ICChip
{
/// <summary>
/// 指令封装
/// </summary>
internal class CommandHandler
{
private SerialPortClient commProxy;
private ICChipPackage package = new ICChipPackage();

/// <summary>
/// 初始化
/// </summary>
internal void Init(SerialPortClient commProxy)
{
this.commProxy = commProxy;
EventBus.GetInstance().Subscribe<TakeCupEvent>(TakeCupEventHandle);
EventBus.GetInstance().Subscribe<MakeIceCreamEvent>(MakeIceCreamEventHandle);
}

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(500);

DateTime timeOut = DateTime.Now.AddSeconds(3);
bool loop = true;
while (loop)
{
loop = DateTime.Now < timeOut;
switch ((@event as MakeIceCreamEvent).SteeringEngine)
{
case IC_SE.SE_1:
loop = !ChipStatus.GetInstance().CompletedOpen_SE_1;
break;
case IC_SE.SE_2:
loop = !ChipStatus.GetInstance().CompletedOpen_SE_2;
break;
case IC_SE.SE_3:
loop = !ChipStatus.GetInstance().CompletedOpen_SE_3;
break;
}
}

switch ((@event as MakeIceCreamEvent).SteeringEngine)
{
case IC_SE.SE_1:
ChipStatus.GetInstance().CompletedClose_SE_1 = false;
break;
case IC_SE.SE_2:
ChipStatus.GetInstance().CompletedClose_SE_2 = false;
break;
case IC_SE.SE_3:
ChipStatus.GetInstance().CompletedClose_SE_3 = false;
break;
}
package.Cmd = IC_CMD.CLOSE_SE;
package.Value = (byte)(@event as MakeIceCreamEvent).SteeringEngine;
commProxy.SendData(StructureToByte(package));
Thread.Sleep(500);

timeOut = DateTime.Now.AddSeconds(3);
loop = true;
while (loop)
{
loop = DateTime.Now < timeOut;
switch ((@event as MakeIceCreamEvent).SteeringEngine)
{
case IC_SE.SE_1:
loop = !ChipStatus.GetInstance().CompletedClose_SE_1;
break;
case IC_SE.SE_2:
loop = !ChipStatus.GetInstance().CompletedClose_SE_2;
break;
case IC_SE.SE_3:
loop = !ChipStatus.GetInstance().CompletedClose_SE_3;
break;
}
}
}

private void TakeCupEventHandle(IEvent @event, EventCallBackHandle callBack)
{
switch ((@event 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)(@event as TakeCupEvent).Cup;
commProxy.SendData(StructureToByte(package));
}


private byte[] StructureToByte(ICChipPackage structure)
{
structure.Header = 0xAA;
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;
}


}
}

+ 17
- 0
HBLDevice.ICChip/HBLDevice.ICChip.csproj View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Communication\HBLConsole.Communication.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="BPA.Utility">
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

+ 102
- 0
HBLDevice.ICChip/ICChipMachine.cs View File

@@ -0,0 +1,102 @@
using HBLConsole.Communication;
using HBLConsole.Model;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;

namespace HBLDevice.ICChip
{
public class ICChipMachine
{
//指令组装
private CommandHandler commandHandler = new CommandHandler();
//通讯代理
SerialPortClient commProxy = null;
//数据仓库
private DataStorage<byte> dataStorage = new DataStorage<byte>();
//主线程运行标识
private bool running = false;
//是否下发指令,主线程等待
public Action<string> SendCallback;
public Action<string> ReciveCallback;



public ICChipMachine(string portName, BaudRates baud)
{
commProxy = new SerialPortClient(portName, baud);
commProxy.SetDataStorage(dataStorage);
commandHandler.Init(commProxy);
}

public void Start()
{
commProxy.Start();
running = true;
MainLoop();
}

public void Stop()
{
}

private void MainLoop()
{
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
ResolveMsg();
//Thread.Sleep(2000);
}), "冰淇淋解析线程");
}
int contentLength = 0;
int currentContentOffset = 0;
private void ResolveMsg()
{
List<byte> temp = new List<byte>();
//一系列解包
while (dataStorage.GetSize() > 0)
{
byte item = dataStorage.GetData();
if (item == 0xAA)
{
while (dataStorage.GetSize() < 4) { Thread.Sleep(5); }
while (temp.Count < 5)
{
temp.Add(dataStorage.GetData());
}
if (temp[4] == 0xBB)
{
var package = ByteToStructure(temp.ToArray());
ChipStatus.GetInstance().ProcessMsg(package);
temp.Clear();
}
}
continue;
}
Thread.Sleep(5);
}

/// <summary>
/// 由byte数组转换为结构体
/// </summary>
private ICChipPackage ByteToStructure(byte[] dataBuffer)
{
ICChipPackage structure = new ICChipPackage();
int size = Marshal.SizeOf(typeof(ICChipPackage));
IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
try
{
Marshal.Copy(dataBuffer, 0, allocIntPtr, size);
structure = (ICChipPackage)Marshal.PtrToStructure(allocIntPtr, typeof(ICChipPackage));
}
finally
{
Marshal.FreeHGlobal(allocIntPtr);
}
return structure;
}
}

}

+ 37
- 0
HBLDevice.ICChip/Protocal/ICChipPackage.cs View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
/// <summary>
/// Dr咖啡机基础协议
/// </summary>
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct ICChipPackage
{
/// <summary>
/// 包头(固定0xAA)
/// </summary>
public byte Header;
/// <summary>
/// 发送方
/// </summary>
public IC_SENDER Sender;
/// <summary>
/// 命令
/// </summary>
public IC_CMD Cmd;
/// <summary>
/// 故障(咖啡机负责写,工控机负责读)
/// </summary>
public byte Value;
/// <summary>
/// 包尾(固定为0xBB)
/// </summary>
public byte End;
}
}

+ 35
- 0
HBLDevice.ICChip/Protocal/IC_CMD.cs View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
/// <summary>
/// 命令
/// </summary>
public enum IC_CMD:byte
{
/// <summary>
/// 心跳
/// </summary>
HEART_BEAT=0x00,
/// <summary>
/// 下杯(带上碗参数)
/// </summary>
TAKE_CUP=0x01,
/// <summary>
/// 打开舵机(带上舵机参数)
/// </summary>
OPEN_SE=0x02,
/// <summary>
/// 关闭舵机(带上舵机参数)
/// </summary>
CLOSE_SE = 0x03,
/// <summary>
/// 使能冰淇淋转子(带上开关参数)
/// </summary>
ROTOR=0x04,
}
}

+ 23
- 0
HBLDevice.ICChip/Protocal/IC_CUP.cs View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
/// <summary>
/// 杯子
/// </summary>
public enum IC_CUP : byte
{
/// <summary>
/// 冰淇淋杯
/// </summary>
CUP_ICECREAM = 0x01,
/// <summary>
/// 咖啡杯
/// </summary>
CUP_COFFEE = 0x02
}
}

+ 27
- 0
HBLDevice.ICChip/Protocal/IC_SE.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
/// <summary>
/// 冰淇淋舵机
/// </summary>
public enum IC_SE:byte
{
/// <summary>
/// 舵机1
/// </summary>
SE_1=0x01,
/// <summary>
/// 舵机2
/// </summary>
SE_2=0x02,
/// <summary>
/// 舵机3
/// </summary>
SE_3=0x03,
}
}

+ 23
- 0
HBLDevice.ICChip/Protocal/IC_SENDER.cs View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLDevice.ICChip
{
/// <summary>
/// 命令发送方
/// </summary>
public enum IC_SENDER:byte
{
/// <summary>
/// 上位机
/// </summary>
CONSOLE=0x01,
/// <summary>
/// 单片机
/// </summary>
DEVICE=0x02,
}
}

+ 17
- 0
HBLDevice.IceCreamV1/HBLDevice.ICChip.csproj View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Communication\HBLConsole.Communication.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="BPA.Utility">
<HintPath>..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

Loading…
Cancel
Save