Program.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using System.Runtime.InteropServices;
  6. namespace WindowsFormsApplication1
  7. {
  8. public class Program
  9. {
  10. /// <summary>
  11. /// 应用程序的主入口点。
  12. /// </summary>
  13. [STAThread]
  14. static void Main()
  15. {
  16. Application.EnableVisualStyles();
  17. Application.SetCompatibleTextRenderingDefault(false);
  18. Application.Run(new Form1());
  19. }
  20. //public int icdev; // 通讯设备标识符
  21. [DllImport("mwrf32.dll", EntryPoint = "rf_init", SetLastError = true,
  22. CharSet = CharSet.Auto, ExactSpelling = false,
  23. CallingConvention = CallingConvention.StdCall)]
  24. public static extern IntPtr rf_init(Int16 port, int baud);
  25. [DllImport("mwrf32.dll", EntryPoint = "rf_exit", SetLastError = true,
  26. CharSet = CharSet.Auto, ExactSpelling = false,
  27. CallingConvention = CallingConvention.StdCall)]
  28. public static extern Int16 rf_exit(IntPtr icdev);
  29. [DllImport("mwrf32.dll", EntryPoint = "rf_beep", SetLastError = true,
  30. CharSet = CharSet.Auto, ExactSpelling = false,
  31. CallingConvention = CallingConvention.StdCall)]
  32. public static extern Int16 rf_beep(IntPtr icdev, int msec);
  33. [DllImport("mwrf32.dll", EntryPoint = "rf_get_status", SetLastError = true,
  34. CharSet = CharSet.Auto, ExactSpelling = false,
  35. CallingConvention = CallingConvention.StdCall)]
  36. public static extern Int16 rf_get_status(IntPtr icdev, byte[] state);
  37. [DllImport("mwrf32.dll", EntryPoint = "rf_load_key", SetLastError = true,
  38. CharSet = CharSet.Auto, ExactSpelling = false,
  39. CallingConvention = CallingConvention.StdCall)]
  40. public static extern Int16 rf_load_key(IntPtr icdev, byte mode, byte secnr, byte[] keybuff);
  41. [DllImport("mwrf32.dll", EntryPoint = "rf_load_key_hex", SetLastError = true,
  42. CharSet = CharSet.Auto, ExactSpelling = false,
  43. CallingConvention = CallingConvention.StdCall)]
  44. public static extern Int16 rf_load_key_hex(IntPtr icdev, byte mode, byte secnr, byte[] keybuff);
  45. [DllImport("mwrf32.dll", EntryPoint = "a_hex", SetLastError = true,
  46. CharSet = CharSet.Auto, ExactSpelling = false,
  47. CallingConvention = CallingConvention.StdCall)]
  48. public static extern Int16 a_hex(byte[] asc, byte[] hex, Int16 len);
  49. [DllImport("mwrf32.dll", EntryPoint = "hex_a", SetLastError = true,
  50. CharSet = CharSet.Auto, ExactSpelling = false,
  51. CallingConvention = CallingConvention.StdCall)]
  52. public static extern Int16 hex_a(byte[] hex, byte[] asc, Int16 len);
  53. [DllImport("mwrf32.dll", EntryPoint = "rf_reset", SetLastError = true,
  54. CharSet = CharSet.Auto, ExactSpelling = false,
  55. CallingConvention = CallingConvention.StdCall)]
  56. public static extern Int16 rf_reset(IntPtr icdev, Int16 msec);
  57. [DllImport("mwrf32.dll", EntryPoint = "rf_request", SetLastError = true,
  58. CharSet = CharSet.Auto, ExactSpelling = false,
  59. CallingConvention = CallingConvention.StdCall)]
  60. public static extern Int16 rf_request(IntPtr icdev, byte mode, out UInt16 tagtype);
  61. [DllImport("mwrf32.dll", EntryPoint = "rf_anticoll", SetLastError = true,
  62. CharSet = CharSet.Auto, ExactSpelling = false,
  63. CallingConvention = CallingConvention.StdCall)]
  64. public static extern Int16 rf_anticoll(IntPtr icdev, byte bcnt, out UInt32 snr);
  65. [DllImport("mwrf32.dll", EntryPoint = "rf_select", SetLastError = true,
  66. CharSet = CharSet.Auto, ExactSpelling = false,
  67. CallingConvention = CallingConvention.StdCall)]
  68. public static extern Int16 rf_select(IntPtr icdev, UInt32 snr, out byte size);
  69. [DllImport("mwrf32.dll", EntryPoint = "rf_card", SetLastError = true,
  70. CharSet = CharSet.Auto, ExactSpelling = false,
  71. CallingConvention = CallingConvention.StdCall)]
  72. public static extern Int16 rf_card(IntPtr icdev, byte mode, byte[] snr); //这里将第三个参数设置为byte数组,以便直接返回16进制卡号
  73. //public static extern Int16 rf_card(IntPtr icdev, int mode, out UInt32 snr);
  74. [DllImport("mwrf32.dll", EntryPoint = "rf_authentication", SetLastError = true,
  75. CharSet = CharSet.Auto, ExactSpelling = false,
  76. CallingConvention = CallingConvention.StdCall)]
  77. public static extern Int16 rf_authentication(IntPtr icdev, byte mode, byte secnr);
  78. [DllImport("mwrf32.dll", EntryPoint = "rf_authentication_2", SetLastError = true,
  79. CharSet = CharSet.Auto, ExactSpelling = false,
  80. CallingConvention = CallingConvention.StdCall)]
  81. public static extern Int16 rf_authentication_2(IntPtr icdev, byte mode, byte keynr, byte blocknr);
  82. [DllImport("mwrf32.dll", EntryPoint = "rf_read", SetLastError = true,
  83. CharSet = CharSet.Auto, ExactSpelling = false,
  84. CallingConvention = CallingConvention.StdCall)]
  85. public static extern Int16 rf_read(IntPtr icdev, byte blocknr, byte[] databuff);
  86. [DllImport("mwrf32.dll", EntryPoint = "rf_read_hex", SetLastError = true,
  87. CharSet = CharSet.Auto, ExactSpelling = false,
  88. CallingConvention = CallingConvention.StdCall)]
  89. public static extern Int16 rf_read_hex(IntPtr icdev, byte blocknr, byte[] databuff);
  90. [DllImport("mwrf32.dll", EntryPoint = "rf_write_hex", SetLastError = true,
  91. CharSet = CharSet.Auto, ExactSpelling = false,
  92. CallingConvention = CallingConvention.StdCall)]
  93. public static extern Int16 rf_write_hex(IntPtr icdev, int blocknr, byte[] databuff);
  94. [DllImport("mwrf32.dll", EntryPoint = "rf_write", SetLastError = true,
  95. CharSet = CharSet.Auto, ExactSpelling = false,
  96. CallingConvention = CallingConvention.StdCall)]
  97. public static extern Int16 rf_write(IntPtr icdev, byte blocknr, byte[] databuff);
  98. [DllImport("mwrf32.dll", EntryPoint = "rf_halt", SetLastError = true,
  99. CharSet = CharSet.Auto, ExactSpelling = false,
  100. CallingConvention = CallingConvention.StdCall)]
  101. public static extern Int16 rf_halt(IntPtr icdev);
  102. [DllImport("mwrf32.dll", EntryPoint = "rf_changeb3", SetLastError = true,
  103. CharSet = CharSet.Auto, ExactSpelling = false,
  104. CallingConvention = CallingConvention.StdCall)]
  105. public static extern Int16 rf_changeb3(IntPtr icdev, byte sector, byte[] keya, byte B0, byte B1,
  106. byte B2, byte B3, byte Bk, byte[] keyb);
  107. [DllImport("mwrf32.dll", EntryPoint = "rf_pro_rst", SetLastError = true,
  108. CharSet = CharSet.Auto, ExactSpelling = false,
  109. CallingConvention = CallingConvention.StdCall)]
  110. public static extern Int16 rf_pro_rst(IntPtr icdev, byte[] _Data);
  111. [DllImport("mwrf32.dll", EntryPoint = "rf_pro_trn", SetLastError = true,
  112. CharSet = CharSet.Auto, ExactSpelling = false,
  113. CallingConvention = CallingConvention.StdCall)]
  114. public static extern Int16 rf_pro_trn(IntPtr icdev, byte[] problock, byte[] recv);
  115. [DllImport ("mwrf32.dll",EntryPoint="rf_ctl_mode",SetLastError=true,
  116. CharSet=CharSet.Auto,ExactSpelling=false,
  117. CallingConvention=CallingConvention.StdCall)]
  118. public static extern Int16 rf_ctl_mode(IntPtr icdev, byte mode); //受控方式
  119. [DllImport ("mwrf32.dll")]
  120. public static extern Int16 rf_setbright(IntPtr icdev,byte bright);
  121. [DllImport ("mwrf32.dll")]
  122. public static extern Int16 rf_disp_mode(IntPtr icdev,byte mode);
  123. [DllImport("mwrf32.dll")]
  124. public static extern Int16 rf_settime(IntPtr icdev,byte[] time);
  125. [DllImport("mwrf32.dll", EntryPoint = "rf_ctl_mode", SetLastError = true,
  126. CharSet = CharSet.Ansi, ExactSpelling = false,
  127. CallingConvention = CallingConvention.StdCall)]
  128. public static extern Int16 rf_settimehex(IntPtr icdev,string time);
  129. [DllImport("mwrf32.dll", EntryPoint = "rf_CtlBackLight", SetLastError = true,
  130. CharSet = CharSet.Auto, ExactSpelling = false,
  131. CallingConvention = CallingConvention.StdCall)]
  132. public static extern Int16 rf_CtlBackLight(IntPtr icdev, byte cOpenFlag); //控制背光
  133. [DllImport("mwrf32.dll", EntryPoint = "rf_LcdClrScrn", SetLastError = true,
  134. CharSet = CharSet.Auto, ExactSpelling = false,
  135. CallingConvention = CallingConvention.StdCall)]
  136. public static extern Int16 rf_LcdClrScrn(IntPtr icdev, byte cLine); //清LCD屏
  137. [DllImport("mwrf32.dll", EntryPoint = "rf_DispMainMenu", SetLastError = true,
  138. CharSet = CharSet.Auto, ExactSpelling = false,
  139. CallingConvention = CallingConvention.StdCall)]
  140. public static extern Int16 rf_DispMainMenu(IntPtr icdev); //显示欢迎光临
  141. [DllImport("mwrf32.dll", EntryPoint = "rf_DispLcd", SetLastError = true,
  142. CharSet = CharSet.Auto, ExactSpelling = false,
  143. CallingConvention = CallingConvention.StdCall)]
  144. public static extern Int16 rf_DispLcd(IntPtr icdev, byte line, byte type); //显示系统内置操作
  145. [DllImport("mwrf32.dll", EntryPoint = "rf_DispInfo", SetLastError = true,
  146. CharSet = CharSet.Auto, ExactSpelling = false,
  147. CallingConvention = CallingConvention.StdCall)]
  148. public static extern Int16 rf_DispInfo(IntPtr icdev, byte line, byte offset, byte[] data); //显示信息,操作前需清屏
  149. [DllImport("mwrf32.dll", EntryPoint = "rf_disp8", SetLastError = true,
  150. CharSet = CharSet.Auto, ExactSpelling = false,
  151. CallingConvention = CallingConvention.StdCall)]
  152. public static extern Int16 rf_disp8(IntPtr icdev, Int16 disp_len, byte[] disp_str); //在读写器数码管上显示数字
  153. }
  154. }