using System.Runtime.InteropServices; using System.Text; namespace UHFHelper { public static class UHFHelper { /// /// 解析数据 /// /// /// public static string ByteArrayToHexString(this byte[] data) { StringBuilder sb = new(data.Length * 3); foreach (byte b in data) sb.Append(Convert.ToString(b, 16).PadLeft(2, '0')); return sb.ToString().ToUpper(); } } public class Resultoutput { public bool Res { get; set; } public string? ResMes { get; set; } } public class DKoutput { /// /// 刷卡机地址 /// public string? Address { get; set; } /// /// 刷卡器数据 /// public string? ResData { get; set; } } /// /// 蜂鸣开关 /// public enum Beep { open=0, close=1, } /// /// CRC算法 /// public class CRC16 { /// /// CRC算法 /// /// /// public static byte[] ToCRC16(byte[] pucY) { ushort uiCrcValue = 0xFFFF; for ( int ucI = 0; ucI < pucY.Length; ucI++) { uiCrcValue = Convert.ToUInt16(uiCrcValue ^ pucY[ucI]); for ( int ucJ = 0; ucJ < 8; ucJ++) { if ((uiCrcValue & 0x0001)==1) { uiCrcValue =Convert.ToUInt16((uiCrcValue >> 1) ^ 0x8408); } else { uiCrcValue = Convert.ToUInt16((uiCrcValue >> 1)); } } } byte[] tem = new byte[2]; tem[0] = (byte)uiCrcValue; tem[1] = (byte)(uiCrcValue >> 8); return tem; } } }