C#读写T5557芯片卡复制ID门禁卡源码

2023-10-07 04:50

本文主要是介绍C#读写T5557芯片卡复制ID门禁卡源码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

        T5557卡是美国Atmel公司生产的多功能非接触式射频芯片卡,属于125KHz的低频卡,在国内有广大的应用市场,如很多酒店的门禁卡都是使用T5557卡。该芯片共有330bit(比特)的EPROM(分布为10个区块, 每个区块33bit)。0页的块0是被保留用于设置T5557操作模式的参数配置块。第0页第7块可以作用户数据块使用,也可以作为保护全部数据的密码(假如在配置块中启用密码功能的话),防止非法改写数据。 第1页的1、2块保存了出厂商信息及唯一出厂ID,只能读取不可更改。T5567、T5577是T5557的升级版。

        通过修改T5557卡的参数配置块,可以将t5557卡模拟成ID卡及HID卡,所以被广泛地用于门禁卡的复制行业。

本示例使用的发卡器介绍:T5557 T5567 T5577低频RFID读写器 EM4100 HID卡复制器 酒店门卡-淘宝网 (taobao.com)

  一、函数声明

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{CheckBox[] myCheckBox = new CheckBox[14];TextBox[] myTextBox = new TextBox[14]; //------------------------------------------------------------------------------------------------------------------------------------------------------//外部函数声明:让设备发出声响[DllImport("OUR_IDR.dll", EntryPoint = "idr_beep", CallingConvention = CallingConvention.StdCall)]static extern byte idr_beep(UInt32 xms);//xms单位为毫秒 //------------------------------------------------------------------------------------------------------------------------------------------------------    //读取设备编号,可做为软件加密狗用,也可以根据此编号在公司网站上查询保修期限[DllImport("OUR_IDR.dll", EntryPoint = "pcdgetdevicenumber", CallingConvention = CallingConvention.StdCall)]static extern byte pcdgetdevicenumber(byte[] devicenumber);//devicenumber用于返回编号 //------------------------------------------------------------------------------------------------------------------------------------------------------    //只读EM4100卡号[DllImport("OUR_IDR.dll", EntryPoint = "idr_read", CallingConvention = CallingConvention.StdCall)]public static extern byte idr_read(byte[] serial);//serial返回卡号        //------------------------------------------------------------------------------------------------------------------------------------------------------    //只读卡号,只读一次EM4100卡,必须拿开卡才能再读到[DllImport("OUR_IDR.dll", EntryPoint = "idr_read_once", CallingConvention = CallingConvention.StdCall)]public static extern byte idr_read_once(byte[] serial);//serial返回卡号//------------------------------------------------------------------------------------------------------------------------------------------------------//T5557卡写配置块[DllImport("OUR_IDR.dll", EntryPoint = "t5557_init", CallingConvention = CallingConvention.StdCall)]public static extern byte  t5557_init(byte ctrlword,byte[] seria,byte[] key,byte[] configdata,byte[] newkey);//------------------------------------------------------------------------------------------------------------------------------------------------------//T5557卡读卡[DllImport("OUR_IDR.dll", EntryPoint = "t5557_read", CallingConvention = CallingConvention.StdCall)]public static extern byte  t5557_read(byte ctrlword,byte[] seria,byte[] key,byte[] blockflag,byte[] readdata);//------------------------------------------------------------------------------------------------------------------------------------------------------//T5557卡写卡[DllImport("OUR_IDR.dll", EntryPoint = "t5557_write", CallingConvention = CallingConvention.StdCall)]public static extern byte  t5557_write(byte ctrlword,byte[] seria,byte[] key,byte[] blockflag,byte[] writedata);//------------------------------------------------------------------------------------------------------------------------------------------------------//T5557卡改密码[DllImport("OUR_IDR.dll", EntryPoint = "t5557_changekey", CallingConvention = CallingConvention.StdCall)]public static extern byte  t5557_changekey(byte ctrlword,byte[] seria,byte[] oldkey,byte[] newkey);//------------------------------------------------------------------------------------------------------------------------------------------------------//用T5557卡制作ID卡(也就是EM4100及兼容卡)[DllImport("OUR_IDR.dll", EntryPoint = "t5557_to4100", CallingConvention = CallingConvention.StdCall)]public static extern byte  t5557_to4100(byte ctrlword,byte[] seria,byte[] oldkey,byte[] newkey,byte[] myuidbuf);//-----------------------------------------------------------------------------------------------------------------------------------------------------        //只读HID卡号[DllImport("OUR_IDR.dll", EntryPoint = "hid_read", CallingConvention = CallingConvention.StdCall)]public static extern byte hid_read(byte[] serial);//serial返回卡号 //------------------------------------------------------------------------------------------------------------------------------------------------------//用T5557卡制作HID卡[DllImport("OUR_IDR.dll", EntryPoint = "t5557_tohid", CallingConvention = CallingConvention.StdCall)]public static extern byte t5557_tohid(byte ctrlword, byte[] seria, byte[] oldkey, byte[] newkey, byte[] myuidbuf);byte NEEDSERIAL = 0x01;   //需要只对指定系列号的卡操作byte NEEDKEY = 0x02;      //需要用密码认证byte LOCKBIT = 0x04;      //锁定配置块或数据块,仅对   t5557_init,t5557_write ,t5557_changekey函数有效byte KEYENABLE = 0x08;    //启用本卡的密码功能byte RESETCARD = 0x10;    //操作成功后重启卡片

二、读取T5557卡块内数据 

        private void button1_Click(object sender, EventArgs e){byte status;     //存放返回值int j;byte myctrlword = 0x00;  //控制字byte[] oldpicckey = new byte[4];  //密码byte[] mypiccserial = new byte[6];  //卡序列号byte[] mypiccdata = new byte[50];  //读卡数据缓冲:卡无线转输分频比、卡内容长度(字节数),及最多返回12个块的数据byte[] mypiccblockflag = new byte[2]; //指定读哪一块string PasswStr = textBox14.Text.Trim();string seriaStr = textBox15.Text.Trim();if (checkBox1.Checked)  //本次操作需要密码验证{myctrlword =(byte)(myctrlword+ NEEDKEY);try{oldpicckey[0] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(0, 2), 16));oldpicckey[1] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(2, 2), 16));oldpicckey[2] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(4, 2), 16));oldpicckey[3] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(6, 2), 16));}catch {MessageBox.Show("认证密码输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox14.Select();return;}}if (checkBox2.Checked)  //仅操作指定卡号的卡{try{myctrlword = (byte)(myctrlword + NEEDSERIAL);mypiccserial[0] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(0, 2), 16));mypiccserial[1] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(2, 2), 16));mypiccserial[2] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(4, 2), 16));mypiccserial[3] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(6, 2), 16));mypiccserial[4] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(8, 2), 16));mypiccserial[5] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(10, 2), 16));}catch{MessageBox.Show("卡号输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox15.Select();return;}}j = 0;mypiccblockflag[0] = 0x00;for (int i = 0; i < 8; i++){if (myCheckBox[i].Checked){mypiccblockflag[0] = (byte)(mypiccblockflag[0] + Math.Pow(2, i));j++;}}mypiccblockflag[1] = 0x00;for (int i = 0; i < 4; i++){if (myCheckBox[8+i].Checked){mypiccblockflag[1] = (byte)(mypiccblockflag[1] + Math.Pow(2, i+1));j++;}}status = t5557_read(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);if (status == 0){string blockdata = "";for (int i = 0; i < mypiccdata[1]; i++){blockdata = blockdata + mypiccdata[2+i].ToString("X2");}j = 0;for (int i = 0; i < 12; i++){if (myCheckBox[i].Checked){myTextBox[i].Text = blockdata.Substring(j, 8);j = j + 8;}}seriaStr = "";for(int i=0 ;i<6;i++){seriaStr = seriaStr + mypiccserial[i].ToString("X2"); }idr_beep(30);MessageBox.Show("读卡成功,卡无线转输分频比:" + mypiccdata[0].ToString("D") + ",卡号:" + seriaStr, "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { MessageErrInf(status); }}

三、改写T5557卡块内数据

private void button3_Click(object sender, EventArgs e){byte status;     //存放返回值int j;byte myctrlword = 0x00;               //控制字byte[] oldpicckey = new byte[4];      //密码byte[] mypiccserial = new byte[6];    //卡序列号byte[] mypiccdata = new byte[50];     //写卡数据缓冲byte[] mypiccblockflag = new byte[2]; //指定读哪一块string PasswStr = textBox14.Text.Trim();string seriaStr = textBox15.Text.Trim();int chtxt=Form1_chedkdata();if (chtxt != 100){MessageBox.Show("写卡数据输入错误,请重新输入!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);myTextBox[chtxt].Select(); return;}if (checkBox1.Checked)  //本次操作需要密码验证{myctrlword = (byte)(myctrlword + NEEDKEY);try{oldpicckey[0] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(0, 2), 16));oldpicckey[1] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(2, 2), 16));oldpicckey[2] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(4, 2), 16));oldpicckey[3] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(6, 2), 16));}catch{MessageBox.Show("认证密码输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox14.Select();return;}}if (checkBox2.Checked)  //仅操作指定卡号的卡{try{myctrlword = (byte)(myctrlword + NEEDSERIAL);mypiccserial[0] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(0, 2), 16));mypiccserial[1] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(2, 2), 16));mypiccserial[2] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(4, 2), 16));mypiccserial[3] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(6, 2), 16));mypiccserial[4] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(8, 2), 16));mypiccserial[5] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(10, 2), 16));}catch{MessageBox.Show("卡号输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox15.Select();return;}}j = 0;mypiccblockflag[0] = 0x00;for (int i = 0; i < 8; i++){if (myCheckBox[i].Checked){mypiccblockflag[0] = (byte)(mypiccblockflag[0] + Math.Pow(2, i));j++;}}mypiccblockflag[1] = 0x00;for (int i = 0; i < 4; i++){if (myCheckBox[8 + i].Checked){mypiccblockflag[1] = (byte)(mypiccblockflag[1] + Math.Pow(2, i+1));j++;}}string WriteStr = "";for (int i = 0; i < 12; i++){               if (myCheckBox[i].Checked){WriteStr = WriteStr+myTextBox[i].Text;                    }}for (int i = 0; i < WriteStr.Length/2;i++ ){mypiccdata[i] = Convert.ToByte(Convert.ToInt32(WriteStr.Substring(i * 2, 2), 16));}status = t5557_write(myctrlword, mypiccserial, oldpicckey, mypiccblockflag, mypiccdata);if (status == 0){                seriaStr = "";for (int i = 0; i < 6; i++){seriaStr = seriaStr + mypiccserial[i].ToString("X2");}idr_beep(30);MessageBox.Show("卡号:" + seriaStr+"写卡成功!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { MessageErrInf(status); }}

 四、将T5557卡配置成ID卡、HID卡

private void button8_Click(object sender, EventArgs e){byte status;     //存放返回值byte myctrlword = 0x00;  //控制字byte[] oldpicckey = new byte[4];  //密码byte[] newpicckey = new byte[4];  //新密码byte[] mypiccserial = new byte[6];  //卡序列号byte[] mypiccblockflag = new byte[2]; //指定读哪一块string PasswStr = textBox14.Text.Trim();string seriaStr = textBox15.Text.Trim();string newpassw = textBox20.Text.Trim();string newuidstr = textBox17.Text.Trim();if (checkBox1.Checked)  //本次操作需要密码验证{myctrlword = (byte)(myctrlword + NEEDKEY);try{oldpicckey[0] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(0, 2), 16));oldpicckey[1] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(2, 2), 16));oldpicckey[2] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(4, 2), 16));oldpicckey[3] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(6, 2), 16));}catch{MessageBox.Show("认证密码输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox14.Select();return;}}if (checkBox2.Checked)  //仅操作指定卡号的卡{try{myctrlword = (byte)(myctrlword + NEEDSERIAL);mypiccserial[0] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(0, 2), 16));mypiccserial[1] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(2, 2), 16));mypiccserial[2] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(4, 2), 16));mypiccserial[3] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(6, 2), 16));mypiccserial[4] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(8, 2), 16));mypiccserial[5] = Convert.ToByte(Convert.ToInt32(seriaStr.Substring(10, 2), 16));}catch{MessageBox.Show("卡号输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox15.Select();return;}}if (checkBox11.Checked)  //修改卡片密码{try{myctrlword = (byte)(myctrlword + KEYENABLE);newpicckey[0] = Convert.ToByte(Convert.ToInt32(newpassw.Substring(0, 2), 16));newpicckey[1] = Convert.ToByte(Convert.ToInt32(newpassw.Substring(2, 2), 16));newpicckey[2] = Convert.ToByte(Convert.ToInt32(newpassw.Substring(4, 2), 16));newpicckey[3] = Convert.ToByte(Convert.ToInt32(newpassw.Substring(6, 2), 16));}catch{MessageBox.Show("密码输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox20.Select();return;}}myctrlword = (byte)(myctrlword + RESETCARD); //操作后重启卡片,否则在制卡后,需要拿开卡片重放才能成功读ID卡if (radioButton3.Checked){byte[] myuid = new byte[5];        //写入的新卡号try{myuid[0] = Convert.ToByte(Convert.ToInt32(textBox16.Text.Substring(0, 2), 16));}catch{MessageBox.Show("产家标识输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox16.Select();return;}try{myuid[1] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(0, 2), 16));myuid[2] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(2, 2), 16));myuid[3] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(4, 2), 16));myuid[4] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(6, 2), 16));}catch{MessageBox.Show("新卡号输入错误,请输入8位16进制数的卡号!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox17.Select();return;}status = t5557_to4100(myctrlword, mypiccserial, oldpicckey, newpicckey, myuid);if (status == 0){idr_beep(50);MessageBox.Show("卡号:" + System.Convert.ToString(myuid[1] * 256 * 256 * 256 + myuid[2] * 256 * 256 + myuid[3] * 256 + myuid[4]) + " 写卡成功变成ID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能。", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { MessageErrInf(status); }}else{byte[] myuid = new byte[7];        //写入的新卡号try{myuid[0] = Convert.ToByte(Convert.ToInt32(textBox16.Text.Substring(0, 2), 16));}catch{MessageBox.Show("HID卡号位数错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox16.Select();return;}try{myuid[1] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(0, 2), 16));myuid[2] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(2, 2), 16));myuid[3] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(4, 2), 16));myuid[4] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(6, 2), 16));myuid[5] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(8, 2), 16));myuid[6] = Convert.ToByte(Convert.ToInt32(newuidstr.Substring(10, 2), 16));}catch{MessageBox.Show("新卡号输入错误,请输入12位16进制数的卡号!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox17.Select();return;}status = t5557_tohid(myctrlword, mypiccserial, oldpicckey, newpicckey, myuid);if (status == 0){idr_beep(50);MessageBox.Show("卡号:" + System.Convert.ToString(myuid[3] * 256 * 256 * 256 + myuid[4] * 256 * 256 + myuid[5] * 256 + myuid[6]) + " 写卡成功变成HID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能。", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { MessageErrInf(status); }}}

五、T5557卡初始化

private void button9_Click(object sender, EventArgs e)
        {
            byte status;     //存放返回值
            byte[] oldpicckey = new byte[4];  //旧密码
            byte[] newpicckey = new byte[4];  //启用的新密码
            byte[] mypiccserial = new byte[6];  //卡序列号
            byte[] mypiccdata = new byte[4];  //配置值
            string PasswStr = textBox14.Text.Trim();
            string NewPass = textBox21.Text.Trim();
            string ConfStr = textBox18.Text.Trim();

            byte myctrlword = 0x00;  //控制字

            if (checkBox1.Checked)  //本次操作需要密码验证
            {
                myctrlword = (byte)(myctrlword + NEEDKEY);
                try
                {
                    oldpicckey[0] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(0, 2), 16));
                    oldpicckey[1] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(2, 2), 16));
                    oldpicckey[2] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(4, 2), 16));
                    oldpicckey[3] = Convert.ToByte(Convert.ToInt32(PasswStr.Substring(6, 2), 16));
                }
                catch
                {
                    MessageBox.Show("认证密码输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox14.Select();
                    return;
                }
            }

            if (checkBox13.Checked)  //卡片启用新密码
            {
                myctrlword = (byte)(myctrlword + KEYENABLE);
                try
                {
                    newpicckey[0] = Convert.ToByte(Convert.ToInt32(NewPass.Substring(0, 2), 16));
                    newpicckey[1] = Convert.ToByte(Convert.ToInt32(NewPass.Substring(2, 2), 16));
                    newpicckey[2] = Convert.ToByte(Convert.ToInt32(NewPass.Substring(4, 2), 16));
                    newpicckey[3] = Convert.ToByte(Convert.ToInt32(NewPass.Substring(6, 2), 16));
                }
                catch
                {
                    MessageBox.Show("认证密码输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox21.Select();
                    return;
                }
            }

            try
            {
                mypiccdata[0] = Convert.ToByte(Convert.ToInt32(ConfStr.Substring(0, 2), 16));
                mypiccdata[1] = Convert.ToByte(Convert.ToInt32(ConfStr.Substring(2, 2), 16));
                mypiccdata[2] = Convert.ToByte(Convert.ToInt32(ConfStr.Substring(4, 2), 16));
                mypiccdata[3] = Convert.ToByte(Convert.ToInt32(ConfStr.Substring(6, 2), 16));
            }
            catch
            {
                MessageBox.Show("配置值输入错误!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox18.Select();
                return;
            }

            status = t5557_init(myctrlword,mypiccserial,oldpicckey,mypiccdata,newpicckey);
            if (status == 0)
            {
                string seriaStr = "";
                for (int i = 0; i < 6; i++)
                {
                    seriaStr = seriaStr + mypiccserial[i].ToString("X2");
                }
                idr_beep(30);
                MessageBox.Show("卡号:" + seriaStr + "配置成功!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else { MessageErrInf(status); }
        }

        private void GetConfigNUm()
        {
            byte byte_i;
            byte[] Configdata = new byte[4];

            if (radioButton1.Checked)  //e5550兼容模式(X-Mode位:bit15)为0
            {
                if (comboBox1.SelectedIndex == 0) //主控键
                {
                    Configdata[0] = 0x00;
                }
                else { Configdata[0] = 0x60; }


                if (comboBox2.SelectedIndex < 9) //调制方式
                {
                    byte_i = (byte)comboBox2.SelectedIndex;
                }
                else
                {
                    if (comboBox2.SelectedIndex == 9)
                    {
                        byte_i = 0x10;
                    }
                    else { byte_i = 0x18; }
                }

                Configdata[1] = (byte)((2 * 4) | ((byte_i / 16) & 0x01));  //波特率
                Configdata[2] = (byte)((byte_i % 16) * 16);
                Configdata[2] = (byte)(Configdata[2] | ((comboBox3.SelectedIndex % 4) * 4));  //相位键控调制

                if (checkBox12.Checked) //AOR请求应答模式
                {
                    Configdata[2] = (byte)(Configdata[2] | 0x02);
                }

                Configdata[3] = (byte)((comboBox4.SelectedIndex % 8) * 32);  //最大块

                if (checkBox13.Checked) //启用加密功能
                {
                    if (Configdata[3] > (6 * 32))  //启用密码功能后,最大块不能为7
                    {
                        Configdata[3] = 6 * 32;
                    }
                    Configdata[3] = (byte)(Configdata[3] | 0x10);
                }
                else { Configdata[2] = (byte)(Configdata[2] & 0xfd); } //取消AOR请求应答模式

                if (checkBox14.Checked) //帧终结符有效
                {
                    Configdata[3] = (byte)(Configdata[3] | 0x08);
                }

                if (checkBox19.Checked) //卡片复位延时67ms
                {
                    Configdata[3] = (byte)(Configdata[3] | 0x01);
                }
            }
            else //扩展模式(X-Mode位:bit15)为1
            {
                Configdata[1] = 0x02;

                if (comboBox1.SelectedIndex == 0) //主控键
                {
                    Configdata[0] = 0x60;
                }
                else { Configdata[0] = 0x90; }

                byte_i = (byte)((int)(btlnum.Value) % 64); //波特率BIT9-14
                Configdata[1] = (byte)(Configdata[1] | (byte_i * 4));

                if (comboBox2.SelectedIndex < 6) //调制方式
                {
                    byte_i = (byte)comboBox2.SelectedIndex;
                }
                else
                {
                    if (comboBox2.SelectedIndex == 7)
                    {
                        byte_i = 0x10;
                    }
                    else
                    {
                        if (comboBox2.SelectedIndex == 8)
                        {
                            byte_i = 0x18;
                        }
                        else { byte_i = 0x08; }
                    }
                }

                Configdata[1] = (byte)(Configdata[1] | ((byte_i/16) & 0x01));  //波特率
                Configdata[2] = (byte)((byte_i % 16) * 16);
                Configdata[2] = (byte)(Configdata[2] | ((comboBox3.SelectedIndex % 4) * 4));  //相位键控调制

                if (checkBox12.Checked) //AOR请求应答模式
                {
                    Configdata[2] = (byte)(Configdata[2] | 0x02);
                }

                if (checkBox23.Checked) //OTP
                {
                    Configdata[2] = (byte)(Configdata[2] | 0x01);
                }

                Configdata[3] = (byte)((comboBox4.SelectedIndex % 8) * 32);  //最大块

                if (checkBox13.Checked) //启用加密功能
                {
                    if (Configdata[3] > (6 * 32))  //启用密码功能后,最大块不能为7
                    {
                        Configdata[3] = 6 * 32;
                    }
                    Configdata[3] = (byte)(Configdata[3] | 0x10);
                }
                else { Configdata[2] = (byte)(Configdata[2] & 0xfd); } //取消AOR请求应答模式

                if (checkBox22.Checked) //帧起始符有效
                {
                    Configdata[3] = (byte)(Configdata[3] | 0x08);
                }

                if (checkBox24.Checked) //快速写:0为12TC,1为27TC
                {
                    Configdata[3] = (byte)(Configdata[3] | 0x04);
                }

                if (checkBox25.Checked) //数据取反输出
                {
                    Configdata[3] = (byte)(Configdata[3] | 0x02);
                }

                if (checkBox19.Checked) //卡片复位延时67ms
                {
                    Configdata[3] = (byte)(Configdata[3] | 0x01);
                }
            }

            textBox18.Text = Configdata[0].ToString("X2") + Configdata[1].ToString("X2") + Configdata[2].ToString("X2") + Configdata[3].ToString("X2"); 
        }

这篇关于C#读写T5557芯片卡复制ID门禁卡源码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/156125

相关文章

linux如何复制文件夹并重命名

《linux如何复制文件夹并重命名》在Linux系统中,复制文件夹并重命名可以通过使用“cp”和“mv”命令来实现,使用“cp-r”命令可以递归复制整个文件夹及其子文件夹和文件,而使用“mv”命令可以... 目录linux复制文件夹并重命名我们需要使用“cp”命令来复制文件夹我们还可以结合使用“mv”命令总

C# string转unicode字符的实现

《C#string转unicode字符的实现》本文主要介绍了C#string转unicode字符的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随... 目录1. 获取字符串中每个字符的 Unicode 值示例代码:输出:2. 将 Unicode 值格式化

C#中读取XML文件的四种常用方法

《C#中读取XML文件的四种常用方法》Xml是Internet环境中跨平台的,依赖于内容的技术,是当前处理结构化文档信息的有力工具,下面我们就来看看C#中读取XML文件的方法都有哪些吧... 目录XML简介格式C#读取XML文件方法使用XmlDocument使用XmlTextReader/XmlTextWr

C#比较两个List集合内容是否相同的几种方法

《C#比较两个List集合内容是否相同的几种方法》本文详细介绍了在C#中比较两个List集合内容是否相同的方法,包括非自定义类和自定义类的元素比较,对于非自定义类,可以使用SequenceEqual、... 目录 一、非自定义类的元素比较1. 使用 SequenceEqual 方法(顺序和内容都相等)2.

C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep

C#从XmlDocument提取完整字符串的方法

《C#从XmlDocument提取完整字符串的方法》文章介绍了两种生成格式化XML字符串的方法,方法一使用`XmlDocument`的`OuterXml`属性,但输出的XML字符串不带格式,可读性差,... 方法1:通过XMLDocument的OuterXml属性,见XmlDocument类该方法获得的xm

C#多线程编程中导致死锁的常见陷阱和避免方法

《C#多线程编程中导致死锁的常见陷阱和避免方法》在C#多线程编程中,死锁(Deadlock)是一种常见的、令人头疼的错误,死锁通常发生在多个线程试图获取多个资源的锁时,导致相互等待对方释放资源,最终形... 目录引言1. 什么是死锁?死锁的典型条件:2. 导致死锁的常见原因2.1 锁的顺序问题错误示例:不同

C#提取PDF表单数据的实现流程

《C#提取PDF表单数据的实现流程》PDF表单是一种常见的数据收集工具,广泛应用于调查问卷、业务合同等场景,凭借出色的跨平台兼容性和标准化特点,PDF表单在各行各业中得到了广泛应用,本文将探讨如何使用... 目录引言使用工具C# 提取多个PDF表单域的数据C# 提取特定PDF表单域的数据引言PDF表单是一

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更