dcc.cs
6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using NHTSS.ClientApp.RWIC.MDI;
using System.Text;
namespace NHTSS.ClientApp.RWIC
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class FormRWIC : System.Windows.Forms.Form
{
#region 对USB接口的使用(PHILIPH卡)
[DllImport("dcrf32.dll")]
public static extern int dc_init(Int16 port,long baud); //初试化
[DllImport("dcrf32.dll")]
public static extern short dc_exit(int icdev);
[DllImport("dcrf32.dll")]
public static extern short dc_reset(int icdev,uint sec);
[DllImport("dcrf32.dll")]
public static extern short dc_config_card(int icdev, byte cardtype);
[DllImport("dcrf32.dll")]
public static extern short dc_request(int icdev,char _Mode,ref uint TagType);
[DllImport("dcrf32.dll")]
public static extern short dc_card(int icdev,char _Mode,ref ulong Snr);
[DllImport("dcrf32.dll")]
public static extern short dc_halt(int icdev);
[DllImport("dcrf32.dll")]
public static extern short dc_anticoll(int icdev,char _Bcnt,ref ulong IcCardNo);
[DllImport("dcrf32.dll")]
public static extern short dc_beep(int icdev,uint _Msec);
[DllImport("dcrf32.dll")]
public static extern short dc_authentication(int icdev,int _Mode,int _SecNr);
[DllImport("dcrf32.dll")]
public static extern short dc_load_key(int icdev, int mode,int secnr,[In] byte[] nkey ); //密码装载到读写模块中
[DllImport("dcrf32.dll")]
public static extern short dc_load_key_hex(int icdev, int mode,int secnr, string nkey ); //密码装载到读写模块中
[DllImport("dcrf32.dll")]
public static extern short dc_write ( int icdev, int adr, [In] byte[] sdata); //向卡中写入数据
[DllImport("dcrf32.dll")]
public static extern short dc_write ( int icdev, int adr, [In] string sdata); //向卡中写入数据
[DllImport("dcrf32.dll")]
public static extern short dc_write_hex ( int icdev, int adr,[In] string sdata); //向卡中写入数据(转换为16进制)
[DllImport("dcrf32.dll")]
public static extern short dc_read ( int icdev, int adr,[Out] byte[] sdata );
[DllImport("dcrf32.dll")]
public static extern short dc_read ( int icdev, int adr,[MarshalAs(UnmanagedType.LPStr)] StringBuilder sdata ); //从卡中读数据
[DllImport("dcrf32.dll")]
public static extern short dc_read_hex ( int icdev, int adr,[MarshalAs(UnmanagedType.LPStr)] StringBuilder sdata ); //从卡中读数据(转换为16进制)
[DllImport("dcrf32.dll")]
public static extern int a_hex (string oldValue,ref string newValue,Int16 len); //普通字符转换成十六进制字符
[DllImport("dcrf32.dll")]
public static extern void hex_a (ref string oldValue,ref string newValue,int len); //十六进制字符转换成普通字符
#endregion
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mItemIcManager;
private System.Windows.Forms.MenuItem mItemExit;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public FormRWIC()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mItemIcManager = new System.Windows.Forms.MenuItem();
this.mItemExit = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mItemIcManager,
this.mItemExit});
//
// mItemIcManager
//
this.mItemIcManager.Index = 0;
this.mItemIcManager.Text = "IC卡管理(&M)";
this.mItemIcManager.Click += new System.EventHandler(this.mItemIcManager_Click);
//
// mItemExit
//
this.mItemExit.Index = 1;
this.mItemExit.Text = "退出(&E)";
this.mItemExit.Click += new System.EventHandler(this.mItemExit_Click);
//
// FormRWIC
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(792, 566);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "FormRWIC";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "IC卡读写管理";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.FormRWIC_Load);
this.Closed += new System.EventHandler(this.FormRWIC_Closed);
}
#endregion
private int _icdev = -1;
#region IC卡函数和属性(PHILIPS卡)
public int IcDev
{
get { return _icdev; }
set { _icdev = value; }
}
public void InitIC()
{
//初始化串口1
if (_icdev < 0)
{
_icdev = dc_init(0,115200);
}
if(_icdev<=0)
{
//MessageBox.Show("Init Com Error!"+_icdev.ToString());
}
else
{
string a = "ffffffffffff";
//MessageBox.Show("Init Com OK!");
//int s =dc_load_key_hex(_icdev,0,0,a);
//MessageBox.Show(s.ToString());
}
}
//关闭串口
public void ExitIC()
{
dc_exit((Int16)_icdev);
}
//读卡
public string ReadIc()
{
uint st=4;
ulong icCardNo=0;
char str=(char )0;
dc_card((Int16)_icdev,str,ref icCardNo);
return icCardNo.ToString();
}
//器蜂鸣
public void Beep()
{
dc_beep((Int16)_icdev,50);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormRWIC());
}
private void FormRWIC_Closed(object sender, System.EventArgs e)
{
//结束串口
ExitIC();
}
private void FormRWIC_Load(object sender, System.EventArgs e)
{
//初试化IC卡
InitIC();
mItemIcManager_Click(null, null);
}
private void mItemIcManager_Click(object sender, System.EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
FormIcManager IcManager = new FormIcManager();
IcManager.MdiParent = this;
IcManager.Show();
IcManager.Activate();
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void mItemExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}