@@ -0,0 +1,16 @@ | |||
[*.cs] | |||
# CS8600: 将 null 字面量或可能为 null 的值转换为非 null 类型。 | |||
dotnet_diagnostic.CS8600.severity = none | |||
# CS8604: 引用类型参数可能为 null。 | |||
dotnet_diagnostic.CS8604.severity = none | |||
# CS8603: 可能返回 null 引用。 | |||
dotnet_diagnostic.CS8603.severity = none | |||
# Default severity for all analyzer diagnostics | |||
dotnet_analyzer_diagnostic.severity = none | |||
# CS8602: 解引用可能出现空引用。 | |||
dotnet_diagnostic.CS8602.severity = none |
@@ -1,4 +1,4 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,4 +6,10 @@ | |||
<Nullable>enable</Nullable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.Device\BPASmartClient.Device.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Helper\BPASmartClient.Helper.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,7 +0,0 @@ | |||
namespace BPASmartClient.Business | |||
{ | |||
public class Class1 | |||
{ | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
using BPASmartClient.Model; | |||
using System.Xml.Linq; | |||
using System.Xml.XPath; | |||
namespace BPASmartClient.Business | |||
{ | |||
public class ConfigMgr : IPlugin | |||
{ | |||
private List<DeviceConfig> deviceConfigs; | |||
public void Dispose() | |||
{ | |||
} | |||
public void Initialize() | |||
{ | |||
InitDeviceModel(); | |||
} | |||
public List<DeviceConfig> GetDeviceConfigs() | |||
{ | |||
if (null == deviceConfigs) | |||
InitDeviceModel(); | |||
return deviceConfigs; | |||
} | |||
private void InitDeviceModel() | |||
{ | |||
deviceConfigs = new List<DeviceConfig>(); | |||
var devicePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DeviceInfo.xml"); | |||
var xdoc = XDocument.Load(devicePath); | |||
var devices = xdoc.XPathSelectElements("//Device"); | |||
foreach (var device in devices) | |||
{ | |||
DeviceConfig deviceConfig = new DeviceConfig(); | |||
deviceConfig.Name = device.Attribute("Name").Value; | |||
deviceConfig.Module = device.Attribute("Module").Value; | |||
deviceConfig.DeviceId = device.Attribute("DeviceId").Value; | |||
foreach (var peripheralEl in device.XPathSelectElements("//Peripheral")) | |||
{ | |||
BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral(); | |||
peripheral.Module = peripheralEl.Attribute("Module").Value; | |||
foreach (XElement parameter in peripheralEl.Element("Parameters").Elements()) | |||
{ | |||
peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value); | |||
} | |||
deviceConfig.Peripherals.Add(peripheral); | |||
} | |||
deviceConfigs.Add(deviceConfig); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,67 @@ | |||
using BPASmartClient.Device; | |||
using BPASmartClient.Helper; | |||
using BPASmartClient.Peripheral; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Business | |||
{ | |||
/// <summary> | |||
/// 设备管理器,统一管理所有设备资源 | |||
/// </summary> | |||
public class DeviceMgr : IPlugin | |||
{ | |||
//设备集合 | |||
private List<IDevice> devices = new List<IDevice>(); | |||
public void Dispose() | |||
{ | |||
} | |||
public void Initialize() | |||
{ | |||
LoadDevice(); | |||
} | |||
/// <summary> | |||
/// 设备加载 | |||
/// </summary> | |||
private void LoadDevice() | |||
{ | |||
var devices = Plugin.GetInstance().GetPlugin<ConfigMgr>().GetDeviceConfigs(); | |||
foreach (var device in devices) | |||
{ | |||
var deviceTemp = Assembly.Load(device.Module.Substring(0, device.Module.LastIndexOf('.'))).CreateInstance(device.Module) as IDevice; | |||
deviceTemp.Name = device.Name; | |||
deviceTemp.DeviceId = device.DeviceId; | |||
List<IPeripheral> peripherals = new List<IPeripheral>(); | |||
foreach (var peripheral in device.Peripherals) | |||
{ | |||
var peripheralTemp = Assembly.Load(peripheral.Module.Substring(0, peripheral.Module.LastIndexOf('.'))).CreateInstance(peripheral.Module) as IPeripheral; | |||
foreach (var pars in peripheral.Parameters) | |||
{ | |||
peripheralTemp.GetType().GetProperty(pars.Key).SetValue(peripheralTemp, Convert.ChangeType(pars.Value, peripheralTemp.GetType().GetProperty(pars.Key).PropertyType)); | |||
} | |||
peripherals.Add(peripheralTemp); | |||
} | |||
deviceTemp.Initliaze(peripherals); | |||
this.devices.Add(deviceTemp); | |||
} | |||
} | |||
public void StartService() | |||
{ | |||
this.devices.ForEach(device => device.StartMain()); | |||
} | |||
public void StopService() | |||
{ | |||
this.devices.ForEach(device => device.Stop()); | |||
} | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Business | |||
{ | |||
/// <summary> | |||
/// 业务插件 | |||
/// </summary> | |||
public interface IPlugin:IDisposable | |||
{ | |||
void Initialize(); | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
using BPASmartClient.Helper; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Business | |||
{ | |||
public class Plugin : Singleton<Plugin>, IDisposable | |||
{ | |||
private List<IPlugin> plugins = new List<IPlugin>(); | |||
public void Dispose() | |||
{ | |||
plugins.ForEach(p => p.Dispose()); | |||
} | |||
public void Init() | |||
{ | |||
this.GetType().Assembly.GetTypes().ToList().ForEach(plugin => | |||
{ | |||
if (plugin.GetInterfaces().Contains(typeof(IPlugin))) | |||
{ | |||
plugins.Add((IPlugin)Activator.CreateInstance(plugin)); | |||
} | |||
}); | |||
plugins.ForEach(p => p.Initialize()); | |||
} | |||
public T GetPlugin<T>() where T : IPlugin | |||
{ | |||
return (T)plugins.FirstOrDefault(p => p.GetType().Equals(typeof(T))); | |||
} | |||
} | |||
} |
@@ -4,8 +4,13 @@ | |||
<TargetFramework>net6.0</TargetFramework> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<None Include="..\.editorconfig" Link=".editorconfig" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | |||
</ItemGroup> | |||
@@ -1,16 +1,17 @@ | |||
using BPASmartClient.DRCoffee; | |||
using BPASmartClient.Helper; | |||
using BPASmartClient.Peripheral; | |||
using BPASmartClient.SerialPort; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Threading; | |||
namespace HBLDevice.Coffee | |||
namespace BPASmartClient.DRCoffee | |||
{ | |||
/// <summary> | |||
/// 咖啡机 | |||
/// </summary> | |||
public class CoffeeMachine | |||
public class CoffeeMachine: BasePeripheral | |||
{ | |||
//通讯代理 | |||
@@ -69,21 +70,21 @@ namespace HBLDevice.Coffee | |||
/// </summary> | |||
public Action<DrCoffeeAppStatus> CoffeeAppStatusChanged; | |||
public CoffeeMachine(string portName, BaudRates baud) | |||
public CoffeeMachine() | |||
{ | |||
commProxy = new SerialPortClient(portName, baud); | |||
commProxy.SetDataStorage(dataStorage); | |||
commandHandler.Init(commProxy); | |||
commandHandler.PauseAsk = delegate (bool pause) | |||
{ | |||
free = !pause; | |||
}; | |||
//commProxy = new SerialPortClient(portName, baud); | |||
//commProxy.SetDataStorage(dataStorage); | |||
//commandHandler.Init(commProxy); | |||
//commandHandler.PauseAsk = delegate (bool pause) | |||
//{ | |||
// free = !pause; | |||
//}; | |||
} | |||
/// <summary> | |||
/// 主线程开始运行 | |||
/// </summary> | |||
public void Start() | |||
public override void Start() | |||
{ | |||
commProxy.Start(); | |||
running = true; | |||
@@ -93,7 +94,7 @@ namespace HBLDevice.Coffee | |||
/// <summary> | |||
/// 停止运行 | |||
/// </summary> | |||
public void Stop() | |||
public override void Stop() | |||
{ | |||
commProxy.Stop(); | |||
running = false; | |||
@@ -151,5 +152,15 @@ namespace HBLDevice.Coffee | |||
Thread.Sleep(5); | |||
}), "咖啡机解析线程"); | |||
} | |||
protected override void InitStatus() | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public override void Init() | |||
{ | |||
} | |||
} | |||
} |
@@ -11,7 +11,7 @@ using System.Text; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
namespace HBLDevice.Coffee | |||
namespace BPASmartClient.DRCoffee | |||
{ | |||
/// <summary> | |||
/// 指令封装 | |||
@@ -6,7 +6,7 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace HBLDevice.Coffee | |||
namespace BPASmartClient.DRCoffee | |||
{ | |||
public class MorkCStatus | |||
{ | |||
@@ -4,4 +4,8 @@ | |||
<TargetFramework>net6.0</TargetFramework> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,41 @@ | |||
using BPASmartClient.Peripheral; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Device | |||
{ | |||
/// <summary> | |||
/// 设备基类 | |||
/// </summary> | |||
public abstract class BaseDevice : IDevice | |||
{ | |||
/// <summary> | |||
/// 设备ID | |||
/// </summary> | |||
public string DeviceId { get; set; } | |||
/// <summary> | |||
/// 设备所有状态 | |||
/// </summary> | |||
public DeviceStatus Status { get; set; } | |||
public string Name { get; set; } | |||
public void Initliaze() | |||
{ | |||
} | |||
public void Initliaze(List<IPeripheral> peripherals) | |||
{ | |||
peripherals.ForEach(p => { | |||
p.DeviceId = this.DeviceId; | |||
p.Init(); | |||
}); | |||
} | |||
public abstract void StartMain(); | |||
public abstract void Stop(); | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
using System; | |||
using BPASmartClient.Peripheral; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -11,11 +12,19 @@ namespace BPASmartClient.Device | |||
/// </summary> | |||
public interface IDevice | |||
{ | |||
/// <summary> | |||
/// 设备ID | |||
/// </summary> | |||
string DeviceId { get; set; } | |||
string Name { get; set; } | |||
/// <summary> | |||
/// 设备所有状态 | |||
/// </summary> | |||
DeviceStatus Status { get; set; } | |||
/// <summary> | |||
/// 初始化设备加载 | |||
/// </summary> | |||
void Initliaze(); | |||
void Initliaze(List<IPeripheral> peripherals); | |||
/// <summary> | |||
/// 开启设备主任务 | |||
/// </summary> | |||
@@ -0,0 +1,13 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<Nullable>enable</Nullable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.Helper\BPASmartClient.Helper.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,128 @@ | |||
using BPASmartClient.Helper; | |||
using System; | |||
using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
/* *********************************************** | |||
* subject 事件总线,总线入口,后续按类型分发 | |||
* author 张原川 | |||
* date 2019/6/3 15:49:03 | |||
* ***********************************************/ | |||
namespace BPASmartClient.EventBus | |||
{ | |||
/// <summary> | |||
/// 事件总线 | |||
/// </summary> | |||
public class EventBus : Singleton<EventBus> | |||
{ | |||
/// <summary> | |||
/// 事件处理委托 | |||
/// </summary> | |||
/// <param name="args"></param> | |||
public delegate void EventCallBackHandle(params object[] args); | |||
/// <summary> | |||
/// 事件处理委托 | |||
/// </summary> | |||
/// <param name="event"></param> | |||
/// <param name="callBack"></param> | |||
public delegate void EventHandle(IEvent @event, EventCallBackHandle callBack = null); | |||
/// <summary> | |||
/// 事件订阅者集合 | |||
/// </summary> | |||
private ConcurrentDictionary<string, ConcurrentDictionary<Type, List<EventHandle>>> _eventHandls = new ConcurrentDictionary<string, ConcurrentDictionary<Type, List<EventHandle>>>(); | |||
/// <summary> | |||
/// 事件订阅 | |||
/// </summary> | |||
public void Subscribe<TEvent>(string id,EventHandle handle) | |||
{ | |||
if (!_eventHandls.ContainsKey(id)) | |||
_eventHandls.TryAdd(id, new ConcurrentDictionary<Type, List<EventHandle>>()); | |||
if (!_eventHandls[id].ContainsKey(typeof(TEvent))) | |||
_eventHandls[id].TryAdd(typeof(TEvent), new List<EventHandle>()); | |||
lock (_eventHandls) | |||
_eventHandls[id][typeof(TEvent)].Add(handle); | |||
} | |||
/// <summary> | |||
/// 事件退订 | |||
/// </summary> | |||
public void UnSubscribe<TEvent>(string id,EventHandle handle) | |||
{ | |||
if (_eventHandls.ContainsKey(id)) | |||
{ | |||
if (_eventHandls[id].ContainsKey(typeof(TEvent))) | |||
{ | |||
if (_eventHandls[id][typeof(TEvent)].Contains(handle)) | |||
{ | |||
lock (_eventHandls) | |||
_eventHandls[id][typeof(TEvent)].Remove(handle); | |||
} | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 事件发布,不带返回 | |||
/// </summary> | |||
public void Publish<TEvent>(TEvent @event) where TEvent : IEvent | |||
{ | |||
if (_eventHandls.ContainsKey(@event.Id)) | |||
{ | |||
if (_eventHandls[@event.Id].ContainsKey(typeof(TEvent))) | |||
{ | |||
for (int i = _eventHandls[@event.Id][typeof(TEvent)].Count - 1; i >= 0; i--) | |||
_eventHandls[@event.Id][typeof(TEvent)][i](@event); | |||
//_eventHandls[typeof(TEvent)].ForEach(p => | |||
//{ | |||
// p(@event); | |||
//}); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 事件发布,带返回 | |||
/// </summary> | |||
public void Publish<TEvent>(TEvent @event, EventCallBackHandle eventCallBack) where TEvent : IEvent | |||
{ | |||
List<object> result = new List<object>(); | |||
if (_eventHandls.ContainsKey(@event.Id)) | |||
{ | |||
if (_eventHandls[@event.Id].ContainsKey(typeof(TEvent))) | |||
{ | |||
//_eventHandls[typeof(TEvent)].ForEach(p => | |||
//{ | |||
// p(@event, delegate (object[] args) | |||
// { | |||
// result.AddRange(args); | |||
// }); | |||
//}); | |||
for (int i = _eventHandls[@event.Id][typeof(TEvent)].Count - 1; i >= 0; i--) | |||
{ | |||
_eventHandls[@event.Id][typeof(TEvent)][i](@event, delegate (object[] args) | |||
{ | |||
result.AddRange(args); | |||
}); | |||
} | |||
} | |||
} | |||
eventCallBack.Invoke(result.ToArray()); | |||
} | |||
/// <summary> | |||
/// 事件总线释放 | |||
/// </summary> | |||
public void Dispose() | |||
{ | |||
_eventHandls.Clear(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
namespace BPASmartClient.EventBus | |||
{ | |||
/// <summary> | |||
/// 事件接口 | |||
/// </summary> | |||
public interface IEvent | |||
{ | |||
string Id { get; set; } | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
/* ============================================================================== | |||
* 功能描述: | |||
* 创 建 者:张原川 | |||
* 创建日期:2016/10/10 16:50:12 | |||
* ==============================================================================*/ | |||
namespace BPASmartClient.EventBus | |||
{ | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
public static class IEventExtends | |||
{ | |||
#region Methods - Public | |||
/// <summary> | |||
/// 发布 | |||
/// </summary> | |||
/// <typeparam name="TEvent"></typeparam> | |||
/// <param name="message"></param> | |||
public static void Publish<TEvent>(this TEvent message) where TEvent : class, IEvent | |||
{ | |||
EventBus.GetInstance().Publish<TEvent>(message); | |||
} | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <typeparam name="TEvent"></typeparam> | |||
/// <param name="message"></param> | |||
/// <param name="eventCallBack"></param> | |||
public static void Publish<TEvent>(this TEvent message, EventBus.EventCallBackHandle eventCallBack) where TEvent : class, IEvent | |||
{ | |||
EventBus.GetInstance().Publish<TEvent>(message, eventCallBack); | |||
} | |||
#endregion | |||
} | |||
} |
@@ -27,8 +27,8 @@ namespace BPASmartClient.Helper | |||
{ | |||
get | |||
{ | |||
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{LocaPath.GetInstance.FilePath}\\JSON")); | |||
return $"{AppDomain.CurrentDomain.BaseDirectory}{LocaPath.GetInstance.FilePath}JSON\\{typeof(T).Name}.json"; | |||
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{LocaPath.GetInstance().FilePath}\\JSON")); | |||
return $"{AppDomain.CurrentDomain.BaseDirectory}{LocaPath.GetInstance().FilePath}JSON\\{typeof(T).Name}.json"; | |||
} | |||
} | |||
@@ -7,12 +7,9 @@ using System.Threading.Tasks; | |||
namespace BPASmartClient.Helper | |||
{ | |||
public class LocaPath | |||
public class LocaPath:Singleton<LocaPath> | |||
{ | |||
private volatile static LocaPath _Instance; | |||
public static LocaPath GetInstance => _Instance ?? (_Instance = new LocaPath()); | |||
private LocaPath() { } | |||
public string FilePath { get; set; } = string.Empty; | |||
@@ -22,8 +22,8 @@ namespace BPASmartClient.Helper | |||
{ | |||
if (info?.Length > 0) | |||
{ | |||
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{LocaPath.GetInstance.FilePath}\\{DicrectoryName}")); | |||
string path = $"{AppDomain.CurrentDomain.BaseDirectory}{LocaPath.GetInstance.FilePath}\\{DicrectoryName}\\{DateTime.Now.ToString("yyyy-MM-dd") + " " + name}.txt"; | |||
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{LocaPath.GetInstance().FilePath}\\{DicrectoryName}")); | |||
string path = $"{AppDomain.CurrentDomain.BaseDirectory}{LocaPath.GetInstance().FilePath}\\{DicrectoryName}\\{DateTime.Now.ToString("yyyy-MM-dd") + " " + name}.txt"; | |||
StringBuilder sb = new StringBuilder(); | |||
sb.Append($"****************************************** {DateTime.Now} ******************************************" + "\n"); | |||
sb.Append(info); | |||
@@ -0,0 +1,85 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.IO; | |||
using System.Data; | |||
using System.Xml; | |||
using System.Xml.Serialization; | |||
namespace BPASmartClient.Helper | |||
{ | |||
/// <summary> | |||
/// Xml序列化与反序列化 | |||
/// </summary> | |||
public class XmlUtil | |||
{ | |||
#region 反序列化 | |||
/// <summary> | |||
/// 反序列化 | |||
/// </summary> | |||
/// <param name="type">类型</param> | |||
/// <param name="xml">XML字符串</param> | |||
/// <returns></returns> | |||
public static object Deserialize(Type type, string xml) | |||
{ | |||
try | |||
{ | |||
using (StringReader sr = new StringReader(xml)) | |||
{ | |||
XmlSerializer xmldes = new XmlSerializer(type); | |||
return xmldes.Deserialize(sr); | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
return null; | |||
} | |||
} | |||
/// <summary> | |||
/// 反序列化 | |||
/// </summary> | |||
/// <param name="type"></param> | |||
/// <param name="xml"></param> | |||
/// <returns></returns> | |||
public static object Deserialize(Type type, Stream stream) | |||
{ | |||
XmlSerializer xmldes = new XmlSerializer(type); | |||
return xmldes.Deserialize(stream); | |||
} | |||
#endregion | |||
#region 序列化 | |||
/// <summary> | |||
/// 序列化 | |||
/// </summary> | |||
/// <param name="type">类型</param> | |||
/// <param name="obj">对象</param> | |||
/// <returns></returns> | |||
public static string Serializer(Type type, object obj) | |||
{ | |||
MemoryStream Stream = new MemoryStream(); | |||
XmlSerializer xml = new XmlSerializer(type); | |||
try | |||
{ | |||
//序列化对象 | |||
xml.Serialize(Stream, obj); | |||
} | |||
catch (InvalidOperationException) | |||
{ | |||
throw; | |||
} | |||
Stream.Position = 0; | |||
StreamReader sr = new StreamReader(Stream); | |||
string str = sr.ReadToEnd(); | |||
sr.Dispose(); | |||
Stream.Dispose(); | |||
return str; | |||
} | |||
#endregion | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -7,8 +7,10 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.EventBus\BPASmartClient.EventBus.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Helper\BPASmartClient.Helper.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Message\BPASmartClient.Message.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | |||
<ProjectReference Include="..\Lebai.SDK\Lebai.SDK.csproj" /> | |||
</ItemGroup> | |||
@@ -11,6 +11,9 @@ using BPASmartClient.Message; | |||
using BPASmartClient.Helper; | |||
using TaskStatus = Lebai.SDK.Dtos.TaskStatus; | |||
using BPASmartClient.Peripheral; | |||
using BPASmartClient.EventBus; | |||
using static BPASmartClient.EventBus.EventBus; | |||
using BPASmartClient.Model; | |||
namespace BPASmartClient.Lebai | |||
{ | |||
@@ -240,5 +243,13 @@ namespace BPASmartClient.Lebai | |||
public override void Stop() | |||
{ | |||
} | |||
public override void Init() | |||
{ | |||
EventBus.EventBus.GetInstance().Subscribe<Demo_MakeCoffeeEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack ) | |||
{ | |||
}); | |||
} | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<Nullable>enable</Nullable> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.EventBus\BPASmartClient.EventBus.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,14 @@ | |||
using BPASmartClient.EventBus; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Model | |||
{ | |||
public class BaseEvent : IEvent | |||
{ | |||
public string Id { get; set; } | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using BPASmartClient.EventBus; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Model | |||
{ | |||
public class Demo_MakeCoffeeEvent : BaseEvent | |||
{ | |||
} | |||
} |
@@ -0,0 +1,27 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Model | |||
{ | |||
public class DeviceConfigModel | |||
{ | |||
public List<DeviceConfig> Devices { get; set; } = new List<DeviceConfig>(); | |||
} | |||
public class DeviceConfig | |||
{ | |||
public string Name { get; set; } | |||
public string Module { get; set; } | |||
public string DeviceId { get; set; } | |||
public List<Peripheral> Peripherals { get; set; } = new List<Peripheral>(); | |||
} | |||
public class Peripheral | |||
{ | |||
public string Module { get; set; } | |||
public Dictionary<string, string> Parameters { get; set; } = new Dictionary<string, string>(); | |||
} | |||
} |
@@ -4,4 +4,8 @@ | |||
<TargetFramework>net6.0</TargetFramework> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.Device\BPASmartClient.Device.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,6 @@ | |||
using System; | |||
using BPASmartClient.Device; | |||
using BPASmartClient.Peripheral; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -6,9 +8,14 @@ using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkT | |||
{ | |||
public class Device_MorkT | |||
public class Device_MorkT : BaseDevice | |||
{ | |||
} | |||
public override void StartMain() | |||
{ | |||
} | |||
public override void Stop() | |||
{ | |||
} | |||
} | |||
} |
@@ -9,7 +9,7 @@ namespace BPASmartClient.Peripheral | |||
/// <summary> | |||
/// 外设基类 | |||
/// </summary> | |||
public abstract class BasePeripheral : IBasePeripheral | |||
public abstract class BasePeripheral : IPeripheral | |||
{ | |||
/// <summary> | |||
/// 是否已连接 | |||
@@ -19,6 +19,11 @@ namespace BPASmartClient.Peripheral | |||
/// 是否工作正常 | |||
/// </summary> | |||
public bool IsWork { get; protected set; } | |||
/// <summary> | |||
/// 归属设备Id | |||
/// </summary> | |||
public string DeviceId { get; set; } | |||
/// <summary> | |||
/// 外设状态集合 | |||
/// </summary> | |||
@@ -41,6 +46,6 @@ namespace BPASmartClient.Peripheral | |||
public abstract void Stop(); | |||
public abstract void Init(); | |||
} | |||
} |
@@ -9,8 +9,12 @@ namespace BPASmartClient.Peripheral | |||
/// <summary> | |||
/// 外设接口 | |||
/// </summary> | |||
public interface IBasePeripheral | |||
public interface IPeripheral | |||
{ | |||
/// <summary> | |||
/// 设备ID | |||
/// </summary> | |||
string DeviceId { get; set; } | |||
/// <summary> | |||
/// 获取指定状态值 | |||
/// </summary> | |||
@@ -18,6 +22,10 @@ namespace BPASmartClient.Peripheral | |||
/// <returns>状态值</returns> | |||
object? GetStatus(string statusName); | |||
/// <summary> | |||
/// 初始化 | |||
/// </summary> | |||
void Init(); | |||
/// <summary> | |||
/// 驱动开启 | |||
/// </summary> | |||
void Start(); |
@@ -6,6 +6,7 @@ | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.SerialPort\BPASmartClient.SerialPort.csproj" /> | |||
</ItemGroup> | |||
@@ -1,4 +1,5 @@ | |||
using BPASmartClient.Helper; | |||
using BPASmartClient.Peripheral; | |||
using BPASmartClient.SerialPort; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -7,7 +8,7 @@ using System.Threading; | |||
namespace BPASmartClient.SCChip | |||
{ | |||
public class ICChipMachine | |||
public class ICChipMachine: BasePeripheral | |||
{ | |||
//指令组装 | |||
private CommandHandler commandHandler = new CommandHandler(); | |||
@@ -23,23 +24,21 @@ namespace BPASmartClient.SCChip | |||
public ICChipMachine(string portName, BaudRates baud) | |||
public ICChipMachine() | |||
{ | |||
commProxy = new SerialPortClient(portName, baud); | |||
commProxy.SetDataStorage(dataStorage); | |||
commandHandler.Init(commProxy); | |||
//commProxy = new SerialPortClient(portName, baud); | |||
//commProxy.SetDataStorage(dataStorage); | |||
//commandHandler.Init(commProxy); | |||
} | |||
public void Start() | |||
public override void Start() | |||
{ | |||
commProxy.Start(); | |||
running = true; | |||
MainLoop(); | |||
} | |||
public void Stop() | |||
{ | |||
} | |||
private void MainLoop() | |||
{ | |||
@@ -96,6 +95,18 @@ namespace BPASmartClient.SCChip | |||
} | |||
return structure; | |||
} | |||
protected override void InitStatus() | |||
{ | |||
} | |||
public override void Stop() | |||
{ | |||
} | |||
public override void Init() | |||
{ | |||
} | |||
} | |||
} |
@@ -7,4 +7,22 @@ | |||
<UseWPF>true</UseWPF> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmartClient.Business\BPASmartClient.Business.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.DRCoffee\BPASmartClient.DRCoffee.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.GSIceCream\BPASmartClient.GSIceCream.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.KLMCoffee\BPASmartClient.KLMCoffee.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.Lebai\BPASmartClient.Lebai.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.MorkD\BPASmartClient.MorkD.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.MorkS\BPASmartClient.MorkS.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.MorkT\BPASmartClient.MorkT.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.SCChip\BPASmartClient.SCChip.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Update="DeviceInfo.xml"> | |||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |||
</None> | |||
</ItemGroup> | |||
</Project> |
@@ -1,6 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8" ?> | |||
<BPADevices> | |||
<Device Name="MorkT" Module="Device_MorkT" ClientId=""> | |||
<Device Name="MorkT" Module="BPASmartClient.MorkT.Device_MorkT" DeviceId="1"> | |||
<Peripherals> | |||
<Peripheral Module="BPASmartClient.Lebai.LebaiRobot"> | |||
<Parameters> | |||
@@ -9,16 +9,12 @@ | |||
<OutputSingalValue>0</OutputSingalValue> | |||
</Parameters> | |||
</Peripheral> | |||
<Peripheral Module="BPASmartClient.DRCoffee"> | |||
<Peripheral Module="BPASmartClient.DRCoffee.CoffeeMachine"> | |||
<Parameters> | |||
<COM>COM5</COM> | |||
<BaudRate>9600</BaudRate> | |||
</Parameters> | |||
</Peripheral> | |||
<Peripheral Module="BPASmartClient.BPASmartClient.SCChip"> | |||
<Peripheral Module="BPASmartClient.SCChip.ICChipMachine"> | |||
<Parameters> | |||
<COM>COM6</COM> | |||
<BaudRate>115200</BaudRate> | |||
</Parameters> | |||
</Peripheral> | |||
</Peripherals> | |||
@@ -7,6 +7,7 @@ | |||
mc:Ignorable="d" | |||
Title="MainWindow" Height="450" Width="800"> | |||
<Grid> | |||
<Button Content="Button" HorizontalAlignment="Left" Margin="153,123,0,0" VerticalAlignment="Top" Click="Button_Click"/> | |||
</Grid> | |||
</Window> |
@@ -1,4 +1,7 @@ | |||
using System; | |||
using BPASmartClient.Business; | |||
using BPASmartClient.EventBus; | |||
using BPASmartClient.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -22,7 +25,13 @@ namespace BPASmartClient | |||
{ | |||
public MainWindow() | |||
{ | |||
Plugin.GetInstance().Init(); | |||
InitializeComponent(); | |||
} | |||
private void Button_Click(object sender, RoutedEventArgs e) | |||
{ | |||
new Demo_MakeCoffeeEvent() { Id = "1" }.Publish(); | |||
} | |||
} | |||
} |
@@ -63,6 +63,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.OrderProxy", | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MessageCommunication", "BPASmartClient.MessageCommunication\BPASmartClient.MessageCommunication.csproj", "{DCC07B39-E342-4841-B9E4-4D44DA2978FD}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.EventBus", "BPASmartClient.EventBus\BPASmartClient.EventBus.csproj", "{C7FC5FC8-4C72-4CD3-973E-327BDA880DF5}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.Model", "BPASmartClient.Model\BPASmartClient.Model.csproj", "{268012B6-C4FC-4C40-802C-74D5FAD3CA45}" | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.Business", "BPASmartClient.Business\BPASmartClient.Business.csproj", "{EF5EF8EF-4A44-4E44-9594-D878CABC4182}" | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1E1191EB-9EA8-460E-A0A3-15DF0BC2EDAB}" | |||
ProjectSection(SolutionItems) = preProject | |||
.editorconfig = .editorconfig | |||
EndProjectSection | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -165,6 +176,18 @@ Global | |||
{DCC07B39-E342-4841-B9E4-4D44DA2978FD}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{DCC07B39-E342-4841-B9E4-4D44DA2978FD}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{DCC07B39-E342-4841-B9E4-4D44DA2978FD}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{C7FC5FC8-4C72-4CD3-973E-327BDA880DF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{C7FC5FC8-4C72-4CD3-973E-327BDA880DF5}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{C7FC5FC8-4C72-4CD3-973E-327BDA880DF5}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{C7FC5FC8-4C72-4CD3-973E-327BDA880DF5}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{268012B6-C4FC-4C40-802C-74D5FAD3CA45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{268012B6-C4FC-4C40-802C-74D5FAD3CA45}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{268012B6-C4FC-4C40-802C-74D5FAD3CA45}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{268012B6-C4FC-4C40-802C-74D5FAD3CA45}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{EF5EF8EF-4A44-4E44-9594-D878CABC4182}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{EF5EF8EF-4A44-4E44-9594-D878CABC4182}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{EF5EF8EF-4A44-4E44-9594-D878CABC4182}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{EF5EF8EF-4A44-4E44-9594-D878CABC4182}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
@@ -194,6 +217,9 @@ Global | |||
{9F5E2879-972A-45FB-913C-89E9F0CEB189} = {666CB1A9-562E-453A-A2C7-FD9D77CFDFDD} | |||
{EBDFF87C-0B98-4BB5-8760-D86964E38A88} = {6CEA3385-6F62-452A-8275-033A6037235D} | |||
{DCC07B39-E342-4841-B9E4-4D44DA2978FD} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625} | |||
{C7FC5FC8-4C72-4CD3-973E-327BDA880DF5} = {1A9920BA-7C8D-4BDC-8D7D-6544A71AF3CF} | |||
{268012B6-C4FC-4C40-802C-74D5FAD3CA45} = {1A9920BA-7C8D-4BDC-8D7D-6544A71AF3CF} | |||
{EF5EF8EF-4A44-4E44-9594-D878CABC4182} = {6CEA3385-6F62-452A-8275-033A6037235D} | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC} | |||