Professional Documents
Culture Documents
IC卡
IC卡
IC卡
dll IC IC
1auto_init
IC
public static extern int auto_init(int port, int baud);
portCom1 0Com2 1
baud
IC
2setsc_md
icdev auto_init
mode 0
1
l
3get_status
icdev auto_init
state 0 1
4csc_4442
IC
public static extern Int16 Csc_4442(int icdev, int len,
[MarshalAs(UnmanagedType.LPArray)] byte[] p_string);
icdev auto_init
len 3
p_string
5swr_4442
IC
public static extern int swr_4442(int icdev, int offset, int len, char* w_string);
icdev auto_init
offset 0255
len
w_string
6ic_exit
icdev auto_init
7dv_beep
icdev auto_init
time 10
1 Ex13_05 Form1
2 Form1 Button
TextBox TextBox IC
3
IC IC
[StructLayout(LayoutKind.Sequential)]
public unsafe class IC
{
//
[DllImport("Mwic_32.dll", EntryPoint = "auto_init", SetLastError = true,
CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention =
CallingConvention.StdCall)]
public static extern int auto_init(int port, int baud);
//
[DllImport("Mwic_32.dll", EntryPoint = "setsc_md", SetLastError = true,
CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention =
CallingConvention.StdCall)]
public static extern int setsc_md(int icdev, int mode);
//
[DllImport("Mwic_32.dll", EntryPoint = "get_status", SetLastError = true,
CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention =
CallingConvention.StdCall)]
public static extern Int16 get_status(int icdev, Int16* state);
//
[DllImport("Mwic_32.dll", EntryPoint = "ic_exit", SetLastError = true,
CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention =
CallingConvention.StdCall)]
public static extern int ic_exit(int icdev);
//
[DllImport("Mwic_32.dll", EntryPoint = "dv_beep", SetLastError = true,
CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention =
CallingConvention.StdCall)]
TextBox IC
private void button1_Click(object sender, EventArgs e)
{
//
int icdev = IC.auto_init(0, 9600);
if (icdev < 0)
MessageBox.Show(",","
",MessageBoxButtons.OK,MessageBoxIcon.Information);
int md = IC.setsc_md(icdev, 1); //
unsafe
{
Int16 status = 0;
Int16 result = 0;
result = IC.get_status(icdev, &status);
if (result != 0)
{
MessageBox.Show("");
int d1 = IC.ic_exit(icdev); //
return;
}
if (status != 1)
{
MessageBox.Show("");
int d2 = IC.ic_exit(icdev); //
return;
}
}
unsafe
{
// 6 fffffff1 f 16 15, f
16 255
byte[] pwd = new byte[3] { 255, 255, 255 };
//byte[] pwd = new byte[3] { 0xff, 0xff, 0xff };
//char[] pass=new ch{0xff,0xff,0xff};
Int16 checkIC_pwd = IC.Csc_4442(icdev, 3, pwd);
if (checkIC_pwd < 0)
{
MessageBox.Show("");
return;
}
char str = 'a';
int write=-1;
for (int j = 0; j < textBox1.Text.Length; j++)
{
str = Convert.ToChar(textBox1.Text.Substring(j, 1));