常用15693标签NXP ICODE存储结构说明
片内含1024位E2PROM,共分为32 Block,每个Block 32bit。其中64位为唯一序列号,32位用作特殊功能(EAS、AFI、DSFID等),32位用于Block锁定,其余为用户使用区。
本示例使用的发卡器: Android Linux RFID读写器NFC发卡器WEB可编程NDEF文本/智能海报/-淘宝网 (taobao.com)
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QDebug>
#include "QLibrary"
#include "QMessageBox"
//#include <QStringListModel>
#define NEEDSERIAL 0x08;
#define NEEDHALT 0x20;
//QStringListModel *model;
//判断windows、linux系统,声明动态库函数----------------------------------------------------------------------------------------------------------------------------------------------
//让读写器发出声音
typedef unsigned char (*pcdbeep)(unsigned long xms);
#ifdef Q_OS_WIN
pcdbeep mypcdbeep = (pcdbeep)QLibrary("OUR_MIFARE.dll").resolve("pcdbeep");
#else
pcdbeep mypcdbeep = (pcdbeep)QLibrary("./libOURIDR.so").resolve("pcdbeep");
#endif
//返回本读写器独一无二的设备编号
typedef unsigned char (*pcdgetdevicenumber)(unsigned char *devicenumber);
#ifdef Q_OS_WIN
pcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("OUR_MIFARE.dll").resolve("pcdgetdevicenumber");
#else
pcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("./libOURIDR.so").resolve("pcdgetdevicenumber");
#endif
//轻松读15693卡
typedef unsigned char (*iso15693readex)(unsigned char ctrlword,unsigned char afi,unsigned char startblock,unsigned char blocknum,unsigned char *uid,unsigned char *piccdatabuf);
#ifdef Q_OS_WIN
iso15693readex myiso15693readex = (iso15693readex)QLibrary("OUR_MIFARE.dll").resolve("iso15693readex");
#else
iso15693readex myiso15693readex = (iso15693readex)QLibrary("./libOURIDR.so").resolve("iso15693readex");
#endif
//轻松写15693卡
typedef unsigned char (*iso15693writeex)(unsigned char ctrlword,unsigned char afi,unsigned char startblock,unsigned char blocknum,unsigned char *uid,unsigned char *piccdatabuf);
#ifdef Q_OS_WIN
iso15693writeex myiso15693writeex = (iso15693writeex)QLibrary("OUR_MIFARE.dll").resolve("iso15693writeex");
#else
iso15693writeex myiso15693writeex = (iso15693writeex)QLibrary("./libOURIDR.so").resolve("iso15693writeex");
#endif
//寻一张15693卡
typedef unsigned char (*iso15693inventory)(unsigned char flags,unsigned char afi,unsigned char masklen,unsigned char *maskuid,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693inventory myiso15693inventory = (iso15693inventory)QLibrary("OUR_MIFARE.dll").resolve("iso15693inventory");
#else
iso15693inventory myiso15693inventory = (iso15693inventory)QLibrary("./libOURIDR.so").resolve("iso15693inventory");
#endif
//寻多张15693卡
typedef unsigned char (*iso15693inventory16)(unsigned char flags,unsigned char afi,unsigned char masklen,unsigned char *maskuid,unsigned char *revlen,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693inventory16 myiso15693inventory16 = (iso15693inventory16)QLibrary("OUR_MIFARE.dll").resolve("iso15693inventory16");
#else
iso15693inventory16 myiso15693inventory16 = (iso15693inventory16)QLibrary("./libOURIDR.so").resolve("iso15693inventory16");
#endif
//让15693卡进入闲置(Quiet)静止状态
typedef unsigned char (*iso15693stayquiet)(unsigned char flags,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693stayquiet myiso15693stayquiet = (iso15693stayquiet)QLibrary("OUR_MIFARE.dll").resolve("iso15693stayquiet");
#else
iso15693stayquiet myiso15693stayquiet = (iso15693stayquiet)QLibrary("./libOURIDR.so").resolve("iso15693stayquiet");
#endif
//使15693卡进入选择(selected )状态
typedef unsigned char (*iso15693Select)(unsigned char flags,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693Select myiso15693Select = (iso15693Select)QLibrary("OUR_MIFARE.dll").resolve("iso15693Select");
#else
iso15693Select myiso15693Select = (iso15693Select)QLibrary("./libOURIDR.so").resolve("iso15693Select");
#endif
//使15693卡进入准备(Ready)状态
typedef unsigned char (*iso15693resettoready)(unsigned char flags,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693resettoready myiso15693resettoready = (iso15693resettoready)QLibrary("OUR_MIFARE.dll").resolve("iso15693resettoready");
#else
iso15693resettoready myiso15693resettoready = (iso15693resettoready)QLibrary("./libOURIDR.so").resolve("iso15693resettoready");
#endif
//写15693卡AFI
typedef unsigned char (*iso15693writeafi)(unsigned char flags,unsigned char afi,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693writeafi myiso15693writeafi = (iso15693writeafi)QLibrary("OUR_MIFARE.dll").resolve("iso15693writeafi");
#else
iso15693writeafi myiso15693writeafi = (iso15693writeafi)QLibrary("./libOURIDR.so").resolve("iso15693writeafi");
#endif
//锁15693卡AFI
typedef unsigned char (*iso15693lockafi)(unsigned char flags,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693lockafi myiso15693lockafi = (iso15693lockafi)QLibrary("OUR_MIFARE.dll").resolve("iso15693lockafi");
#else
iso15693lockafi myiso15693lockafi = (iso15693lockafi)QLibrary("./libOURIDR.so").resolve("iso15693lockafi");
#endif
//写15693卡DSFID
typedef unsigned char (*iso15693writedsfid)(unsigned char flags,unsigned char dsfid,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693writedsfid myiso15693writedsfid = (iso15693writedsfid)QLibrary("OUR_MIFARE.dll").resolve("iso15693writedsfid");
#else
iso15693writedsfid myiso15693writedsfid = (iso15693writedsfid)QLibrary("./libOURIDR.so").resolve("iso15693writedsfid");
#endif
//锁15693卡DSFID
typedef unsigned char (*iso15693lockdsfid)(unsigned char flags,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693lockdsfid myiso15693lockdsfid = (iso15693lockdsfid)QLibrary("OUR_MIFARE.dll").resolve("iso15693lockdsfid");
#else
iso15693lockdsfid myiso15693lockdsfid = (iso15693lockdsfid)QLibrary("./libOURIDR.so").resolve("iso15693lockdsfid");
#endif
//锁15693卡数据块
typedef unsigned char (*iso15693lockblock)(unsigned char flags,unsigned char startblock,unsigned char *uid);
#ifdef Q_OS_WIN
iso15693lockblock myiso15693lockblock = (iso15693lockblock)QLibrary("OUR_MIFARE.dll").resolve("iso15693lockblock");
#else
iso15693lockblock myiso15693lockblock = (iso15693lockblock)QLibrary("./libOURIDR.so").resolve("iso15693lockblock");
#endif
//获取15693卡系统信息
typedef unsigned char (*iso15693readinfo)(unsigned char flags,unsigned char *uid,unsigned char *revlen,unsigned char *revbuf);
#ifdef Q_OS_WIN
iso15693readinfo myiso15693readinfo = (iso15693readinfo)QLibrary("OUR_MIFARE.dll").resolve("iso15693readinfo");
#else
iso15693readinfo myiso15693readinfo = (iso15693readinfo)QLibrary("./libOURIDR.so").resolve("iso15693readinfo");
#endif
//获取15693卡块安全信息
typedef unsigned char (*iso15693readsecuritystate)(unsigned char flags,unsigned char startblock,unsigned char blocknum,unsigned char *uid,unsigned char *revlen,unsigned char *revbuf);
#ifdef Q_OS_WIN
iso15693readsecuritystate myiso15693readsecuritystate = (iso15693readsecuritystate)QLibrary("OUR_MIFARE.dll").resolve("iso15693readsecuritystate");
#else
iso15693readsecuritystate myiso15693readsecuritystate = (iso15693readsecuritystate)QLibrary("./libOURIDR.so").resolve("iso15693readsecuritystate");
#endif
//读15693卡指定块
typedef unsigned char (*iso15693readblock)(unsigned char flags,unsigned char startblock,unsigned char blocknum,unsigned char *uid,unsigned char *revlen,unsigned char *piccdatabuf);
#ifdef Q_OS_WIN
iso15693readblock myiso15693readblock = (iso15693readblock)QLibrary("OUR_MIFARE.dll").resolve("iso15693readblock");
#else
iso15693readblock myiso15693readblock = (iso15693readblock)QLibrary("./libOURIDR.so").resolve("iso15693readblock");
#endif
//写15693卡指定块
typedef unsigned char (*iso15693writeblock)(unsigned char flags,unsigned char startblock,unsigned char blocknum,unsigned char *uid,unsigned char writelen,unsigned char *writebuf);
#ifdef Q_OS_WIN
iso15693writeblock myiso15693writeblock= (iso15693writeblock)QLibrary("OUR_MIFARE.dll").resolve("iso15693writeblock");
#else
iso15693writeblock myiso15693writeblock= (iso15693writeblock)QLibrary("./libOURIDR.so").resolve("iso15693writeblock");
#endif
//检测输入数据是否为16进制数
static bool checkinput(QString inputstr){
QString inputyes="0123456789abcdefABCDEF";
for(int i=0;i<inputstr.length();i++){
if(inputyes.contains(inputstr.mid(i,1),Qt::CaseSensitive)){
}else{return false;}
}
return true;
}
//检测动态库文件是否在运行目录内
static bool checkdllos(){
#ifdef Q_OS_WIN
QLibrary mylib("OUR_MIFARE.dll");
if (!mylib.load()){ //判断windows系统下,OUR_MIFARE.dll是否在运行目录内
QMessageBox::information(NULL, "提示", "请将OUR_MIFARE.dll文件拷贝到生成exe文件相同目录下!");
return false;
}else{return true;}
#else
QLibrary mylib("./libOURIDR.so");
if (!mylib.load()){ //判断linux系统下,libOURIDR.so是否正运行目录内
QMessageBox::information(NULL, "提示", "请将libOURIDR.so文件拷贝到生成的运行文件相同目录下!");
return false;
}else{return true;}
#endif
}
//显示返回的错误代码信息
static void disperrinf(unsigned char result){
switch (result) {
case 1:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",0~2块都没读出来,可能刷卡太块。但卡序列号已被读出来!");
break;
case 2:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",第0块已被读出,但1~2块读取失败。卡序列号已被读出来!");
break;
case 3:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",第0、1块已被读出,但2块读取失败。卡序列号已被读出来!");
break;
case 8:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",未寻到卡,请重新拿开卡后再放到感应区!");
break;
case 9:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",有多张卡在感应区,寻卡过程中防冲突失败,读序列吗错误!");
break;
case 10:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",该卡可能已被休眠,无法选中卡片!");
break;
case 11:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",密码装载失败!");
break;
case 12:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",卡片密码认证失败!");
break;
case 13:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",读指定块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!");
break;
case 14:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",写指定块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!");
break;
case 18:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",写UID失败,此卡可能不是UID卡!");
break;
case 22:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",动态库或驱动程序异常!");
break;
case 23:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",驱动程序错误或发卡器尚未安装!");
break;
case 24:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",操作超时,一般是动态库没有反应!");
break;
case 25:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",发送字数不够!");
break;
case 26:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",驱动程序错误或发卡器尚未安装!");
break;
case 27:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",操作超时,一般是动态库没有反应!");
break;
case 28:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",发送字数不够!");
break;
default:
QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",未知的错误信息!");
break;
}
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pb_beep_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
status = mypcdbeep(30);
if(status==0){
}
else
{
disperrinf(status);
}
}
void MainWindow::on_pb_getdevnum_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char devicenumber[4];
unsigned char status;
status = mypcdgetdevicenumber(devicenumber);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", QString::asprintf("设备编号:%03d-%03d-%03d-%03d", devicenumber[0],devicenumber[1],devicenumber[2],devicenumber[3]));
}
else
{
disperrinf(status);
}
}
void MainWindow::on_pb_easyread_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char ctrlword=0x00; //读任何卡,不需指定卡号,读完后不静止该卡,可赋值NEEDSERIAL及NEEDHALT的组合模式,或为0
unsigned char afi;
unsigned char myuid[8];
unsigned char startblock;
unsigned char blocknum;
unsigned char piccdatabuf[255];
ui->lineEdit_uid->setText("");
ui->plainTextEdit_data->setPlainText("");
QString afistr=ui->lineEdit_afi->text().trimmed();
if(afistr.length()==2 and checkinput(afistr)){
bool ok;
afi=afistr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制AFI!");
ui->lineEdit_afi->setFocus();
return;
}
startblock=ui->spinBox_star->value();
blocknum=ui->spinBox_num->value();
if(blocknum>12){
QMessageBox::critical(NULL, "提示","一次最多只能读取12块数据!");
return;
}
status = myiso15693readex(ctrlword,afi,startblock,blocknum,myuid,piccdatabuf);
if(status==0){
mypcdbeep(30);
QString uidstr="";
for(int i=0;i<8;i++){
uidstr=uidstr+QString::asprintf("%02X", myuid[i]);
}
ui->lineEdit_uid->setText(uidstr);
QString datastr="";
for(int i=1;i<=piccdatabuf[0];i++){
datastr=datastr+QString::asprintf("%02X ", piccdatabuf[i]);
}
ui->plainTextEdit_data->setPlainText(datastr);
QMessageBox::information(NULL, "提示", "读卡成功,卡片UID:"+uidstr);
}
else
{
if(status==46){
QString uidstr="";
for(int i=0;i<8;i++){
uidstr=uidstr+QString::asprintf("%02X", myuid[i]);
}
ui->lineEdit_uid->setText(uidstr);
QMessageBox::information(NULL, "提示", "本次读取的块数超过卡片允许的一次读取最多块数,读取卡片UID:"+uidstr);
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_easywrite_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char ctrlword=0x00; //读任何卡,不需指定卡号,读完后不静止该卡,可赋值NEEDSERIAL及NEEDHALT的组合模式,或为0
unsigned char afi=0x00;
unsigned char myuid[8];
unsigned char startblock;
unsigned char blocknum;
unsigned char piccdatabuf[255];
unsigned char eachblocksize;
ui->lineEdit_uid->setText("");
QString afistr=ui->lineEdit_afi->text().trimmed();
if(afistr.length()==2 and checkinput(afistr)){
bool ok;
afi=afistr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制AFI!");
return;
}
startblock=ui->spinBox_star->value();
blocknum=ui->spinBox_num->value();
if(blocknum>12){
QMessageBox::critical(NULL, "提示","一次最多只能写12块数据!");
return;
}
switch(ui->comboBox_cardtype->currentIndex()){
case 0:
eachblocksize=4;
break;
case 1:
eachblocksize=8;
break;
default:
eachblocksize=32;
break;
}
piccdatabuf[0]=blocknum*eachblocksize;
//检测写卡数据
QChar ch;
QString writinf = ui->plainTextEdit_data->toPlainText().trimmed();
QString writinf1 = "";
int m = 1;
int n = 0;
char s;
if(writinf.length()<1){
QMessageBox::critical(NULL, "提示", "请输入正确的16进制写卡数据!");
ui->plainTextEdit_data->setFocus();
return;
}
ch = writinf.at(0);
s = writinf.at(0).toLatin1();
for(int i=0; i<writinf.length() ; i++)
{
ch = writinf.at(i);
s = writinf.at(i).toLatin1();
if((('0' <= s) && (s <= '9')) || (('A' <= s) && (s <= 'F')) || (('a' <= s) && (s <= 'f')))
{
writinf1 += ch;
n++;
if(n==2){
bool ok;
piccdatabuf[m++] = writinf1.toInt(&ok,16);
writinf1 = "";
n = 0;
if(m>=49){
break;
}
}
}
else if(s == ' '){
}
else
{
QMessageBox::critical(NULL, "提示", "写卡数据错误,请输入正确的16进制数据!");
ui->plainTextEdit_data->setFocus();
return;
}
}
if(m<=piccdatabuf[0]){
QMessageBox::critical(NULL, "提示", "写卡数据不足,请输入"+QString::asprintf("错误代码:%d", piccdatabuf[0])+"个字节16进制数据!");
ui->plainTextEdit_data->setFocus();
return;
}
status = myiso15693writeex(ctrlword,afi,startblock,blocknum,myuid,piccdatabuf);
if(status==0){
mypcdbeep(30);
QString uidstr="";
for(int i=0;i<8;i++){
uidstr=uidstr+QString::asprintf("%02X", myuid[i]);
}
ui->lineEdit_uid->setText(uidstr);
QMessageBox::information(NULL, "提示", "写卡成功,卡片UID:"+uidstr);
}
else
{
if(status==45){
QString uidstr="";
for(int i=0;i<8;i++){
uidstr=uidstr+QString::asprintf("%02X", myuid[i]);
}
ui->lineEdit_uid->setText(uidstr);
QMessageBox::information(NULL, "提示", "每块字节数选错,卡片UID:"+uidstr);
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_search1_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char afi;
unsigned char maskuid[8]; //卡号掩码,一般可以不理这个参数
unsigned char masklen;
unsigned char uid[9];
ui->lineEdit_uid->setText("");
ui->lineEdit_flags->setText("36");
flags=54;
QString afistr=ui->lineEdit_afi->text().trimmed();
if(afistr.length()==2 and checkinput(afistr)){
bool ok;
afi=afistr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制AFI!");
return;
}
QString masklstr=ui->lineEdit_masklen->text().trimmed();
if(masklstr.length()==2 and checkinput(masklstr)){
bool ok;
masklen=masklstr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制掩码长度!");
return;
}
status = myiso15693inventory(flags, afi, masklen, maskuid, uid);
if(status==0){
mypcdbeep(30);
ui->lineEdit_dsfid->setText(QString::asprintf("%02X", uid[0]));
QString uidstr="";
for(int i=1;i<9;i++){
uidstr=uidstr+QString::asprintf("%02X", uid[i]);
}
ui->lineEdit_uid->setText(uidstr);
}else{
disperrinf(status);
}
}
void MainWindow::on_pb_searchall_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char afi;
unsigned char maskuid[8]; //卡号掩码,一般可以不理这个参数
unsigned char masklen;
unsigned char uid[9];
unsigned char revlen[1];
ui->lineEdit_uid->setText("");
ui->comboBox_uid->clear();
ui->lineEdit_flags->setText("16");
flags=22;
QString afistr=ui->lineEdit_afi->text().trimmed();
if(afistr.length()==2 and checkinput(afistr)){
bool ok;
afi=afistr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制AFI!");
ui->lineEdit_afi->setFocus();
return;
}
QString masklstr=ui->lineEdit_masklen->text().trimmed();
if(masklstr.length()==2 and checkinput(masklstr)){
bool ok;
masklen=masklstr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制掩码长度!");
return;
}
status = myiso15693inventory16(flags, afi, masklen, maskuid,revlen, uid);
if(status==0){
mypcdbeep(30);
ui->lineEdit_dsfid->setText(QString::asprintf("%02X", uid[0]));
QString uidstr="";
for(int i=1;i<9;i++){
uidstr=uidstr+QString::asprintf("%02X", uid[i]);
}
ui->lineEdit_uid->setText(uidstr);
// QStringList strlist;
int j=0;
while (j<revlen[0]){
QString cardinfstr="DSFID:"+QString::asprintf("%02X", uid[j])+",UID:";
for (int i=1;i<9;i++){
cardinfstr=cardinfstr+QString::asprintf("%02X", uid[j+i]);
}
// strlist.append(cardinfstr);
ui->comboBox_uid->addItem(cardinfstr);
j=j+9;
}
// model = new QStringListModel(strlist); //QStringListModel将QStringList包装了起来
// ui->listView->setModel(model); //填充到listview
// ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置item内容不可编辑
}else{
disperrinf(status);
}
}
void MainWindow::on_pb_quiet_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693stayquiet(flags, uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "操作成功,卡片已静止!");
}else{
if(status==40){
QMessageBox::critical(NULL, "提示","使卡进入静止(Quiet)状态失败!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_select_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693Select(flags, uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "操作成功,卡片已在选中状态!");
}else{
if(status==41){
QMessageBox::critical(NULL, "提示","使卡进入选中状态失败!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_restare_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693resettoready(flags, uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "操作成功,卡片已从静止中重起到准备状态!");
}else{
if(status==42){
QMessageBox::critical(NULL, "提示","让卡从静止中重起准备失败!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_afi_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char afi;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString afistr=ui->lineEdit_afi->text().trimmed();
if(afistr.length()==2 and checkinput(afistr)){
bool ok;
afi=afistr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制AFI!");
ui->lineEdit_afi->setFocus();
return;
}
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693writeafi(flags, afi,uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "写AIF操作成功!");
}else{
if(status==46){
QMessageBox::critical(NULL, "提示","写AIF操作失败!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_dsfid_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char dsfid;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString dsfidstr=ui->lineEdit_dsfid->text().trimmed();
if(dsfidstr.length()==2 and checkinput(dsfidstr)){
bool ok;
dsfid=dsfidstr.toInt(&ok,16);
}else{
QMessageBox::critical(NULL, "提示","请输入2位16进制dsfid!");
ui->lineEdit_dsfid->setFocus();
return;
}
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693writedsfid(flags, dsfid,uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "写DSFID操作成功!");
}else{
if(status==41){
QMessageBox::critical(NULL, "提示","写DSFID操作失败!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_systeminf_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char uid[8];
unsigned char revlen[1];
unsigned char revbuf[255];
ui->plainTextEdit_data->setPlainText("");
ui->lineEdit_flags->setText("22");
flags=34;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693readinfo(flags, uid,revlen,revbuf);
if(status==0){
mypcdbeep(30);
int j=0;
QString cardinfstr="";
while (j<revlen[0]){
cardinfstr=cardinfstr+QString::asprintf("%02X ", revbuf[j]);
j++;
}
ui->plainTextEdit_data->setPlainText(cardinfstr);
QMessageBox::information(NULL, "提示", "读取卡片系统信息成功!");
}else{
disperrinf(status);
}
}
void MainWindow::on_pb_secure_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char startblock;
unsigned char blocknum;
unsigned char uid[8];
unsigned char revlen[1];
unsigned char revbuf[255];
ui->plainTextEdit_data->setPlainText("");
ui->lineEdit_flags->setText("22");
flags=34;
startblock=ui->spinBox_star->value();
blocknum=ui->spinBox_num->value();
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693readsecuritystate(flags, startblock,blocknum,uid,revlen,revbuf);
if(status==0){
mypcdbeep(30);
int j=0;
QString cardinfstr="";
while (j<revlen[0]){
cardinfstr=cardinfstr+QString::asprintf("%02X ", revbuf[j]);
j++;
}
ui->plainTextEdit_data->setPlainText(cardinfstr);
QMessageBox::information(NULL, "提示", "读取卡片系统信息成功!");
}else{
disperrinf(status);
}
}
void MainWindow::on_pb_lockafi_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
int answ=QMessageBox::question (this, "警告", "你确定要锁定卡片的AFI吗 ?锁定后不可以再次修改!", QMessageBox::Ok, QMessageBox::Cancel);
if (answ ==1024){
unsigned char status;
unsigned char flags;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693lockafi(flags, uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "锁AFI操作成功!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_lockdsfid_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
int answ=QMessageBox::question (this, "警告", "你确定要锁定卡片的DSFID吗 ?锁定后不可以再次修改!", QMessageBox::Ok, QMessageBox::Cancel);
if (answ ==1024){
unsigned char status;
unsigned char flags;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693lockdsfid(flags, uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "数据存储格式标识DSFID锁定成功!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_lockdata_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
int answ=QMessageBox::question (this, "警告", "你确定要锁定卡片的数据块吗 ?锁定后不可以再次修改!", QMessageBox::Ok, QMessageBox::Cancel);
if (answ ==1024){
unsigned char status;
unsigned char flags;
unsigned char startblock;
unsigned char uid[8];
ui->lineEdit_flags->setText("22");
flags=34;
startblock=ui->spinBox_star->value();
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
status = myiso15693lockblock(flags,startblock, uid);
if(status==0){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "数据块锁定成功!");
}else{
disperrinf(status);
}
}
}
void MainWindow::on_pb_read_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char startblock;
unsigned char blocknum;
unsigned char uid[8];
unsigned char revlen[1];
unsigned char revbuf[255];
ui->plainTextEdit_data->setPlainText("");
ui->lineEdit_flags->setText("22");
flags=34;
startblock=ui->spinBox_star->value();
blocknum=startblock+ui->spinBox_num->value();
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
QString blockdata="";
while (startblock<blocknum){
status = myiso15693readblock(flags, startblock, 1, uid, revlen, revbuf);
if(status==0){
int j=0;
while(j<revlen[0]){
blockdata=blockdata+QString::asprintf("%02X ", revbuf[j]);
j++;
}
startblock++;
}else{
blocknum=startblock-1;
}
}
if(startblock==blocknum){
mypcdbeep(30);
ui->plainTextEdit_data->setPlainText(blockdata);
QMessageBox::information(NULL, "提示", "读卡成功,卡片UID:"+uidstr);
}else{
QMessageBox::critical(NULL, "提示",QString::asprintf("在读取第 :%d", startblock)+",块时返回错误代码:"+QString::asprintf("%d", status));
}
}
void MainWindow::on_pb_write_clicked()
{
if(!checkdllos()){return;} //判断运行目录内动态库文件是否存在
unsigned char status;
unsigned char flags;
unsigned char eachblocksize;
unsigned char startblock;
unsigned char blocknum;
unsigned char uid[8];
unsigned char writebuf[2000];
int writelen;
ui->lineEdit_flags->setText("22");
flags=34;
startblock=ui->spinBox_star->value();
blocknum=startblock+ui->spinBox_num->value();
switch(ui->comboBox_cardtype->currentIndex()){
case 0:
eachblocksize=4;
break;
case 1:
eachblocksize=8;
break;
default:
eachblocksize=32;
break;
}
writelen=blocknum*eachblocksize;
QString uidstr=ui->lineEdit_uid->text().trimmed();
if(uidstr.length()==16 and checkinput(uidstr)){
bool ok;
for(int i=0;i<8;i++){
uid[i]=QString(uidstr.mid(i*2,2)).toInt(&ok,16);
}
}else{
QMessageBox::critical(NULL, "提示","请先寻找卡片或输入16位16进制UID!");
ui->lineEdit_uid->setFocus();
return;
}
for(int i=0;i<2000;i++){writebuf[i]=0x00;}
//检测写卡数据
QChar ch;
QString writinf = ui->plainTextEdit_data->toPlainText().trimmed();
QString writinf1 = "";
int m = 0;
int n = 0;
char s;
if(writinf.length()<1){
QMessageBox::critical(NULL, "提示", "请输入正确的16进制写卡数据!");
ui->plainTextEdit_data->setFocus();
return;
}
ch = writinf.at(0);
s = writinf.at(0).toLatin1();
for(int i=0; i<writinf.length() ; i++)
{
ch = writinf.at(i);
s = writinf.at(i).toLatin1();
if((('0' <= s) && (s <= '9')) || (('A' <= s) && (s <= 'F')) || (('a' <= s) && (s <= 'f')))
{
writinf1 += ch;
n++;
if(n==2){
bool ok;
writebuf[m++] = writinf1.toInt(&ok,16);
writinf1 = "";
n = 0;
}
}
else if(s == ' '){
}
else
{
QMessageBox::critical(NULL, "提示", "写卡数据错误,请输入正确的16进制数据!");
ui->plainTextEdit_data->setFocus();
return;
}
}
int i=0;
while (startblock<blocknum){
unsigned char wbuf[eachblocksize];
for(int j=0;j<eachblocksize;j++){
wbuf[j]=writebuf[i+j];
}
status = myiso15693writeblock(flags, startblock, 1, uid, eachblocksize, wbuf);
if(status==0){
startblock=startblock+1;
i=i+eachblocksize;
}else{
blocknum=startblock-1;
}
}
if(startblock==blocknum){
mypcdbeep(30);
QMessageBox::information(NULL, "提示", "写卡成功,卡片UID:"+uidstr);
}else{
QMessageBox::critical(NULL, "提示",QString::asprintf("在写第 :%d", startblock)+",块时返回错误代码:"+QString::asprintf("%d", status));
}
}