|
|
@@ -73,7 +73,6 @@ namespace UHFHelper |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private object asy = new object(); |
|
|
|
/// <summary> |
|
|
|
/// 读卡方法,返回读卡器数据 |
|
|
|
/// </summary> |
|
|
@@ -81,39 +80,36 @@ namespace UHFHelper |
|
|
|
/// <returns></returns> |
|
|
|
public DKoutput? ReadCard(int adr) |
|
|
|
{ |
|
|
|
lock (asy) |
|
|
|
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 |
|
|
|
{ |
|
|
|
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) |
|
|
|
//获取校验码 |
|
|
|
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()) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
dKoutput.Address = address.ByteArrayToHexString(); |
|
|
|
dKoutput.ResData = cardNo.ByteArrayToHexString(); |
|
|
|
return dKoutput; |
|
|
|
} |
|
|
|
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; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|