From 3bf1b8e35c4df1658a3ac12e4387125db7f6426e Mon Sep 17 00:00:00 2001 From: xxe Date: Fri, 30 Sep 2022 11:53:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=AD=E7=BD=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardOUT/ViewModels/RootViewModel.cs | 57 ++++++--------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/HKCardOUT/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index 7113e97..3c324c1 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -79,16 +79,21 @@ namespace HKCardOUT.ViewModels { if (UHF_RS485_Helper.GetInstance().GetSerialPortState()) { - DataBus.StoreInfo.Devices.ForEach(item => + if (DataBus.StoreInfo != null) { - var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); - - if (res != null) + DataBus.StoreInfo.Devices.ForEach(item => { - if (!res.ResData.IsMatch(new Regex("0{20}"))) - ReadFunc?.Invoke(res); - } - }); + var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); + + if (res != null) + { + if (!res.ResData.IsMatch(new Regex("0{20}"))) + ReadFunc?.Invoke(res); + } + }); + } + else + HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络,并重启程序!"); } Thread.Sleep(10); @@ -112,42 +117,6 @@ namespace HKCardOUT.ViewModels }), "打开串口"); } - /// - /// 读取信息 - /// - public void GetData() - { - //开启循环监听数据 - timer1.Interval = 500; - timer1.Elapsed += (o, a) => - { - if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) - { - HandyControl.Controls.Growl.InfoGlobal("串口打开失败"); - timer1.Stop(); - return; - } - else - { - if (DataBus.NetWordState) - { - DataBus.StoreInfo.Devices.ForEach(item => - { - var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); - - if (res != null) - { - if (!res.ResData.IsMatch(new Regex("0{20}"))) - ReadFunc?.Invoke(res); - } - }); - } - else - HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络,并重启程序!"); - } - }; - timer1.Start(); - } protected override void OnViewLoaded() { //广告初始化