赞
踩
- 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; //调用动态库一定要加入这个引用
- //using System.Text;//一定要加入这个
-
- namespace iso15693reader
- {
- public partial class Form1 : Form
- {
- public const byte NEEDSERIAL = 0x08;//仅对指定UID号的卡操作
- public const byte NEEDHALT = 0x20;//读卡或写卡后顺便休眠该卡,休眠后,卡必须拿离开感应区,再放回感应区,才能进行第二次操作。
-
- //外部函数声明:让设备发出声响
- [DllImport("OUR_MIFARE.dll", EntryPoint = "pcdbeep", CallingConvention = CallingConvention.StdCall)]
- static extern byte pcdbeep(UInt32 xms);//xms单位为毫秒
-
- //读取设备编号,可做为软件加密狗用,也可以根据此编号在公司网站上查询保修期限
- [DllImport("OUR_MIFARE.dll", EntryPoint = "pcdgetdevicenumber", CallingConvention = CallingConvention.StdCall)]
- static extern byte pcdgetdevicenumber(byte[] devicenumber);//devicenumber用于返回编号
-
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //轻松读卡
- [DllImport("OUR_MIFARE.dll", EntryPoint = "iso15693readex", CallingConvention = CallingConvention.StdCall)]
- static extern byte iso15693readex(byte ctrlword, byte afi, byte startblock,byte blocknum,byte[] uid, byte[] revbuf);
- //参数说明
- //ctrlword:控制字,用常量NEEDSERIAL,NEEDHALT赋值,这两常量说明请看声明后的注释
- //afi:应用领域识别号,只能操作相同识别号的卡,一般卡出厂时AFI为0
- //startblock:起始块号
- //blocknum:本次操作的块数量
- //uid:卡序列号,15693卡序列号为8个字节
- //revbuf:用于返回卡块内信息,最大49个字节,其中头一个字节存放返回的字节数,紧跟着的为卡块内信息.
-
-
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- //轻松写卡
- [DllImport("OUR_MIFARE.dll", EntryPoint = "iso15693writeex", CallingConvention = CallingConvention.StdCall)]
- static extern byte iso15693writeex(byte ctrlword, byte afi, byte startblock, byte blocknum, byte[] uid, byte[] writebuf);
- //参数说明
- //ctrlword:控制字,用常量NEEDSERIAL,NEEDHALT赋值,这两常量说明请看声明后的注释
- //afi:应用领域识别号,只能操作相同识别号的卡,一般卡出厂时AFI为0
- //startblock:起始块号
- //blocknum:本次操作的块数量
- //uid:卡序列号,15693卡序列号为8个字节
- //writebuf:用于指定写入的卡块内信息,最大49个字节,其中头一个字节存放本次要写入的字节数,紧跟着的为卡块内信息.
-
- //寻一张卡
- [DllImport("OUR_MIFARE.dll", EntryPoint = "iso15693inventory", CallingConvention = CallingConvention.StdCall)]
- static extern byte iso15693inventory(byte flags, byte afi, byte masklen,byte[] maskuid, byte[] revuid);
- //参数说明
- //ctrlword:控制字,用常量NEEDSERIAL,NEEDHALT赋值,这两常量说明请看声明后的注释
- //afi:应用领域识别号,只能操作相同识别号的卡,一般卡出厂时AFI为0
- //masklen:掩码bit位数,一般置为0
- //maskuid:卡序列号掩码,为8个字节,指的是卡号和maskuid中的masklen位数值相同的卡片才能寻得到
- //revuid:返回DSFID及卡序列号,第0字节为DSFID,第1到8为卡序列号,共为8个字节
-
- public Form1()
- {
- InitializeComponent();
- }
-
- private void button1_Click(object sender, EventArgs e)
- {//轻松读卡
- byte status;//存放返回值
- byte ctrlword;
- byte afi;
- byte startblock;
- byte blocknum;
- byte[] uidbuf = new byte[8];
- byte[] revbuf = new byte[200];//卡数据缓冲
- int i;
- string str;
- //控制字指定,控制字的含义请查看本公司网站提供的动态库说明
- ctrlword = 0;
-
- afi = System.Convert.ToByte(textBox1.Text,16);//以十六进制方式转成数值
-
- startblock = System.Convert.ToByte(textBox2.Text);
-
- blocknum = System.Convert.ToByte(textBox3.Text);
-
- for (i = 0; i < 8; i++)
- {
- uidbuf[i] = Convert.ToByte(textBox4.Text.Substring(i * 2, 2),16);
- }
-
- status = iso15693readex(ctrlword, afi, startblock, blocknum, uidbuf, revbuf);
-
- switch (status)
- {
- case 0:
- str = "";
- for (i = 0; i < 8; i++)
- {
- str += uidbuf[i].ToString("X02");
- }
- textBox4.Text = str;
- str = "";
- for (i = 0; i < revbuf[0]; i++)
- {
- str += revbuf[i+1].ToString("X02");
- }
- richTextBox1.Text = str;
-
- pcdbeep(50);
- break;
- //......
- case 8:
- MessageBox.Show("请将卡放在感应区");
- break;
- default:
- MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
- break;
-
-
- }
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- pcdbeep(50);
- }
-
- private void button4_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 button3_Click(object sender, EventArgs e)
- {//轻松写卡
- byte status;//存放返回值
- byte ctrlword;
- byte afi;
- byte startblock;
- byte blocknum;
- byte[] uidbuf = new byte[8];
- byte[] writebuf = new byte[200];//卡数据缓冲
- int i;
- string str;
- //控制字指定,控制字的含义请查看本公司网站提供的动态库说明
- ctrlword = 0;
-
- afi = System.Convert.ToByte(textBox1.Text, 16);//以十六进制方式转成数值
-
- startblock = System.Convert.ToByte(textBox2.Text);
-
- blocknum = System.Convert.ToByte(textBox3.Text);
-
- for (i = 0; i < 8; i++)
- {
- uidbuf[i] = Convert.ToByte(textBox4.Text.Substring(i * 2, 2), 16);
- }
- writebuf[0] = (byte)(blocknum * 4);
- for (i = 0; i < 48; i++)
- {
- writebuf[i+1] = (byte)i;
- }
-
- status = iso15693writeex(ctrlword, afi, startblock, blocknum, uidbuf, writebuf);
-
- switch (status)
- {
- case 0:
- str = "";
- for (i = 0; i < 8; i++)
- {
- str += uidbuf[i].ToString("X02");
- }
- textBox4.Text = str;
-
- pcdbeep(50);
- break;
- //......
- case 8:
- MessageBox.Show("请将卡放在感应区");
- break;
- default:
- MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
- break;
-
-
- }
-
- }
-
- private void button5_Click(object sender, EventArgs e)
- {
- byte status;//存放返回值
- byte afi;
- byte[] maskuid = new byte[8];
- byte[] revuid = new byte[9];//卡数据缓冲
- int i;
- string str;
- //控制字指定,控制字的含义请查看本公司网站提供的动态库说明
-
- afi = System.Convert.ToByte(textBox1.Text,16);//以十六进制方式转成数值
-
- status = iso15693inventory(0x36, afi, 0, maskuid, revuid);
-
- switch (status)
- {
- case 0:
- str = "";
- for (i = 1; i < 9; i++)
- {
- str += revuid[i].ToString("X02");
- }
- textBox4.Text = str;
-
- pcdbeep(50);
- break;
- //......
- case 8:
- MessageBox.Show("请将卡放在感应区");
- break;
- default:
- MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
- break;
-
-
- }
-
- }
-
- private void Form1_Load(object sender, EventArgs e)
- {
-
- }
- }
- }
-
- /*
- '返回解释
- '#define ERR_REQUEST 8'寻卡错误
- '#define ERR_READSERIAL 9'读序列吗错误
- '#define ERR_SELECTCARD 10'选卡错误
- '#define ERR_LOADKEY 11'装载密码错误
- '#define ERR_AUTHKEY 12'密码认证错误
- '#define ERR_READ 13'读卡错误
- '#define ERR_WRITE 14'写卡错误
- '#define ERR_NONEDLL 21'没有动态库
- '#define ERR_DRIVERORDLL 22'动态库或驱动程序异常
- '#define ERR_DRIVERNULL 23'驱动程序错误或尚未安装
- '#define ERR_TIMEOUT 24'操作超时,一般是动态库没有反映
- '#define ERR_TXSIZE 25'发送字数不够
- '#define ERR_TXCRC 26'发送的CRC错
- '#define ERR_RXSIZE 27'接收的字数不够
- '#define ERR_RXCRC 28'接收的CRC错
- */
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。