概述
//读卡器介绍: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
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;
}
}
}
}
最后
以上就是忧郁抽屉为你收集整理的C#读取RFID卡号源码的全部内容,希望文章能够帮你解决C#读取RFID卡号源码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复