当前位置:   article > 正文

C#读取RFID卡号源码_使用c#代码读取读取加密狗

使用c#代码读取读取加密狗

  //读卡器介绍:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.23.16795b43onC5S2&id=600862990715https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.23.16795b43onC5S2&id=600862990715

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Runtime.InteropServices; //调用动态库一定要加入这个引用
  11. namespace idcardreader
  12. {
  13. public partial class Form1 : Form
  14. {
  15. //------------------------------------------------------------------------------------------------------------------------------------------------------
  16. //外部函数声明:让设备发出声响
  17. [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_beep", CallingConvention = CallingConvention.StdCall)]
  18. static extern byte idr_beep(UInt32 xms);//xms单位为毫秒
  19. //------------------------------------------------------------------------------------------------------------------------------------------------------
  20. //读取设备编号,可做为软件加密狗用,也可以根据此编号在公司网站上查询保修期限
  21. [DllImport("OUR_IDR_x64.dll", EntryPoint = "pcdgetdevicenumber", CallingConvention = CallingConvention.StdCall)]
  22. static extern byte pcdgetdevicenumber(byte[] devicenumber);//devicenumber用于返回编号
  23. //------------------------------------------------------------------------------------------------------------------------------------------------------
  24. //只读卡号
  25. [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_read", CallingConvention = CallingConvention.StdCall)]
  26. public static extern byte idr_read(byte[] serial);//serial返回卡号
  27. //------------------------------------------------------------------------------------------------------------------------------------------------------
  28. //只读卡号,只读一次,必须拿开卡才能再读到
  29. [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_read_once", CallingConvention = CallingConvention.StdCall)]
  30. public static extern byte idr_read_once(byte[] serial);//serial返回卡号
  31. //------------------------------------------------------------------------------------------------------------------------------------------------------
  32. //发送显示内容到读卡器
  33. //[DllImport("OUR_IDR.dll", EntryPoint = "lcddispfull", CallingConvention = CallingConvention.StdCall)]
  34. //static extern byte lcddispfull(string lcdstr);
  35. //参数:说明
  36. public Form1()
  37. {
  38. InitializeComponent();
  39. }
  40. private void button2_Click(object sender, EventArgs e)
  41. {
  42. byte status;//存放返回值
  43. byte[] myserial = new byte[5];//卡序列号
  44. status = idr_read(myserial);
  45. switch (status)
  46. {
  47. case 0:
  48. idr_beep(50);
  49. MessageBox.Show("读卡成功,卡号为" + System.Convert.ToString(myserial[1] * 256 * 256 * 256 + myserial[2] * 256 * 256 + myserial[3] * 256 + myserial[4]));
  50. //MessageBox.Show("操作成功,卡号已在myserial中,卡号一般为myserial[0]卡厂商标识,myserial[1]到myserial[4]为卡号,用户可以组合为各种卡号编码。");
  51. break;
  52. //......
  53. case 8:
  54. MessageBox.Show("请将卡放在感应区");
  55. break;
  56. default:
  57. MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
  58. break;
  59. }
  60. }
  61. private void button7_Click(object sender, EventArgs e)
  62. {//嘀一声
  63. idr_beep(50);
  64. }
  65. private void button6_Click(object sender, EventArgs e)
  66. {//读取设备编号,可做为软件加密狗用
  67. byte[] devno = new byte[4];
  68. if (pcdgetdevicenumber(devno) == 0)
  69. {
  70. MessageBox.Show(System.Convert.ToString(devno[0]) + "-" + System.Convert.ToString(devno[1]) + "-" + System.Convert.ToString(devno[2]) + "-" + System.Convert.ToString(devno[3]));
  71. //ShowMessage(IntToStr(devno[0]) + "-" + IntToStr(devno[1]) + "-" + IntToStr(devno[2]) + "-" + IntToStr(devno[3]));
  72. }
  73. }
  74. private void button4_Click(object sender, EventArgs e)
  75. {
  76. byte status;//存放返回值
  77. byte[] myserial = new byte[5];//卡序列号
  78. status = idr_read_once(myserial);
  79. switch (status)
  80. {
  81. case 0:
  82. idr_beep(50);
  83. MessageBox.Show("读卡成功,卡号为" + System.Convert.ToString(myserial[1] * 256 * 256 * 256 + myserial[2] * 256 * 256 + myserial[3] * 256 + myserial[4]));
  84. //MessageBox.Show("操作成功,卡号已在myserial中,卡号一般为myserial[0]卡厂商标识,myserial[1]到myserial[4]为卡号,用户可以组合为各种卡号编码。");
  85. break;
  86. //......
  87. case 8:
  88. MessageBox.Show("请将卡放在感应区");
  89. break;
  90. default:
  91. MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
  92. break;
  93. }
  94. }
  95. }
  96. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/985966?site
推荐阅读
相关标签
  

闽ICP备14008679号