T5557卡是美国Atmel公司生产的多功能非接触式射频卡芯片,属于125KHz的低频卡,在国内有广大的应用市场。该芯片共有330bit(比特)的EPROM(分布为10个区块, 每个区块33bit)。0页的块0是被保留用于设置T5557操作模式的参数配置块。第0页第7块可以作用户数据块使用,也可以作为保护全部数据的密码(假如在配置块中启用密码功能的话),防止非法改写数据。 第1页的1、2块保存了出厂商信息及唯一出厂ID,只能读取不可更改,我们的读写器取出其中的6个字节做为物理卡号,以实现与13.56等高频卡相同的应用场景。

        T5567、T5577是T5557的升级版。

一、函数声明 

#include <QDebug>
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "QLibrary"
#include "QMessageBox"

//函数声明
//驱动发卡器响声
typedef  unsigned char (*idr_beep)(unsigned long xms);
idr_beep myidr_beep = (idr_beep)QLibrary("OUR_IDR.dll").resolve("idr_beep");

//读取发卡器编号
typedef  unsigned char  (*pcdgetdevicenumber)(unsigned char *devicenumber);
pcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("OUR_IDR.dll").resolve("pcdgetdevicenumber");

//读t5557卡
typedef  unsigned char (*t5557_read)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *blockflag,unsigned char *readdata);
t5557_read myt5557_read = (t5557_read)QLibrary("OUR_IDR.dll").resolve("t5557_read");

//写t5557卡
typedef  unsigned char (*t5557_write)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *blockflag,unsigned char *writedata);
t5557_write myt5557_write = (t5557_write)QLibrary("OUR_IDR.dll").resolve("t5557_write");

//修改t5557卡密码
typedef  unsigned char (*t5557_changekey)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *newkey);
t5557_changekey myt5557_changekey = (t5557_changekey)QLibrary("OUR_IDR.dll").resolve("t5557_changekey");

//修改t5557卡配置值
typedef  unsigned char (*t5557_init)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *mypiccdata,unsigned char *newkey);
t5557_init myt5557_init = (t5557_init)QLibrary("OUR_IDR.dll").resolve("t5557_init");

//读id卡
typedef  unsigned char (*idr_read)(unsigned char *piccserial);
idr_read myidr_read = (idr_read)QLibrary("OUR_IDR.dll").resolve("idr_read");

//读hid卡
typedef  unsigned char (*hid_read)(unsigned char *piccserial);
hid_read myhid_read = (hid_read)QLibrary("OUR_IDR.dll").resolve("hid_read");

//将t5557卡制作成ID卡
typedef  unsigned char (*t5557_to4100)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *newkey,unsigned char *newuid);
t5557_to4100 myt5557_to4100 = (t5557_to4100)QLibrary("OUR_IDR.dll").resolve("t5557_to4100");

//将t5557卡制作成HID卡
typedef  unsigned char (*t5557_tohid)(unsigned char ctrlword,unsigned char *piccserial,unsigned char *authkey,unsigned char *newkey,unsigned char *newuid);
t5557_tohid myt5557_tohid = (t5557_tohid)QLibrary("OUR_IDR.dll").resolve("t5557_tohid");


const unsigned char NEEDSERIAL=0x01;   //需要只对指定系列号的卡操作
const unsigned char NEEDKEY=0x02;      //需要用密码认证
const unsigned char LOCKBIT=0x04;      //锁定配置块或数据块
const unsigned char KEYENABLE=0x08;    //启用本卡的密码功能
const unsigned char RESETCARD=0x10;    //操作成功后重启卡片

二、读取t5557卡块数据

void MainWindow::on_push_readcard_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char mypiccdata[50];
    unsigned char mypiccblockflag[2];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
            for(int i=0;i<4;i++){
                bool ok;
                oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDKEY;
        }else{
            QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
            return;
        }
    }

    if(ui->check_serial->isChecked()){
        QString picserial=ui->text_piccserial->text().trimmed();
        if(picserial.length()==12 and checkinput(picserial)){
            for(int i=0;i<6;i++){
                bool ok;
                mypiccserial[i]=QString(picserial.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDSERIAL;
        }else{
            QMessageBox::critical(NULL, "提示","请输入12位16进制卡号!");
            return;
        }
    }

    mypiccblockflag[0]=0;
    if(ui->check_block0->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,0);}
    if(ui->check_block1->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,1);}
    if(ui->check_block2->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,2);}
    if(ui->check_block3->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,3);}
    if(ui->check_block4->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,4);}
    if(ui->check_block5->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,5);}
    if(ui->check_block6->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,6);}
    if(ui->check_block7->isChecked()){mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,7);}

    mypiccblockflag[1]=0;
    if(ui->check_block8->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,1);}
    if(ui->check_block9->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,2);}
    if(ui->check_block10->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,3);}
    if(ui->check_block11->isChecked()){mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,4);}

    if (myt5557_read == NULL){
        QMessageBox::critical(NULL, "提示", "t5557_read函数装载失败!");
    }else{
        status = myt5557_read(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);
        if(status==0){
            myidr_beep(30);            
            QString blockdata="";
            for(int i=0;i<mypiccdata[1];i++){
                blockdata=blockdata+QString::asprintf("%02X", mypiccdata[2+i]);
            }
            if(ui->check_block0->isChecked()){ui->text_block0->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block1->isChecked()){ui->text_block1->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block2->isChecked()){ui->text_block2->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block3->isChecked()){ui->text_block3->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block4->isChecked()){ui->text_block4->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block5->isChecked()){ui->text_block5->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block6->isChecked()){ui->text_block6->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block7->isChecked()){ui->text_block7->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block8->isChecked()){ui->text_block8->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block9->isChecked()){ui->text_block9->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block10->isChecked()){ui->text_block10->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}
            if(ui->check_block11->isChecked()){ui->text_block11->setText(blockdata.left(8));blockdata=blockdata.right(blockdata.length()-8);}

            QMessageBox::information(NULL, "提示", QString::asprintf("读卡成功,卡号:%02X%02X%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5])+QString::asprintf(",卡无线转输分频比:%03d",mypiccdata[0] ));
        }
        else
        {
            disperrinf(status);
        }
    }
}

三、写数据到t5557指定块

void MainWindow::on_push_writcard_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char mypiccdata[48];
    unsigned char mypiccblockflag[2];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
            for(int i=0;i<4;i++){
                bool ok;
                oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDKEY;
        }else{
            QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
            return;
        }
    }

    if(ui->check_serial->isChecked()){
        QString picserial=ui->text_piccserial->text().trimmed();
        if(picserial.length()==12 and checkinput(picserial)){
            for(int i=0;i<6;i++){
                bool ok;
                mypiccserial[i]=QString(picserial.mid(i*2,2)).toInt(&ok,16);
            }
            myctrlword=myctrlword+NEEDSERIAL;
        }else{
            QMessageBox::critical(NULL, "提示","请输入12位16进制卡号!");
            return;
        }
    }

    QString writinf="";
    mypiccblockflag[0]=0;
    if(ui->check_block0->isChecked()){
        if(ui->text_block0->text().length()==8 and checkinput(ui->text_block0->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,0);
            writinf=writinf+ui->text_block0->text();
        }else{
            QMessageBox::critical(NULL, "提示","第0块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block1->isChecked()){
        if(ui->text_block1->text().length()==8 and checkinput(ui->text_block1->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,1);
            writinf=writinf+ui->text_block1->text();
        }else{
            QMessageBox::critical(NULL, "提示","第1块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block2->isChecked()){
        if(ui->text_block2->text().length()==8 and checkinput(ui->text_block2->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,2);
            writinf=writinf+ui->text_block2->text();
        }else{
            QMessageBox::critical(NULL, "提示","第2块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block3->isChecked()){
        if(ui->text_block3->text().length()==8 and checkinput(ui->text_block3->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,3);
            writinf=writinf+ui->text_block3->text();
        }else{
            QMessageBox::critical(NULL, "提示","第3块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block4->isChecked()){
        if(ui->text_block4->text().length()==8 and checkinput(ui->text_block4->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,4);
            writinf=writinf+ui->text_block4->text();
        }else{
            QMessageBox::critical(NULL, "提示","第4块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block5->isChecked()){
        if(ui->text_block5->text().length()==8 and checkinput(ui->text_block5->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,5);
            writinf=writinf+ui->text_block5->text();
        }else{
            QMessageBox::critical(NULL, "提示","第5块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block6->isChecked()){
        if(ui->text_block6->text().length()==8 and checkinput(ui->text_block6->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,6);
            writinf=writinf+ui->text_block6->text();
        }else{
            QMessageBox::critical(NULL, "提示","第6块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block7->isChecked()){
        if(ui->text_block7->text().length()==8 and checkinput(ui->text_block7->text())){
            mypiccblockflag[0]=mypiccblockflag[0]+qPow(2,7);
            writinf=writinf+ui->text_block7->text();
        }else{
            QMessageBox::critical(NULL, "提示","第7块请输入8位16进制数据!");
            return;
        }
    }

    mypiccblockflag[1]=0;
    if(ui->check_block8->isChecked()){
        if(ui->text_block8->text().length()==8 and checkinput(ui->text_block8->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,1);
            writinf=writinf+ui->text_block8->text();
        }else{
            QMessageBox::critical(NULL, "提示","第8块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block9->isChecked()){
        if(ui->text_block9->text().length()==8 and checkinput(ui->text_block9->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,2);
            writinf=writinf+ui->text_block9->text();
        }else{
            QMessageBox::critical(NULL, "提示","第9块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block10->isChecked()){
        if(ui->text_block10->text().length()==8 and checkinput(ui->text_block10->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,3);
            writinf=writinf+ui->text_block10->text();
        }else{
            QMessageBox::critical(NULL, "提示","第10块请输入8位16进制数据!");
            return;
        }
    }

    if(ui->check_block11->isChecked()){
        if(ui->text_block11->text().length()==8 and checkinput(ui->text_block11->text())){
            mypiccblockflag[1]=mypiccblockflag[1]+qPow(2,4);
            writinf=writinf+ui->text_block11->text();
        }else{
            QMessageBox::critical(NULL, "提示","第11块请输入8位16进制数据!");
            return;
        }
    }

    if(writinf.length()==0){
        QMessageBox::critical(NULL, "提示", "请选择要写入数据的块!");
        return;
    }else{
        for(int i=0;i<writinf.length()/2;i++){
            bool ok;
            mypiccdata[i]=QString(writinf.mid(i*2,2)).toInt(&ok,16);
        }
    }

    if (myt5557_write == NULL){
        QMessageBox::critical(NULL, "提示", "t5557_write函数装载失败!");
    }else{
        status = myt5557_write(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);
        if(status==0){
            myidr_beep(30);
            QMessageBox::information(NULL, "提示", QString::asprintf("写卡成功,卡号:%02X%02X%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]));
        }
        else
        {
            disperrinf(status);
        }
    }
}

四、将t5557卡制做成ID、HID卡

void MainWindow::on_pushButton_3_clicked()
{
    unsigned char status;
    unsigned char myctrlword=0;
    unsigned char mypiccserial[6];
    unsigned char oldpicckey[4];
    unsigned char newpicckey[4];

    if(ui->check_authkey->isChecked()){
        QString authkey=ui->text_authkey->text().trimmed();
        if(authkey.length()==8 and checkinput(authkey)){
                for(int i=0;i<4;i++){
                        bool ok;
                        oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
                }
                myctrlword=myctrlword+NEEDKEY;
        }else{
                QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
                return;
        }
    }

    if(ui->check_serial->isChecked()){
        QString picserial=ui->text_piccserial->text().trimmed();
        if(picserial.length()==12 and checkinput(picserial)){
                for(int i=0;i<6;i++){
                        bool ok;
                        mypiccserial[i]=QString(picserial.mid(i*2,2)).toInt(&ok,16);
                }
                myctrlword=myctrlword+NEEDSERIAL;
        }else{
                QMessageBox::critical(NULL, "提示","请输入12位16进制卡号!");
                return;
        }
    }

    if(ui->check_authkey_2->isChecked()){
        QString authkey2=ui->text_authkey_2->text().trimmed();
        if(authkey2.length()==8 and checkinput(authkey2)){
                for(int i=0;i<4;i++){
                        bool ok;
                        newpicckey[i]=QString(authkey2.mid(i*2,2)).toInt(&ok,16);
                }
                myctrlword=myctrlword+KEYENABLE;
        }else{
                QMessageBox::critical(NULL, "提示","请输入8位16进制新密码!");
                return;
        }
    }

    myctrlword=myctrlword+RESETCARD;  //操作后重启卡片,否则在制卡后,需要拿开卡片重放才能成功读卡

    QString uidstr=ui->text_idserial->text().trimmed();
    if(ui->radio_em4100->isChecked()){
        if(uidstr.length()!=10 or checkinput(uidstr)==false){
                QMessageBox::critical(NULL, "提示", "请输入10位16进制原始ID卡号!");
                return;
        }else{
            unsigned char mynewuid[5];
            for(int i=0;i<5;i++){
                bool ok;
                mynewuid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
            }
            if (myt5557_to4100 == NULL){
                QMessageBox::critical(NULL, "提示", "t5557_to4100函数装载失败!");
            }else{
                status = myt5557_to4100(myctrlword,mypiccserial,oldpicckey,newpicckey,mynewuid);
                if(status==0){
                    myidr_beep(30);
                    QMessageBox::information(NULL, "提示", "ID卡号写入成功,卡片变成ID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能。");
                }
                else
                {
                    disperrinf(status);
                }
            }
        }
    }else{
            if(uidstr.length()!=14 or checkinput(uidstr)==false){
                QMessageBox::critical(NULL, "提示", "请输入14位16进制原始HID卡号!");
                return;
            }else{
                unsigned char mynewuid[7];
                for(int i=0;i<7;i++){
                    bool ok;
                    mynewuid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
                }
                if (myt5557_tohid == NULL){
                    QMessageBox::critical(NULL, "提示", "t5557_tohid函数装载失败!");
                }else{
                    status = myt5557_tohid(myctrlword,mypiccserial,oldpicckey,newpicckey,mynewuid);
                    if(status==0){
                        myidr_beep(30);
                        QMessageBox::information(NULL, "提示", "HID卡号写入成功,卡片变成HID卡!不能再用t5557的指令读写此卡,可重新设置配置块恢复t5557卡功能。");
                    }
                    else
                    {
                        disperrinf(status);
                    }
                }
            }
    }
}


五、卡号转换

void MainWindow::on_push_changeid0_clicked()
 {
     bool ok;
     unsigned long  cardno;
     QString cardstr;
     QString binstr;    if(ui->radio_em4100->isChecked()){
         QString uidstr=ui->text_idserial->text().trimmed();
         if(uidstr.length()!=10 or checkinput(uidstr)==false){
             QMessageBox::critical(NULL, "提示", "请输入10位16进制原始ID卡号!");
             return;
         }else{
             switch (ui->comboBox->currentIndex()){
                 case 0:
                     ui->text_newid0->setText(uidstr.mid(0,2));
                     ui->text_newid1->setText(uidstr.mid(2,2));
                     ui->text_newid2->setText(uidstr.mid(4,6));
                     break;
                 case 1:
                     ui->text_newid0->setText(uidstr.mid(0,2));
                     ui->text_newid1->setText("");
                     cardno=uidstr.mid(2,2).toInt(&ok,16)*16777216 + uidstr.mid(4,2).toInt(&ok,16)*65536 + uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                     cardstr=QString::number(cardno);
                     ui->text_newid2->setText(("0000000000"+QString::number(cardno)).right(10));
                     break;
                 case 2:
                     ui->text_newid0->setText(uidstr.mid(0,2));
                     ui->text_newid1->setText("");
                     cardno=uidstr.mid(2,2).toInt(&ok,16)*256 + uidstr.mid(4,2).toInt(&ok,16) ;
                     cardstr=QString::asprintf("%05d",cardno);
                     cardno=uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                     cardstr=cardstr+QString::asprintf("%05d",cardno);
                     ui->text_newid2->setText(cardstr);
                     break;
                 default:
                     ui->text_newid0->setText(uidstr.mid(0,2));
                     ui->text_newid1->setText(uidstr.mid(2,2));
                     cardno= uidstr.mid(4,2).toInt(&ok,16) ;
                     cardstr=QString::asprintf("%03d",cardno);
                     cardno=uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                     cardstr=cardstr+QString::asprintf("%05d",cardno);
                     ui->text_newid2->setText(cardstr);
                     break;
                 }
             }
     }else{
             QString uidstr=ui->text_idserial->text().trimmed();
             if(uidstr.length()!=14 or checkinput(uidstr)==false){
                 QMessageBox::critical(NULL, "提示", "请输入14位16进制原始ID卡号!");
                 return;
             }else{
                 ui->text_newid3->setText(QString::asprintf("%d",uidstr.mid(0,2).toInt(&ok,16)));
                 switch (ui->comboBox->currentIndex()){
                     case 0:
                         ui->text_newid0->setText(uidstr.mid(2,4));
                         ui->text_newid1->setText(uidstr.mid(6,2));
                         ui->text_newid2->setText(uidstr.mid(8,6));
                         break;
                     case 1:
                         ui->text_newid0->setText(uidstr.mid(2,4));
                         ui->text_newid1->setText("");
                         cardno=uidstr.mid(6,2).toInt(&ok,16)*16777216 + uidstr.mid(8,2).toInt(&ok,16)*65536 + uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                         ui->text_newid2->setText(QString::asprintf("%010d",cardno));
                         break;
                     case 2:
                         ui->text_newid0->setText(uidstr.mid(2,4));
                         ui->text_newid1->setText("");
                         cardno=uidstr.mid(6,2).toInt(&ok,16)*256 + uidstr.mid(8,2).toInt(&ok,16) ;
                         cardstr=QString::asprintf("%05d",cardno);
                         cardno=uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                         cardstr=cardstr+QString::asprintf("%05d",cardno);
                         ui->text_newid2->setText(cardstr);
                         break;
                     case 3:
                         ui->text_newid0->setText(uidstr.mid(2,4));
                         ui->text_newid1->setText(uidstr.mid(6,2));
                         cardno= uidstr.mid(8,2).toInt(&ok,16) ;
                         cardstr=QString::asprintf("%03d",cardno);
                         cardno=uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                         cardstr=cardstr+QString::asprintf("%05d",cardno);
                         ui->text_newid2->setText(cardstr);
                         break;                    case 4:
                         ui->text_newid0->setText(uidstr.mid(2,4));
                         binstr=("00000000"+QString::number(uidstr.mid(6,2).toInt(&ok,16),2)).right(8)+("00000000"+QString::number(uidstr.mid(8,2).toInt(&ok,16),2)).right(8)+("00000000"+QString::number(uidstr.mid(10,2).toInt(&ok,16),2)).right(8)+("00000000"+QString::number(uidstr.mid(12,2).toInt(&ok,16),2)).right(8);
                         cardno=binstr.mid(0,13).toInt(&ok,2);
                         ui->text_newid1->setText(("0000"+QString::number(cardno,16)).right(4));                        cardno=binstr.mid(13,19).toInt(&ok,2);
                         ui->text_newid2->setText(("000000"+QString::number(cardno,10)).right(6));                        break;
                     default:
                         ui->text_newid0->setText(uidstr.mid(2,4));
                         ui->text_newid1->setText(uidstr.mid(6,4));
                         cardno=uidstr.mid(10,2).toInt(&ok,16)*256 + uidstr.mid(12,2).toInt(&ok,16) ;
                         cardstr=QString::asprintf("%05d",cardno);
                         ui->text_newid2->setText(cardstr);
                         break;
                 }
             }
     }
 }

六、修改t5557卡配置块

void MainWindow::on_push_editconfig_clicked()
 {
     unsigned char status;
     unsigned char myctrlword=0;
     unsigned char mypiccserial[6];
     unsigned char oldpicckey[4];
     unsigned char newpicckey[4];
     unsigned char mypiccdata[4];    if(ui->check_authkey->isChecked()){
         QString authkey=ui->text_authkey->text().trimmed();
         if(authkey.length()==8 and checkinput(authkey)){
             for(int i=0;i<4;i++){
                 bool ok;
                 oldpicckey[i]=QString(authkey.mid(i*2,2)).toInt(&ok,16);
             }
             myctrlword=myctrlword+NEEDKEY;
         }else{
             QMessageBox::critical(NULL, "提示","请输入8位16进制认证密码!");
             return;
         }
     }else{
         newpicckey[0]=0;
         newpicckey[1]=0;
         newpicckey[2]=0;
         newpicckey[3]=0;
     }    if(ui->check_Enkey->isChecked()){
         QString newkey=ui->text_Enauthkey->text().trimmed();
         if(newkey.length()!=8 or checkinput(newkey)==false){
             QMessageBox::critical(NULL, "提示", "请输入8位16进制保护密码!");
             return;
         }else{
             for(int i=0;i<newkey.length()/2;i++){
                 bool ok;
                 newpicckey[i]=QString(newkey.mid(i*2,2)).toInt(&ok,16);
             }
             myctrlword = myctrlword + KEYENABLE;
         }
     }else{
         newpicckey[0]=0;
         newpicckey[1]=0;
         newpicckey[2]=0;
         newpicckey[3]=0;
     }    QString configstr=ui->text_config->text().trimmed();
     if(configstr.length()!=8 or checkinput(configstr)==false){
         QMessageBox::critical(NULL, "提示", "请输入8位16进制配置值!");
         return;
     }else{
         for(int i=0;i<configstr.length()/2;i++){
             bool ok;
             mypiccdata[i]=QString(configstr.mid(i*2,2)).toInt(&ok,16);
         }
     }    if (myt5557_init == NULL){
         QMessageBox::critical(NULL, "提示", "t5557_init函数装载失败!");
     }else{
         status = myt5557_init(myctrlword,mypiccserial,oldpicckey,mypiccdata,newpicckey);
         if(status==0){
             myidr_beep(30);
             QMessageBox::information(NULL, "提示", QString::asprintf("修改卡配置值成功,卡号:%02X%02X%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]));
         }
         else
         {
             disperrinf(status);
         }
     }
 }