|
|
@@ -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<IScreen> |
|
|
|
{ |
|
|
|
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<AdDTO>(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<DKoutput>(key) == null) |
|
|
|
{ |
|
|
|
Container.Get<HKCore>().DeviceSale(new SaleLog |
|
|
|
{ |
|
|
|
CardNo = input.ResData.Substring(1, input.ResData.Length), |
|
|
|
Location = input.Address.AsInt().ToString() |
|
|
|
}); |
|
|
|
Caches.RunTimeCacheSet(key, input, 10, true); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |