From 367c8fc1f12ea854f7bd2efc084429540697ed85 Mon Sep 17 00:00:00 2001 From: xxe Date: Thu, 22 Sep 2022 11:37:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardOUT/Bootstrapper.cs | 1 + HKCardOUT/HKCardOUT.csproj | 2 + HKCardOUT/Helper/DataBus.cs | 1 + HKCardOUT/ViewModels/RootViewModel.cs | 56 +++++++++++++++++++++++++-- HKCardOUT/options.json | 1 + 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/HKCardOUT/Bootstrapper.cs b/HKCardOUT/Bootstrapper.cs index 920321b..0e38a83 100644 --- a/HKCardOUT/Bootstrapper.cs +++ b/HKCardOUT/Bootstrapper.cs @@ -39,6 +39,7 @@ namespace HKCardOUT DataBus.Cron = configer["Cron"]; DataBus.SaasRoute = configer["SaasRoute"]; DataBus.StoreId = configer["StoreId"]; + DataBus.COM = configer["COM"]; DbContext.InitTable(); RemoteService.PullShopInfo(); base.Configure(); diff --git a/HKCardOUT/HKCardOUT.csproj b/HKCardOUT/HKCardOUT.csproj index 64fea3c..ea1be6f 100644 --- a/HKCardOUT/HKCardOUT.csproj +++ b/HKCardOUT/HKCardOUT.csproj @@ -51,5 +51,7 @@ + + diff --git a/HKCardOUT/Helper/DataBus.cs b/HKCardOUT/Helper/DataBus.cs index a9505f8..5cbf872 100644 --- a/HKCardOUT/Helper/DataBus.cs +++ b/HKCardOUT/Helper/DataBus.cs @@ -27,6 +27,7 @@ namespace HKCardOUT.Helper public static bool NetWordState { get; set; } = false; public static string Cron { get; set; } public static string StoreId { get; set; } + public static string COM { get; set; } public static string SaasRoute { get; set; } public static StoreInfoResponse StoreInfo { get; set; } public static Dictionary AdStatus { get; set; } = new Dictionary(); diff --git a/HKCardOUT/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index be14a40..ee8fc4d 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -1,21 +1,25 @@ using DTO; using HKCardOUT.Helper; -using HKCardOUT.Logic; using HKCardOUT.Logic.Model; using HKCardOUT.Logic.Service; using Stylet; using StyletIoC; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading; using System.Windows.Documents; +using UHFHelper; +using XExten.Advance.CacheFramework; +using XExten.Advance.CacheFramework.RunTimeCache; +using XExten.Advance.LinqFramework; namespace HKCardOUT.ViewModels { public class RootViewModel : Conductor { + public delegate void ReadCardFunc(DKoutput? input); + public event ReadCardFunc ReadFunc; IContainer Container; public RootViewModel(IContainer Container) { @@ -35,8 +39,8 @@ namespace HKCardOUT.ViewModels { Ad = x.Remaek, IsActive = false, - Device =t.Name, - Stalls=x.Name + Device = t.Name, + Stalls = x.Name }).ToList(); if (Init != null) Ad = new ObservableCollection(Init); @@ -60,6 +64,8 @@ namespace HKCardOUT.ViewModels #region 方法 private void MainThread() { + ReadFunc -= ReadCard; + ReadFunc += ReadCard; ThreadManage.GetInstance().StartLong(new Action(() => { try @@ -79,6 +85,34 @@ namespace HKCardOUT.ViewModels HandyControl.Controls.Growl.InfoGlobal(ex.Message); } }), "循环状态监测线程", false); + // 初始化 串口 + UHF_RS485_Helper.GetInstance().Open(new SerialParam + { + PortName = DataBus.COM, + BaudRate = 57600, + DataBits = 8 + }); + + if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) + HandyControl.Controls.Growl.InfoGlobal("串口打开失败"); + //读取读卡器 + ThreadManage.GetInstance().StartLong(new Action(() => + { + DataBus.StoreInfo.Devices.ForEach(async item => + { + if (UHF_RS485_Helper.GetInstance().GetSerialPortState()) + { + HandyControl.Controls.Growl.InfoGlobal("串口未链接"); + } + else + { + var x = await UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); + if (x != null) + ReadFunc?.Invoke(x); + } + }); + Thread.Sleep(300); + }), "循环读取卡片内容", false); } #endregion @@ -112,6 +146,20 @@ namespace HKCardOUT.ViewModels } } } + public void ReadCard(DKoutput input) + { + var key = input.Address + ":" + input.ResData; + //没有超时第一是刷 + if (Caches.RunTimeCacheGet(key) == null) + { + Container.Get().DeviceSale(new SaleLog + { + CardNo = input.ResData.Substring(1, input.ResData.Length), + Location = input.Address.AsInt().ToString() + }); + Caches.RunTimeCacheSet(key, input, 10, true); + } + } #endregion } } diff --git a/HKCardOUT/options.json b/HKCardOUT/options.json index 804e359..13cea15 100644 --- a/HKCardOUT/options.json +++ b/HKCardOUT/options.json @@ -1,6 +1,7 @@ { //服务地址 "SaasRoute": "https://bpa.black-pa.com:21527/kitchen/", + "COM": "COM5", //定时任务时间表达式 "Cron": "0 0 11,15 * * ? ", //店铺ID