本说明使用设备的淘宝链接:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.11.1386789eDRQjgF&id=615391857885https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.11.1386789eDRQjgF&id=615391857885

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;  //call dll must declare
using System.Text;//Be sure to join thisnamespace WindowsFormsApplication1
{public partial class Form1 : Form{//Constants definedpublic const byte BLOCK0_EN = 0x01;//Operating 0 blockspublic const byte BLOCK1_EN = 0x02;//Operating 1 blockspublic const byte BLOCK2_EN = 0x04;//Operating 2 blockspublic const byte NEEDSERIAL = 0x08;//Only the specified serial number card operationpublic const byte EXTERNKEY = 0x10;public const byte NEEDHALT = 0x20;//Read or write CARDS after dormancy card, by the way, after dormancy, leave induction card must take, return to active area, to carry out the second operation。//-------------------------------------------------------------------------------------------------------------------------//External function declaration: make sound equipment[DllImport("OUR_MIFARE.dll", EntryPoint = "pcdbeep", CallingConvention = CallingConvention.StdCall)]static extern byte pcdbeep(UInt32 xms);//xms  milliseconds //-------------------------------------------------------------------------------------------------------------------------//Read the device number, can be used as a software encryption dog, can also according to the number on the company website query warranty period[DllImport("OUR_MIFARE.dll", EntryPoint = "pcdgetdevicenumber", CallingConvention = CallingConvention.StdCall)]static extern byte pcdgetdevicenumber(byte[] devicenumber);//devicenumber//-------------------------------------------------------------------------------------------------------------------------//Read card Serial Number only [DllImport("OUR_MIFARE.dll", EntryPoint = "piccrequest_ul", CallingConvention = CallingConvention.StdCall)]public static extern byte piccrequest_ul(byte[] serial);// Serial Number //-------------------------------------------------------------------------------------------------------------------------//Read card 4 pages data[DllImport("OUR_MIFARE.dll", EntryPoint = "piccread_ul", CallingConvention = CallingConvention.StdCall)]public static extern byte piccread_ul(byte blockadd, byte[] piccdata);// Serial Number //-------------------------------------------------------------------------------------------------------------------------//Write 1 Page[DllImport("OUR_MIFARE.dll", EntryPoint = "piccwrite_ul", CallingConvention = CallingConvention.StdCall)]public static extern byte piccwrite_ul(byte blockadd, byte[] piccdata);//-------------------------------------------------------------------------------------------------------------------------//认证密码[DllImport("OUR_MIFARE.dll", EntryPoint = "piccauthkey_ntag", CallingConvention = CallingConvention.StdCall)]public static extern byte piccauthkey_ntag(byte[] picckey, byte[] piccntagpack);//-------------------------------------------------------------------------------------------------------------------------//读取卡的版本号及型号[DllImport("OUR_MIFARE.dll", EntryPoint = "piccgetversion_ntag", CallingConvention = CallingConvention.StdCall)]static extern byte piccgetversion_ntag(byte[] mypiccversiondata);//devicenumber//-------------------------------------------------------------------------------------------------------------------------//读取卡的签字信息[DllImport("OUR_MIFARE.dll", EntryPoint = "piccreadsig_ntag", CallingConvention = CallingConvention.StdCall)]static extern byte piccreadsig_ntag(byte[] piccsigdata);//devicenumber//-------------------------------------------------------------------------------------------------------------------------//读取卡操作的单向计数器(卡操作流水号)[DllImport("OUR_MIFARE.dll", EntryPoint = "piccreadcnt_ntag", CallingConvention = CallingConvention.StdCall)]static extern byte piccreadcnt_ntag(byte[] mypicccntdata);//devicenumber//-------------------------------------------------------------------------------------------------------------------------//锁定页数据[DllImport("OUR_MIFARE.dll", EntryPoint = "picclock_ntag", CallingConvention = CallingConvention.StdCall)]public static extern byte picclock_ntag(byte locktype, byte[] mypicclockdata);//-------------------------------------------------------------------------------------------------------------------------//初始化卡[DllImport("OUR_MIFARE.dll", EntryPoint = "piccinit_ntag", CallingConvention = CallingConvention.StdCall)]public static extern byte piccinit_ntag(byte ctrlword, byte[] serial, byte[] picckey,  byte[] piccdata);//-------------------------------------------------------------------------------------------------------------------------//Easy to read[DllImport("OUR_MIFARE.dll", EntryPoint = "piccreadex_ntag", CallingConvention = CallingConvention.StdCall)]public static extern byte piccreadex_ntag(byte ctrlword, byte[] serial, byte[] picckey, byte blockadd, byte blocksize, byte[] piccdata);//parameters://ctrlword://serial:Card serial number array, is used to specify or return card serial number//picckey:password//blockadd:Specifies read card code//piccdata:Used to return to the card the 0 to 2 pieces of data, a total of 48 bytes.//-------------------------------------------------------------------------------------------------------------------------//Easy to write[DllImport("OUR_MIFARE.dll", EntryPoint = "piccwriteex_ntag", CallingConvention = CallingConvention.StdCall)]static extern byte piccwriteex_ntag(byte ctrlword, byte[] serial, byte[] picckey, byte blockadd, byte blocksize, byte[] piccdata);//parameters://ctrlword://serial:Card serial number array, is used to specify or return card serial number//blockadd:Specifies read card code//piccdata:Used to return to the card the 0 to 2 pieces of data, a total of 48 bytes.//-------------------------------------------------------------------------------------------------------------------------//Send Display Information to Drive[DllImport("OUR_MIFARE.dll", EntryPoint = "lcddispfull", CallingConvention = CallingConvention.StdCall)]static extern byte lcddispfull(string lcdstr);//parameters://lcdstr:According to the contentpublic Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e)//easy to read ICcard{byte status;                      //Store the return valuebyte myctrlword;byte[] mypiccserial = new byte[7];//card serial         byte[] mypickey = new byte[4];byte blockadd;                    //Read Begin Page addressbyte blocksize;byte[] mypicdata = new byte[48];  //DataBuffstring CardData;string CardKey;int i;if (rwps.Value > 12 || rwps.Value<1){DialogResult dr = MessageBox.Show("一次最多只能读12页!", "Note", MessageBoxButtons.OK, MessageBoxIcon.Warning );rwps.Select();return;}if (checkBox3.Checked){if ((textBox8.Text.Trim()).Length != 8){DialogResult dr = MessageBox.Show("卡密码不足8位,请输入正确的认证密码。", "Note", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);textBox8.Select();return;}CardKey = textBox8.Text.Trim();for (i = 0; i < 4; i++){mypickey[i] = Convert.ToByte(Convert.ToInt32(CardKey.Substring(i * 2, 2), 16)); ;}myctrlword = 0x10;}else { myctrlword = 0x00; }blockadd = (byte)rwbegp.Value;  //读起始页地址blocksize = (byte)rwps.Value;   //读页数//----------------------------------------------------------------------------------------byte comedc = 0x1b;string ComOrd = "0F1B";comedc = (byte)(comedc ^ myctrlword); //控制字ComOrd = ComOrd + myctrlword.ToString("X2");for (i = 0; i < 7; i++)           //卡序号 {comedc = (byte)(comedc ^ mypiccserial[i]);ComOrd = ComOrd + mypiccserial[i].ToString("X2");}for (i = 0; i < 4; i++)           //认证密码 {comedc = (byte)(comedc ^ mypickey[i]);ComOrd = ComOrd + mypickey[i].ToString("X2");}comedc = (byte)(comedc ^ blockadd); //页地址ComOrd = ComOrd + blockadd.ToString("X2");comedc = (byte)(comedc ^ blocksize); //页数ComOrd = ComOrd + blocksize.ToString("X2");ComOrd = ComOrd + comedc.ToString("X2"); //校验码richTextBox2.Text = ComOrd;//----------------------------------------------------------------------------------------status = piccreadex_ntag(myctrlword, mypiccserial, mypickey, blockadd, blocksize, mypicdata);switch (status){case 0:CardData = "";for ( i = 0; i < 7; i++){CardData = CardData + mypiccserial[i].ToString("X2");}textBox7.Text = CardData;CardData = "";for ( i = 0; i < blocksize*4; i++){CardData = CardData + mypicdata[i].ToString("X2");}richTextBox1.Text = CardData;pcdbeep(38);MessageBox.Show("Operation is successful!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);break;//......case 8:richTextBox1.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 12:richTextBox1.Text = "";MessageBox.Show("密码错误!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 13:richTextBox1.Text = "读卡失败,可能需要验证密码";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:richTextBox1.Text = "";MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:richTextBox1.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}//Return to explain/*REQUEST 8//Not Find card READSERIAL 9//Read a sequence errorSELECTCARD 10//Selected card errorLOADKEY 11//load key errirAUTHKEY 12//authentication Key errorREAD 13//Read card ErrorWRITE 14//Write card ErrorNONEDLL 21//not dllDRIVERORDLL 22//dll files errorDRIVERNULL 23//not install drivers or the drivers is  errTIMEOUT 24//Timeout TXSIZE 25//Send word is not enoughTXCRC 26//send CRC errorRXSIZE 27// receive information is not enoughRXCRC 28//receive CRC is error*/}private void button2_Click(object sender, EventArgs e)//easy to write card{byte status;                      //Store the return valuebyte myctrlword;byte[] mypiccserial = new byte[7];//card serial      byte[] mypickey = new byte[4];byte blockadd;                    //Read Begin Page addressbyte blocksize;byte[] mypicdata = new byte[48];  //DataBuffstring CardData;int i;if (rwps.Value > 11 || rwps.Value < 1){DialogResult dr = MessageBox.Show("一次最多只能写11页!", "Note", MessageBoxButtons.OK, MessageBoxIcon.Warning);rwps.Select();return;}if (checkBox3.Checked){if ((textBox8.Text.Trim()).Length != 8){DialogResult dr = MessageBox.Show("卡密码不足8位,请输入正确的认证密码。", "Note", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);textBox8.Select();return;}string  CardKey = textBox8.Text.Trim();for ( i = 0; i < 4; i++){mypickey[i] = Convert.ToByte(Convert.ToInt32(CardKey.Substring(i * 2, 2), 16)); ;}myctrlword = 0x10;}else { myctrlword = 0x00; }blockadd = (byte)rwbegp.Value;  //读起始页地址blocksize = (byte)rwps.Value;   //读页数if ((richTextBox1.Text.Trim()).Length < blocksize*4*2){DialogResult dr = MessageBox.Show("Write data is not enough, whether to fill 0 in the rear?", "Note", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (dr != DialogResult.OK){return;}else{CardData = (richTextBox1.Text.Trim() + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").Substring(0, blocksize * 4 * 2);}}else{CardData = richTextBox1.Text.Trim().Substring(0, blocksize * 4 * 2);}richTextBox1.Text = CardData;for ( i = 0; i < blocksize * 4; i++){mypicdata[i] = Convert.ToByte(Convert.ToInt32(CardData.Substring(i * 2, 2), 16)); ;}//----------------------------------------------------------------------------------------byte comedc = 0x1c;string ComOrd = "3B1C";comedc = (byte)(comedc ^ myctrlword); //控制字ComOrd = ComOrd + myctrlword.ToString("X2");for (i = 0; i < 7; i++)           //卡序号 {comedc = (byte)(comedc ^ mypiccserial[i]);ComOrd = ComOrd + mypiccserial[i].ToString("X2");}for (i = 0; i < 4; i++)           //认证密码 {comedc = (byte)(comedc ^ mypickey[i]);ComOrd = ComOrd + mypickey[i].ToString("X2");}comedc = (byte)(comedc ^ blockadd); //页地址ComOrd = ComOrd + blockadd.ToString("X2");comedc = (byte)(comedc ^ blocksize); //页数ComOrd = ComOrd + blocksize.ToString("X2");for (i = 0; i < 44; i++)           //数据 {comedc = (byte)(comedc ^ mypicdata[i]);ComOrd = ComOrd + mypicdata[i].ToString("X2");}ComOrd = ComOrd + comedc.ToString("X2"); //校验码richTextBox2.Text = ComOrd;//----------------------------------------------------------------------------------------status = piccwriteex_ntag(myctrlword, mypiccserial, mypickey, blockadd, blocksize, mypicdata);switch (status){case 0:CardData = "";for (i = 0; i < 7; i++){CardData = CardData + mypiccserial[i].ToString("X2");}textBox7.Text = CardData;pcdbeep(38);MessageBox.Show("Operation is successful!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);break;//......case 8:textBox7.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 12:textBox7.Text = "";MessageBox.Show("密码错误!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 14:textBox7.Text = "";MessageBox.Show("写卡失败,可能需要验证密码 或 页已经锁死!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:textBox7.Text = "";MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox7.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}//Return to explain/*REQUEST 8//Not Find card READSERIAL 9//Read a sequence errorSELECTCARD 10//Selected card errorLOADKEY 11//load key errirAUTHKEY 12//authentication Key errorREAD 13//Read card ErrorWRITE 14//Write card ErrorNONEDLL 21//not dllDRIVERORDLL 22//dll files errorDRIVERNULL 23//not install drivers or the drivers is  errTIMEOUT 24//Timeout TXSIZE 25//Send word is not enoughTXCRC 26//send CRC errorRXSIZE 27// receive information is not enoughRXCRC 28//receive CRC is error*/}private void button4_Click(object sender, EventArgs e){pcdbeep(50);}private void button3_Click(object sender, EventArgs e){//Return to explain/*REQUEST 8//Not Find card READSERIAL 9//Read a sequence errorSELECTCARD 10//Selected card errorLOADKEY 11//load key errirAUTHKEY 12//authentication Key errorREAD 13//Read card ErrorWRITE 14//Write card ErrorNONEDLL 21//not dllDRIVERORDLL 22//dll files errorDRIVERNULL 23//not install drivers or the drivers is  errTIMEOUT 24//Timeout TXSIZE 25//Send word is not enoughTXCRC 26//send CRC errorRXSIZE 27// receive information is not enoughRXCRC 28//receive CRC is error*/}private void button8_Click(object sender, EventArgs e)//Read the device number, can be used as a software encryption dog, can also according to the number on the company website query warranty period{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 button9_Click(object sender, EventArgs e){}private void button7_Click(object sender, EventArgs e){}private void button11_Click(object sender, EventArgs e){byte status;//Store the return valuebyte[] mypiccserial = new byte[7];//card serial            string CardSN;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardSN = "";for (int i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox3.Text = CardSN;pcdbeep(38);MessageBox.Show("Operation is successful!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk );break;//......case 8:textBox3.Text ="";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = ""; MessageBox.Show("Error Code:" + status,"warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void button10_Click(object sender, EventArgs e){}private void button5_Click(object sender, EventArgs e){}private void button6_Click(object sender, EventArgs e){}private void Form1_Load(object sender, EventArgs e){comboBox1.SelectedIndex = 1;}private void button7_Click_1(object sender, EventArgs e){byte status;                      //Store the return valuebyte[] mypiccserial = new byte[7];//card serial         byte blockadd;                    //Read Begin Page addressbyte[] mypicdata = new byte[16];  //DataBuffstring CardData;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardData = "";for (int i = 0; i < 7; i++){CardData = CardData + mypiccserial[i].ToString("X2");}textBox3.Text = CardData;blockadd = (byte)rwblockadd.Value;status = piccread_ul(blockadd, mypicdata);if (status==0){CardData = "";for (int i = 0; i < 16; i++){CardData = CardData + mypicdata[i].ToString("X2");}textBox4.Text = CardData;pcdbeep(38);MessageBox.Show("Operation is successful!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void button10_Click_1(object sender, EventArgs e){byte status;                      //Store the return valuebyte[] mypiccserial = new byte[7];//card serial         byte blockadd;                    //Read Begin Page addressbyte[] mypicdata = new byte[4];  //DataBuffstring CardIdH;string CardData;if((textBox5.Text.Trim()).Length <8  ){DialogResult dr = MessageBox.Show("Write data is not enough, whether to fill 0 in the rear?", "Note", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (dr != DialogResult.OK){return;}else{CardData = (textBox5.Text.Trim() + "00000000").Substring(0, 8);}}else{CardData = textBox5.Text.Trim().Substring (0,8);}textBox5.Text = CardData;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardIdH = "";for (int i = 0; i < 7; i++){CardIdH = CardIdH + mypiccserial[i].ToString("X2");}textBox3.Text = CardIdH;blockadd = (byte)rwblockadd.Value;for (int i = 0; i < 4; i++){mypicdata[i] = Convert.ToByte(Convert.ToInt32(CardData.Substring(i*2, 2), 16)); ;}status = piccwrite_ul(blockadd, mypicdata);if (status == 0){                        pcdbeep(38);MessageBox.Show("Operation is successful!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{if (status == 14){ MessageBox.Show("Error Code:" + status + ",写卡失败,可能需要密码 或 页已被锁死!", "note", MessageBoxButtons.OK, MessageBoxIcon.Warning); }else{ MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning); }}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void textBox5_TextChanged(object sender, EventArgs e){}private void textBox5_KeyPress(object sender, KeyPressEventArgs e)  {if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}private void richTextBox1_TextChanged(object sender, EventArgs e){}private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}private void button3_Click_1(object sender, EventArgs e){byte status;                      //Store the return valuebyte[] mypiccserial = new byte[7];//card serial         byte blockadd;                    //Read Begin Page addressbyte[] mypickey = new byte[4];  //DataBuffbyte[] mypiccntagpack = new byte[2];//认证后返回的确认码string CardIdH;string CardKey;if ((textBox1.Text.Trim()).Length != 8){DialogResult dr = MessageBox.Show("卡密码不足8位,请输入正确的认证密码。", "Note", MessageBoxButtons.OK , MessageBoxIcon.Asterisk );return;}CardKey = textBox1.Text.Trim();status = piccrequest_ul(mypiccserial);switch (status){case 0:CardIdH = "";for (int i = 0; i < 7; i++){CardIdH = CardIdH + mypiccserial[i].ToString("X2");}textBox3.Text = CardIdH;for (int i = 0; i < 4; i++){mypickey[i] = Convert.ToByte(Convert.ToInt32(CardKey.Substring(i * 2, 2), 16)); ;}status = piccauthkey_ntag(mypickey, mypiccntagpack);if (status == 0){pcdbeep(38);MessageBox.Show("卡密码认证成功!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{if (status == 12){MessageBox.Show("Error Code:" + status, "卡密码认证失败!", MessageBoxButtons.OK, MessageBoxIcon.Warning);}else{MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void textBox1_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}private void button5_Click_1(object sender, EventArgs e){byte status;//Store the return valuebyte[] mypiccserial = new byte[7];//card serial            byte[] mypiccversiondata = new byte[8];string CardSN;int i;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardSN = "";for ( i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox3.Text = CardSN;status = piccgetversion_ntag(mypiccversiondata);if (status==0){pcdbeep(38);CardSN = "";for (i=0;i<8;i++){CardSN = CardSN + mypiccversiondata[i].ToString("X2");}MessageBox.Show("卡版本信息:" + CardSN, "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{MessageBox.Show("Error Code:" + status + ",读卡版本信息失败!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}                break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void button6_Click_1(object sender, EventArgs e){byte status;//Store the return valuebyte[] mypiccserial = new byte[7];//card serial            byte[] piccsigdata = new byte[32];string CardSN;int i;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardSN = "";for (i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox3.Text = CardSN;status = piccreadsig_ntag(piccsigdata);if (status == 0){pcdbeep(38);CardSN = "";for (i = 0; i < 32; i++){CardSN = CardSN + piccsigdata[i].ToString("X2");}MessageBox.Show("卡签字信息:" + CardSN, "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{MessageBox.Show("Error Code:" + status + ",读卡的签字信息失败!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void button9_Click_1(object sender, EventArgs e){byte status;//Store the return valuebyte[] mypiccserial = new byte[7];//card serial            byte[] mypicccntdata = new byte[3];string CardSN;int i;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardSN = "";for (i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox3.Text = CardSN;status = piccreadcnt_ntag(mypicccntdata);if (status == 0){pcdbeep(38);CardSN = "";for (i = 0; i < 3; i++){CardSN = CardSN + mypicccntdata[i].ToString("X2");}MessageBox.Show("卡操作的单向计数器:" + CardSN, "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{MessageBox.Show("Error Code:" + status + ",可能是计数器功能尚未启用或卡本身不支持计数功能!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void button12_Click(object sender, EventArgs e){byte status;//Store the return valuebyte[] mypiccserial = new byte[7];//card serial            byte[] mypicclockdata = new byte[4];string CardSN;int i;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardSN = "";for (i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox3.Text = CardSN;if (MessageBox.Show("确定要将3`15页数据锁死?", "Confirm Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){mypicclockdata[0] = 0x00;mypicclockdata[1] = 0x00;mypicclockdata[2] = 0xF9;mypicclockdata[3] = 0x00;status = picclock_ntag(0, mypicclockdata);if (status == 0){                           MessageBox.Show("0~15页锁定位写入成功!" , "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{MessageBox.Show("Error Code:" + status + ",写卡失败!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void button13_Click(object sender, EventArgs e){byte status;//Store the return valuebyte[] mypiccserial = new byte[7];//card serial            byte[] mypicclockdata = new byte[4];string CardSN;int i;status = piccrequest_ul(mypiccserial);switch (status){case 0:CardSN = "";for (i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox3.Text = CardSN;if (MessageBox.Show("确定要将3`15页数据锁死?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK){mypicclockdata[0] = 0x01;mypicclockdata[1] = 0x01;mypicclockdata[2] = 0x00;mypicclockdata[3] = 0x00;status = picclock_ntag(1, mypicclockdata);if (status == 0){MessageBox.Show("16之后的页锁定位写入成功!", "note:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);}else{MessageBox.Show("Error Code:" + status + ",写卡失败!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);}}break;//......case 8:textBox3.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox3.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void checkBox1_CheckedChanged(object sender, EventArgs e){}private void tabPage2_Click(object sender, EventArgs e){}private void label2_Click(object sender, EventArgs e){}private void button14_Click(object sender, EventArgs e){byte[] mypiccserial = new byte[7];//card serial            int i;byte status;string CardKey;byte[] mypickey = new byte[4];byte myctrlword;byte comedc;byte[] mypiccdata =new byte[16];string ComOrd;if (checkBox1.Checked) {if ((textBox2.Text.Trim()).Length != 8){DialogResult dr = MessageBox.Show("卡密码不足8位,请输入正确的认证密码。", "Note", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);textBox2.Select();return;}CardKey = textBox2.Text.Trim();for (i = 0; i < 4; i++){mypickey[i] = Convert.ToByte(Convert.ToInt32(CardKey.Substring(i * 2, 2), 16)); ;}myctrlword = 0x10;}else {myctrlword = 0x00;}if (comboBox1.SelectedIndex ==0)  //开启卡密码保护功能{if ((textBox6.Text.Trim()).Length != 8){DialogResult dr = MessageBox.Show("卡密码不足8位,请输入正确的认证密码。", "Note", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);textBox6.Select();return;}CardKey = textBox6.Text.Trim();for (i = 0; i < 4; i++){mypiccdata[i+8] = Convert.ToByte(Convert.ToInt32(CardKey.Substring(i * 2, 2), 16)); ;}mypiccdata[12] = 0x16;mypiccdata[13] = 0x16;mypiccdata[14] = 0x00;mypiccdata[15] = 0x00;myctrlword =(byte)(myctrlword + 0x04);  //更新控制字mypiccdata[0] = 0x00;mypiccdata[1] = 0x00;mypiccdata[2] = 0x00;mypiccdata[3] =(byte) beginpage.Value ;  //密码保护起始页myctrlword = (byte)(myctrlword + 0x01);  //更新控制字mypiccdata[4] = (byte)(authno.Value % 8);  //认证次数if (checkBox2.Checked)                    //开启读密码保护{mypiccdata[4] =(byte)(mypiccdata[4] + 0x80);}mypiccdata[5] = 0x00;    //启用计数器mypiccdata[6] = 0x00;mypiccdata[7] = 0x00;myctrlword = (byte)(myctrlword + 0x02);  //更新控制字}else  //取消卡密码保护功能{mypiccdata[0] = 0x00;mypiccdata[1] = 0x00;mypiccdata[2] = 0x00;mypiccdata[3] = 0xff;myctrlword = (byte)(myctrlword + 0x01);  //更新控制字mypiccdata[4] = 0x00;mypiccdata[5] = 0x00;mypiccdata[6] = 0x00;mypiccdata[7] = 0x00;myctrlword = (byte)(myctrlword + 0x02);  //更新控制字}//-------------------------------------------------------------------comedc = 0x16;ComOrd = "1D16";comedc=(byte)(comedc^myctrlword); //控制字ComOrd = ComOrd + myctrlword.ToString("X2");for (i = 0; i < 7; i++)           //卡序号 {comedc =(byte)(comedc ^ mypiccserial[i]);ComOrd = ComOrd + mypiccserial[i].ToString("X2");}for (i = 0; i < 4; i++)           //认证密码 {comedc = (byte)(comedc ^ mypickey[i]);ComOrd = ComOrd + mypickey[i].ToString("X2");}for (i = 0; i < 16; i++)           //数据{comedc = (byte)(comedc ^ mypiccdata[i]);ComOrd = ComOrd + mypiccdata[i].ToString("X2");}ComOrd = ComOrd + comedc.ToString("X2"); //校验码richTextBox2.Text = ComOrd;//-------------------------------------------------------------------status = piccinit_ntag(myctrlword, mypiccserial, mypickey, mypiccdata);switch (status){case 0:pcdbeep(38);string CardSN = "";for (i = 0; i < 7; i++){CardSN = CardSN + mypiccserial[i].ToString("X2");}textBox7.Text = CardSN;MessageBox.Show("卡片初始化成功!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Information );break;case 8:textBox7.Text = "";MessageBox.Show("Please put the card on the induction area!", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;case 12:MessageBox.Show("卡密码认证失败!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Information );break;case 14:MessageBox.Show("初始化卡失败,可能要先认证密码!", "warn", MessageBoxButtons.OK, MessageBoxIcon.Information);break;case 23:MessageBox.Show("Please Connection the USB Card reader !", "Note:", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:textBox7.Text = "";MessageBox.Show("Error Code:" + status, "warn", MessageBoxButtons.OK, MessageBoxIcon.Warning);break;}}private void textBox6_TextChanged(object sender, EventArgs e){}private void textBox8_TextChanged(object sender, EventArgs e){}private void textBox4_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}private void textBox2_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}private void textBox6_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}private void textBox8_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && !(e.KeyChar >= 97 && e.KeyChar <= 102) && !(e.KeyChar >= 65 && e.KeyChar <= 70))  //only input hex data{e.Handled = true;}}}
}

C#读写NFC系列Ntag2x芯片源码相关推荐

  1. 西门子PLC源码图纸S7-224XP-226 ARM芯片代码ST芯片源码

    西门子PLC源码图纸S7-224XP-226 ARM芯片代码ST芯片源码 ID:879638621827400东莞现货

  2. 死磕 java同步系列之ReentrantReadWriteLock源码解析

    问题 (1)读写锁是什么? (2)读写锁具有哪些特性? (3)ReentrantReadWriteLock是怎么实现读写锁的? (4)如何使用ReentrantReadWriteLock实现高效安全的 ...

  3. c语言读写nfc,Android NFC M1卡读写芯片卡读写(CPU卡读写)(RFID读写)

    版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/sgn5200/article/deta ...

  4. 最简单的基于FFmpeg的内存读写的例子:内存转码器

    ===================================================== 最简单的基于FFmpeg的内存读写的例子系列文章列表: 最简单的基于FFmpeg的内存读写的 ...

  5. 分享88个ASP贺卡图片源码,总有一款适合您

    分享88个ASP贺卡图片源码,总有一款适合您 88个ASP贺卡图片源码下载链接:https://pan.baidu.com/s/1OilB4S8FjYVi3f3q08OdUA?pwd=07dy  提取 ...

  6. 【Flutter】Flutter 拍照示例 ( 拍照并获取照片源码示例 | image_picker 0.7.2+1 | Flutter 最新 SDK 安装 )

    文章目录 一.image_picker 使用 二.更新 Flutter SDK 三.image_picker 使用示例 四.相关资源 之前在 [Flutter]Flutter 拍照示例 ( 拍照并获取 ...

  7. SequoiaDB 系列之六 :源码分析之coord节点

    好久不见. 在上一篇SequoiaDB 系列之五   :源码分析之main函数,有讲述进程开始运行时,会根据自身的角色,来初始化不同的CB(控制块,control block). 在之前的一篇Sequ ...

  8. arduinopn532模块_零知开源分享-使用PN532串口NFC模块读写NFC卡片

    POSTAMBLE:帧尾 一般为 00. 2.读写示例分析 使用的是pn532为主控芯片的NFC串口模块,来读写M1卡,注意所有数字为16进制形式.用usb转串口模块将pn532与电脑连接,串口助手发 ...

  9. 【对讲机的那点事】手把手教你安装公网4G对讲机读写频的驱动及写码?

    大家都知道专业的对讲机需要通过写频软件来和原有的频率对频,专业的对讲机销售公司人员都能够熟练的操作,但是4G公网集群对讲机和专业对讲机读写频操作都是大同小异,但是需要装载一个USB驱动安装包,今天小编 ...

最新文章

  1. SAP PP使用ECR去修改Recipe主数据,报错:Generation not supported for change object
  2. 梳理MVC 架构 MVVM架构
  3. 【uva11994】Happy Painting!【LCT】
  4. [COGS 622] [NOIP2011] 玛雅游戏 模拟
  5. Python中的文件操作和异常
  6. JDBC中Statement与PreparedStatement的区别
  7. HDU4506 小明系列故事——师兄帮帮忙
  8. 庆祝.NET Core悄然崛起:免费送50本优秀技术书籍,请笑纳!!
  9. 进程调度算法 C++实现
  10. junit rule_使用@Rule在JUnit中测试文件和目录
  11. 颈椎前路caspar撑开器_“骨质增生”导致的颈椎病怎么破?
  12. 技术和赚钱真的冲突吗?
  13. testng连接MySQL_Selenium+TestNG实战-8-连接数据库方法去验证文章是否发布
  14. java词法分析_Hive源码系列(七)编译模块之词法、语法解析 (中)
  15. 瑞驰vCloud超融合让数据中心业务更稳定
  16. MATLAB 与Modelsim之间对测试系统的联合仿真
  17. 关于Xcode的Other Linker Flags
  18. 武汉市查询社保电脑号及公积金账号的方法(湖北省其他市也适用)
  19. 单文件PHP版视频解析源码(中间件)
  20. pycharm配置连接服务器+python环境设置

热门文章

  1. CSDN,我的良师益友
  2. 航班信息管理系统(JDBC)
  3. 擦亮AI之星:百度奖学金到底在嘉奖什么?
  4. apk ipa sis 各是什么东西
  5. 设计网络拓扑,一般人我不告诉他这么搞
  6. Zookeeper高频面试题36问(附答案)
  7. 腾讯视频评论爬虫实战
  8. 计算器 控制器 计算机的神经中枢,计算机基础知识(9).ppt
  9. 《图解TCP/IP》读书笔记二:TCP/IP基础知识
  10. laravel-admin 省市区三级联动的爬坑问题