You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 line
2.1 KiB

  1. using System.Runtime.InteropServices;
  2. using System.Text;
  3. namespace UHFHelper
  4. {
  5. public static class UHFHelper
  6. {
  7. /// <summary>
  8. /// 解析数据
  9. /// </summary>
  10. /// <param name="data"></param>
  11. /// <returns></returns>
  12. public static string ByteArrayToHexString(this byte[] data)
  13. {
  14. StringBuilder sb = new(data.Length * 3);
  15. foreach (byte b in data)
  16. sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));
  17. return sb.ToString().ToUpper();
  18. }
  19. }
  20. public class Resultoutput
  21. {
  22. public bool Res { get; set; }
  23. public string? ResMes { get; set; }
  24. }
  25. public class DKoutput
  26. {
  27. /// <summary>
  28. /// 刷卡机地址
  29. /// </summary>
  30. public string? Address { get; set; }
  31. /// <summary>
  32. /// 刷卡器数据
  33. /// </summary>
  34. public string? ResData { get; set; }
  35. }
  36. /// <summary>
  37. /// 蜂鸣开关
  38. /// </summary>
  39. public enum Beep
  40. {
  41. open=0,
  42. close=1,
  43. }
  44. /// <summary>
  45. /// CRC算法
  46. /// </summary>
  47. public class CRC16
  48. {
  49. /// <summary>
  50. /// CRC算法
  51. /// </summary>
  52. /// <param name="pucY"></param>
  53. /// <returns></returns>
  54. public static byte[] ToCRC16(byte[] pucY)
  55. {
  56. ushort uiCrcValue = 0xFFFF;
  57. for ( int ucI = 0; ucI < pucY.Length; ucI++)
  58. {
  59. uiCrcValue = Convert.ToUInt16(uiCrcValue ^ pucY[ucI]);
  60. for ( int ucJ = 0; ucJ < 8; ucJ++)
  61. {
  62. if ((uiCrcValue & 0x0001)==1)
  63. {
  64. uiCrcValue =Convert.ToUInt16((uiCrcValue >> 1) ^ 0x8408);
  65. }
  66. else
  67. {
  68. uiCrcValue = Convert.ToUInt16((uiCrcValue >> 1));
  69. }
  70. }
  71. }
  72. byte[] tem = new byte[2];
  73. tem[0] = (byte)uiCrcValue;
  74. tem[1] = (byte)(uiCrcValue >> 8);
  75. return tem;
  76. }
  77. }
  78. }