xxe 2 years ago
parent
commit
310655a0b9
4 changed files with 75 additions and 56 deletions
  1. +2
    -2
      HKCardOUT/HKCardOUT.csproj
  2. +33
    -25
      HKCardOUT/ViewModels/RootViewModel.cs
  3. +1
    -1
      HKCardOUT/options.pro.json
  4. +39
    -28
      UHFHelper/UHF_RS485_Helper.cs

+ 2
- 2
HKCardOUT/HKCardOUT.csproj View File

@@ -14,9 +14,9 @@
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
<!--<PropertyGroup>
<PropertyGroup>
<ApplicationManifest>App.manifest</ApplicationManifest>
</PropertyGroup>-->
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;Core</DefineConstants>
</PropertyGroup>


+ 33
- 25
HKCardOUT/ViewModels/RootViewModel.cs View File

@@ -82,9 +82,9 @@ namespace HKCardOUT.ViewModels
if (DataBus.StoreInfo != null)
{
DKoutput res = null;
Monitor.TryEnter(async, 2000);
//Monitor.TryEnter(async, 2000);
res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt());
Monitor.Exit(async);
//Monitor.Exit(async);
if (res != null)
{
HKLog.HKLogImport.WriteInfo($"{DateTime.Now.ToString("HH:mm:ss")} 卡号地址:{res.Address}----------卡号数据:{res.ResData}");
@@ -236,35 +236,43 @@ namespace HKCardOUT.ViewModels
{
if (Info != null)
{
var Core = Container.Get<HKCore>();
HKLogImport.WriteInfo("队列读取成功:" + Info.ToJson());
if (Info.Date >= DataBus.Times.AMStartTime && Info.Date < DataBus.Times.AMEndTime)
if (!HKControl.Main.GetInstance.GetIsSwipe(Info.Location.AsInt()))
{
Core.DeviceSaleAM(new SaleLog
{
CardNo = Info.CardNo,
Location = Info.Location,
IsSync = false
});
Stacks.Enqueue(Info);
}
if (Info.Date >= DataBus.Times.PMStartTime && Info.Date < DataBus.Times.PMEndTime)
else
{
Core.DeviceSalePM(new SaleLog
var Core = Container.Get<HKCore>();
HKLogImport.WriteInfo("队列读取成功:" + Info.ToJson());
if (Info.Date >= DataBus.Times.AMStartTime && Info.Date < DataBus.Times.AMEndTime)
{
Core.DeviceSaleAM(new SaleLog
{
CardNo = Info.CardNo,
Location = Info.Location,
IsSync = false
});
}
if (Info.Date >= DataBus.Times.PMStartTime && Info.Date < DataBus.Times.PMEndTime)
{
CardNo = Info.CardNo,
Location = Info.Location,
IsSync = false
});
Core.DeviceSalePM(new SaleLog
{
CardNo = Info.CardNo,
Location = Info.Location,
IsSync = false
});

}
if (Info.Date >= DataBus.Times.ATStartTime && Info.Date < DataBus.Times.ATEndTime)
{
Core.DeviceSaleAT(new SaleLog
}
if (Info.Date >= DataBus.Times.ATStartTime && Info.Date < DataBus.Times.ATEndTime)
{
CardNo = Info.CardNo,
Location = Info.Location,
IsSync = false
});
Core.DeviceSaleAT(new SaleLog
{
CardNo = Info.CardNo,
Location = Info.Location,
IsSync = false
});

}
}
}
}


+ 1
- 1
HKCardOUT/options.pro.json View File

@@ -3,7 +3,7 @@
//服务地址
"SaasRoute": "https://witt.black-pa.com/kitchen/",
//启动设备调试
"StartDevice": false,
"StartDevice": true,
//串口
"COM": "COM8",
//定时任务时间表达式 每隔6小时推送一次


+ 39
- 28
UHFHelper/UHF_RS485_Helper.cs View File

@@ -72,7 +72,7 @@ namespace UHFHelper
_serialPort = null;
}

private object async = new object();
/// <summary>
/// 读卡方法,返回读卡器数据
/// </summary>
@@ -80,36 +80,47 @@ namespace UHFHelper
/// <returns></returns>
public DKoutput? ReadCard(int adr)
{
if (_serialPort == null) return null;
DKoutput dKoutput = new();
var readByte = ReadByte(adr);
_serialPort.Write(readByte, 0, readByte.Length);
var result = SendMessage(readByte, 150, 18);
if (result == null)
{
return null;
}
else
lock (async)
{
//获取校验码
var crc = result.Skip(16).Take(2).ToArray();
//获取卡号
var cardNo = result.Skip(6).Take(10).ToArray();
//获取读卡器数据
var readData = result.Skip(0).Take(16).ToArray();
//获取读卡器地址
var address = result.Skip(1).Take(1).ToArray();
//判断数据是否合法
var temcrc = CRC16.ToCRC16(readData);
if (crc.ByteArrayToHexString() == temcrc.ByteArrayToHexString())
try
{
dKoutput.Address = address.ByteArrayToHexString();
dKoutput.ResData = cardNo.ByteArrayToHexString();
return dKoutput;
if (_serialPort == null) return null;
DKoutput dKoutput = new();
var readByte = ReadByte(adr);
_serialPort.Write(readByte, 0, readByte.Length);
var result = SendMessage(readByte, 150, 18);
if (result == null)
{
return null;
}
else
{
//获取校验码
var crc = result.Skip(16).Take(2).ToArray();
//获取卡号
var cardNo = result.Skip(6).Take(10).ToArray();
//获取读卡器数据
var readData = result.Skip(0).Take(16).ToArray();
//获取读卡器地址
var address = result.Skip(1).Take(1).ToArray();
//判断数据是否合法
var temcrc = CRC16.ToCRC16(readData);
if (crc.ByteArrayToHexString() == temcrc.ByteArrayToHexString())
{
dKoutput.Address = address.ByteArrayToHexString();
dKoutput.ResData = cardNo.ByteArrayToHexString();
return dKoutput;
}
else
{
return null;
}

}
}
else
{
return null;
catch (Exception ex) {
return null;
}
}
}


Loading…
Cancel
Save