赞
踩
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Runtime.InteropServices; //调用动态库一定要加入这个引用
-
-
- namespace idcardreader
- {
- public partial class Form1 : Form
- {
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //外部函数声明:让设备发出声响
- [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_beep", CallingConvention = CallingConvention.StdCall)]
- static extern byte idr_beep(UInt32 xms);//xms单位为毫秒
-
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //读取设备编号,可做为软件加密狗用,也可以根据此编号在公司网站上查询保修期限
- [DllImport("OUR_IDR_x64.dll", EntryPoint = "pcdgetdevicenumber", CallingConvention = CallingConvention.StdCall)]
- static extern byte pcdgetdevicenumber(byte[] devicenumber);//devicenumber用于返回编号
-
-
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //只读卡号
- [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_read", CallingConvention = CallingConvention.StdCall)]
- public static extern byte idr_read(byte[] serial);//serial返回卡号
-
-
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //只读卡号,只读一次,必须拿开卡才能再读到
- [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_read_once", CallingConvention = CallingConvention.StdCall)]
- public static extern byte idr_read_once(byte[] serial);//serial返回卡号
-
-
-
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //发送显示内容到读卡器
- //[DllImport("OUR_IDR.dll", EntryPoint = "lcddispfull", CallingConvention = CallingConvention.StdCall)]
- //static extern byte lcddispfull(string lcdstr);
- //参数:说明
-
- public Form1()
- {
- InitializeComponent();
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- byte status;//存放返回值
- byte[] myserial = new byte[5];//卡序列号
- status = idr_read(myserial);
-
- switch (status)
- {
- case 0:
- idr_beep(50);
-
- MessageBox.Show("读卡成功,卡号为" + System.Convert.ToString(myserial[1] * 256 * 256 * 256 + myserial[2] * 256 * 256 + myserial[3] * 256 + myserial[4]));
- //MessageBox.Show("操作成功,卡号已在myserial中,卡号一般为myserial[0]卡厂商标识,myserial[1]到myserial[4]为卡号,用户可以组合为各种卡号编码。");
-
- break;
- //......
- case 8:
- MessageBox.Show("请将卡放在感应区");
- break;
-
- default:
- MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
- break;
-
- }
-
- }
-
- private void button7_Click(object sender, EventArgs e)
- {//嘀一声
- idr_beep(50);
- }
-
- private void button6_Click(object sender, EventArgs e)
- {//读取设备编号,可做为软件加密狗用
- byte[] devno = new byte[4];
- if (pcdgetdevicenumber(devno) == 0)
- {
- MessageBox.Show(System.Convert.ToString(devno[0]) + "-" + System.Convert.ToString(devno[1]) + "-" + System.Convert.ToString(devno[2]) + "-" + System.Convert.ToString(devno[3]));
- //ShowMessage(IntToStr(devno[0]) + "-" + IntToStr(devno[1]) + "-" + IntToStr(devno[2]) + "-" + IntToStr(devno[3]));
- }
- }
-
-
- private void button4_Click(object sender, EventArgs e)
- {
- byte status;//存放返回值
- byte[] myserial = new byte[5];//卡序列号
- status = idr_read_once(myserial);
-
- switch (status)
- {
- case 0:
- idr_beep(50);
- MessageBox.Show("读卡成功,卡号为" + System.Convert.ToString(myserial[1] * 256 * 256 * 256 + myserial[2] * 256 * 256 + myserial[3] * 256 + myserial[4]));
- //MessageBox.Show("操作成功,卡号已在myserial中,卡号一般为myserial[0]卡厂商标识,myserial[1]到myserial[4]为卡号,用户可以组合为各种卡号编码。");
-
- break;
- //......
- case 8:
- MessageBox.Show("请将卡放在感应区");
- break;
-
- default:
- MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
- break;
-
- }
- }
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。