From 60dac32056ce9fb40badf775cc54b82d9360941c Mon Sep 17 00:00:00 2001
From: fyf <11621@LAPTOP-04QQU0AO>
Date: Tue, 19 Apr 2022 16:10:40 +0800
Subject: [PATCH] 123
---
.editorconfig | 122 ++++++++++++++++++
.../BPASmartClient.DRCoffee.csproj | 4 -
BPASmartClient.DRCoffee/CoffeeMachine.cs | 89 ++++++++-----
BPASmartClient.DRCoffee/CommandHandler.cs | 120 -----------------
BPASmartClient.SCChip/ICChipMachine.cs | 9 +-
5 files changed, 189 insertions(+), 155 deletions(-)
delete mode 100644 BPASmartClient.DRCoffee/CommandHandler.cs
diff --git a/.editorconfig b/.editorconfig
index 12dd7909..433fec56 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -14,3 +14,125 @@ dotnet_analyzer_diagnostic.severity = none
# CS8602: 解引用可能出现空引用。
dotnet_diagnostic.CS8602.severity = none
+
+[*.cs]
+#### 命名样式 ####
+
+# 命名规则
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# 符号规范
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# 命名样式
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+csharp_using_directive_placement = outside_namespace:silent
+csharp_style_expression_bodied_methods = false:silent
+csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_properties = true:silent
+csharp_style_expression_bodied_indexers = true:silent
+csharp_style_expression_bodied_accessors = true:silent
+csharp_style_expression_bodied_lambdas = true:silent
+csharp_style_expression_bodied_local_functions = false:silent
+csharp_style_conditional_delegate_call = true:suggestion
+csharp_style_var_for_built_in_types = false:silent
+csharp_style_var_when_type_is_apparent = false:silent
+csharp_style_var_elsewhere = false:silent
+csharp_prefer_simple_using_statement = true:suggestion
+csharp_prefer_braces = true:silent
+csharp_style_namespace_declarations = block_scoped:silent
+csharp_prefer_static_local_function = true:suggestion
+
+[*.vb]
+#### 命名样式 ####
+
+# 命名规则
+
+dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion
+dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface
+dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始
+
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
+
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
+
+# 符号规范
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.类型.required_modifiers =
+
+dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
+dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.非字段成员.required_modifiers =
+
+# 命名样式
+
+dotnet_naming_style.以_i_开始.required_prefix = I
+dotnet_naming_style.以_i_开始.required_suffix =
+dotnet_naming_style.以_i_开始.word_separator =
+dotnet_naming_style.以_i_开始.capitalization = pascal_case
+
+dotnet_naming_style.帕斯卡拼写法.required_prefix =
+dotnet_naming_style.帕斯卡拼写法.required_suffix =
+dotnet_naming_style.帕斯卡拼写法.word_separator =
+dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
+
+dotnet_naming_style.帕斯卡拼写法.required_prefix =
+dotnet_naming_style.帕斯卡拼写法.required_suffix =
+dotnet_naming_style.帕斯卡拼写法.word_separator =
+dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
+
+[*.{cs,vb}]
+end_of_line = crlf
+dotnet_style_qualification_for_field = false:silent
+dotnet_style_qualification_for_property = false:silent
+dotnet_style_qualification_for_method = false:silent
+dotnet_style_qualification_for_event = false:silent
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
+dotnet_code_quality_unused_parameters = all:suggestion
\ No newline at end of file
diff --git a/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj b/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj
index 8f4b204d..58a6fd19 100644
--- a/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj
+++ b/BPASmartClient.DRCoffee/BPASmartClient.DRCoffee.csproj
@@ -4,10 +4,6 @@
net6.0
-
-
-
-
diff --git a/BPASmartClient.DRCoffee/CoffeeMachine.cs b/BPASmartClient.DRCoffee/CoffeeMachine.cs
index e3e9b163..541856ab 100644
--- a/BPASmartClient.DRCoffee/CoffeeMachine.cs
+++ b/BPASmartClient.DRCoffee/CoffeeMachine.cs
@@ -1,6 +1,7 @@
using BPASmartClient.DRCoffee;
using BPASmartClient.EventBus;
using BPASmartClient.Helper;
+using BPASmartClient.Message;
using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using BPASmartClient.SerialPort;
@@ -16,13 +17,10 @@ namespace BPASmartClient.DRCoffee
///
public class CoffeeMachine: BasePeripheral
{
- public Action PauseAsk { get; set; }
//通讯代理
SerialPortClient commProxy = null;
//数据仓库
private DataStorage dataStorage = new DataStorage();
- //指令组装
- private CommandHandler commandHandler = new CommandHandler();
//主线程运行标识
private bool running = false;
//是否下发指令,主线程等待
@@ -72,7 +70,9 @@ namespace BPASmartClient.DRCoffee
/// 应用状态改变回调
///
public Action CoffeeAppStatusChanged;
-
+ ///
+ /// Dr咖啡机基础协议
+ ///
private DrCoffeePackage drinksOrder = new DrCoffeePackage();
///
@@ -86,13 +86,7 @@ namespace BPASmartClient.DRCoffee
public CoffeeMachine()
{
- //
- //commProxy.SetDataStorage(dataStorage);
- //commandHandler.Init(commProxy);
- //commandHandler.PauseAsk = delegate (bool pause)
- //{
- // free = !pause;
- //};
+
}
///
@@ -100,7 +94,7 @@ namespace BPASmartClient.DRCoffee
///
public override void Start()
{
- commProxy = new SerialPortClient(PortName,(BaudRates)Enum.Parse(typeof(BaudRates),BaudRate));
+
commProxy.Start();
running = true;
MainLoop();
@@ -120,15 +114,15 @@ namespace BPASmartClient.DRCoffee
///
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(commandHandler.GetStatusAsk());
+ // SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetStatusAsk()));
+ // }
+ // Thread.Sleep(200);
+ //}),"咖啡机询问线程");
ThreadManage.GetInstance.StartLong(new Action(() =>
{
@@ -176,28 +170,63 @@ namespace BPASmartClient.DRCoffee
public override void Init()
{
+ commProxy = new SerialPortClient(PortName,(BaudRates)Enum.Parse(typeof(BaudRates),BaudRate));
+ commProxy.SetDataStorage(dataStorage);
+
//咖博士咖啡机制作
EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack)
{
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
- //drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).CommCmd;
- commProxy.SendData(DrCoffee.Packe(drinksOrder));
- Thread.Sleep(200);
- PauseAsk?.Invoke(false);
+ try
+ {
+ free = true;
+ Thread.Sleep(200);
+ drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
+ //drinksOrder.DrinksCode = ((DRCoffee_MakeCoffeeEvent)@event).CommCmd;
+ commProxy.SendData(DrCoffee.Packe(drinksOrder));
+ Thread.Sleep(200);
+ free = false;
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeMachine 类,描述:[{ex.Message}]");
+ }
});
//咖博士咖啡机取消制作咖啡
EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack)
{
-
+ try
+ {
+ free = true;
+ Thread.Sleep(200);
+ drinksOrder.CommCmd = DrCoffeeCommCmd.取消应用指令;
+ drinksOrder.DrinksCode = 0;
+ commProxy.SendData(DrCoffee.Packe(drinksOrder));
+ Thread.Sleep(200);
+ free = false;
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeMachine 类,描述:[{ex.Message}]");
+ }
});
//咖博士咖啡机模式设置
EventBus.EventBus.GetInstance().Subscribe(DeviceId,delegate (IEvent @event,EventCallBackHandle callBack)
{
-
+ try
+ {
+ free = true;
+ Thread.Sleep(200);
+ //drinksOrder.CommCmd = (DrCoffeeCommCmd)int.Parse(e.obj_MessageObj.ToString());
+ commProxy.SendData(DrCoffee.Packe(drinksOrder));
+ Thread.Sleep(200);
+ free = false;
+ }
+ catch (Exception ex)
+ {
+ MessageLog.GetInstance.Show($"BPASmartClient.DRCoffee 中引发错误,CoffeeCommCmdHandler 类,描述:[{ex.Message}]");
+ }
});
}
}
diff --git a/BPASmartClient.DRCoffee/CommandHandler.cs b/BPASmartClient.DRCoffee/CommandHandler.cs
deleted file mode 100644
index f42e3a34..00000000
--- a/BPASmartClient.DRCoffee/CommandHandler.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-
-using BPASmartClient.DRCoffee;
-using BPASmartClient.Message;
-using BPASmartClient.MessageCommunication;
-using BPASmartClient.MessageCommunication.MsgControl;
-using BPASmartClient.SerialPort;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.DRCoffee
-{
- ///
- /// 指令封装
- ///
- internal class CommandHandler
- {
- byte[] cmdAsk;
- private SerialPortClient commProxy;
- private DrCoffeePackage drinksOrder = new DrCoffeePackage();
- public Action PauseAsk { get; set; }
-
- ///
- /// 初始化
- ///
- internal void Init(SerialPortClient commProxy)
- {
- //DoCoffee
- this.commProxy = commProxy;
- DrCoffeePackage package = new DrCoffeePackage();
- package.CommCmd = DrCoffeeCommCmd.饮品制作指令;
- cmdAsk = DrCoffee.Packe(package);
- drinksOrder.CommCmd = DrCoffeeCommCmd.饮品制作指令;
- Class_InnerMessageBus.GetInstance().ListenMessage(this, Class_MessageName.DRCoffee_MakeCoffee, "MakeCoffeeHandler");
- Class_InnerMessageBus.GetInstance().ListenMessage(this, Class_MessageName.DRCoffee_CancelMakeCoffee, "CancelMakeCoffeeHandler");
- Class_InnerMessageBus.GetInstance().ListenMessage(this, Class_MessageName.DRCoffee_CoffeeCommCmd, "CoffeeCommCmdHandler");
- }
-
- ///
- /// 制作咖啡
- ///
- public void MakeCoffeeHandler(object sender, InnerMessageEventArgs e)
- {
- try
- {
- if (e.obj_MessageObj is string)
- {
- PauseAsk?.Invoke(true);
- Thread.Sleep(200);
- 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}]");
- }
- }
-
- ///
- /// 取消制作
- ///
- 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}]");
- }
- }
-
- ///
- /// 模式设置
- ///
- ///
- ///
- 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}]");
- }
- }
-
- ///
- /// 发送状态询问
- ///
- internal byte[] GetStatusAsk()
- {
- return cmdAsk;
- }
- }
-}
diff --git a/BPASmartClient.SCChip/ICChipMachine.cs b/BPASmartClient.SCChip/ICChipMachine.cs
index a8433e3c..e5eda44b 100644
--- a/BPASmartClient.SCChip/ICChipMachine.cs
+++ b/BPASmartClient.SCChip/ICChipMachine.cs
@@ -22,7 +22,14 @@ namespace BPASmartClient.SCChip
public Action SendCallback;
public Action ReciveCallback;
-
+ ///
+ /// 串口COM口
+ ///
+ public string PortName { get; set; }
+ ///
+ /// 串口波特率
+ ///
+ public string BaudRate { get; set; }
public ICChipMachine()
{