Qt_C++读写FM1208 CPU卡源码、支持windows、Linux系统

2023-11-02 16:40

本文主要是介绍Qt_C++读写FM1208 CPU卡源码、支持windows、Linux系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本示例使用的发卡器: Android Linux RFID读写器NFC发卡器WEB可编程NDEF文本/智能海报/-淘宝网 (taobao.com)

#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QDebug>
#include "QLibrary"
#include "QMessageBox"//电话、微信:13822155058
//QQ:954486673//本示例可在windows、linux系统内编译、运行
//判断windows、linux系统,声明动态库函数----------------------------------------------------------------------------------------------------------------------------------------------
//让读写器发出声音
typedef  unsigned char (*pcdbeep)(unsigned long xms);
#ifdef Q_OS_WINpcdbeep mypcdbeep = (pcdbeep)QLibrary("OUR_MIFARE.dll").resolve("pcdbeep");
#elsepcdbeep mypcdbeep = (pcdbeep)QLibrary("./libOURMIFARE.so").resolve("pcdbeep");
#endif//返回本读写器独一无二的设备编号
typedef  unsigned char (*pcdgetdevicenumber)(unsigned char *devicenumber);
#ifdef Q_OS_WINpcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("OUR_MIFARE.dll").resolve("pcdgetdevicenumber");
#elsepcdgetdevicenumber mypcdgetdevicenumber = (pcdgetdevicenumber)QLibrary("./libOURMIFARE.so").resolve("pcdgetdevicenumber");
#endif//CPU卡寻卡及将卡复位到14443A-4的指令状态
typedef  unsigned char (*cpurequest)(unsigned char *serial,unsigned char *param,unsigned char *cosver,unsigned char *code);
#ifdef Q_OS_WINcpurequest mycpurequest = (cpurequest)QLibrary("OUR_MIFARE.dll").resolve("cpurequest");
#elsecpurequest mycpurequest = (cpurequest)QLibrary("./libOURMIFARE.so").resolve("cpurequest");
#endif//cpu卡初始化函数,(ctrlword是否需要先清空卡,不需要清空的话,可以需输入卡密码,卡密码长度)ctrlword_0是否先清空卡,分配空间(字节数)
typedef  unsigned char (*cpursinit)(unsigned char ctrlword,unsigned char *key,unsigned char *keylen,int customsize);
#ifdef Q_OS_WINcpursinit mycpursinit = (cpursinit)QLibrary("OUR_MIFARE.dll").resolve("cpursinit");
#elsecpursinit mycpursinit = (cpursinit)QLibrary("./libOURMIFARE.so").resolve("cpursinit");
#endif//增加易写文件(文件序号0~5,文件只读密码:长度,文件读写密码,长度,分配空间)
typedef  unsigned char (*cpursfileadd_s)(unsigned char fileno,unsigned char *readonlykey,unsigned char *readonlykeylen,unsigned char *writekey,unsigned char *writekeylen,int customsize);
#ifdef Q_OS_WINcpursfileadd_s mycpursfileadd_s = (cpursfileadd_s)QLibrary("OUR_MIFARE.dll").resolve("cpursfileadd_s");
#elsecpursfileadd_s mycpursfileadd_s = (cpursfileadd_s)QLibrary("./libOURMIFARE.so").resolve("cpursfileadd_s");
#endif//增加标准文件(文件序号0~5,文件只读密码:长度,文件读写密码,长度,分配空间)
typedef  unsigned char (*cpursfileadd)(unsigned char fileno,unsigned char *readonlykey,unsigned char *readonlykeylen,unsigned char *writekey,unsigned char *writekeylen,int customsize);
#ifdef Q_OS_WINcpursfileadd mycpursfileadd = (cpursfileadd)QLibrary("OUR_MIFARE.dll").resolve("cpursfileadd");
#elsecpursfileadd mycpursfileadd = (cpursfileadd)QLibrary("./libOURMIFARE.so").resolve("cpursfileadd");
#endif//修改文件密码,修改后,请妥慎记住,否则该文件将无法再用
typedef  unsigned char (*cpursfilekeychg)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,unsigned char *newkey,unsigned char *newkeylen);
#ifdef Q_OS_WINcpursfilekeychg mycpursfilekeychg = (cpursfilekeychg)QLibrary("OUR_MIFARE.dll").resolve("cpursfilekeychg");
#elsecpursfilekeychg mycpursfilekeychg = (cpursfilekeychg)QLibrary("./libOURMIFARE.so").resolve("cpursfilekeychg");
#endif//读文件数据(文件序号,读写密码,密码长度,读取起始位置,读取长度,读出内容)
typedef  unsigned char (*cpursfiledataread)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,int startaddr,unsigned char *databuf,int datalen);
#ifdef Q_OS_WINcpursfiledataread mycpursfiledataread = (cpursfiledataread)QLibrary("OUR_MIFARE.dll").resolve("cpursfiledataread");
#elsecpursfiledataread mycpursfiledataread = (cpursfiledataread)QLibrary("./libOURMIFARE.so").resolve("cpursfiledataread");
#endif//写普通文件数据(文件序号,写密码,密码长度,写起始位置,写长度,写入内容)
typedef  unsigned char (*cpursfiledatawrite)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,int startaddr,unsigned char *databuf,int datalen);
#ifdef Q_OS_WINcpursfiledatawrite mycpursfiledatawrite = (cpursfiledatawrite)QLibrary("OUR_MIFARE.dll").resolve("cpursfiledatawrite");
#elsecpursfiledatawrite mycpursfiledatawrite = (cpursfiledatawrite)QLibrary("./libOURMIFARE.so").resolve("cpursfiledatawrite");
#endif//写易写文件数据(文件序号,写密码,密码长度,写起始位置,写长度,写入内容)
typedef  unsigned char (*cpursfiledatawrite_s)(unsigned char fileno,unsigned char ctrword,unsigned char *oldkey,unsigned char *oldkeylen,int startaddr,unsigned char *databuf,int datalen);
#ifdef Q_OS_WINcpursfiledatawrite_s mycpursfiledatawrite_s = (cpursfiledatawrite_s)QLibrary("OUR_MIFARE.dll").resolve("cpursfiledatawrite_s");
#elsecpursfiledatawrite_s mycpursfiledatawrite_s = (cpursfiledatawrite_s)QLibrary("./libOURMIFARE.so").resolve("cpursfiledatawrite_s");
#endif//强制清空卡,用cpursinit函数成功初始化过后,如果卡密码丢去了,可以尝试用以下的强制清空卡函数清空卡至出厂状态
typedef  unsigned char (*cpurscardclr)();
#ifdef Q_OS_WINcpurscardclr mycpurscardclr = (cpurscardclr)QLibrary("OUR_MIFARE.dll").resolve("cpurscardclr");
#elsecpurscardclr mycpurscardclr = (cpurscardclr)QLibrary("./libOURMIFARE.so").resolve("cpurscardclr");
#endif//修改卡密码,卡密码和文件没有任何关系,卡密码只是用来清空卡,读和写文件是无效的。
typedef  unsigned char (*cpurscardkeychg)(unsigned char *oldkey,unsigned char *oldkeylen,unsigned char *newkey,unsigned char *newkeylen);
#ifdef Q_OS_WINcpurscardkeychg mycpurscardkeychg = (cpurscardkeychg)QLibrary("OUR_MIFARE.dll").resolve("cpurscardkeychg");
#elsecpurscardkeychg mycpurscardkeychg = (cpurscardkeychg)QLibrary("./libOURMIFARE.so").resolve("cpurscardkeychg");
#endifconst unsigned char NEWKEYR = 0x00;   //'更改只读密码
const unsigned char NEWKEYWR = 0x01;  //'更改读写密码
const unsigned char OLDKEYR = 0x00;   //'用只读密码认证
const unsigned char OLDKEYWR = 0x02;  //'用读写密码认证//检测输入数据是否为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;
}//检测输入数据是否为16进制数,将正确的16进制字符存入数组,并返回长度------------------------------------------------------------------------------------------------------------------------------------------------------------
static int checkhexdata(QString inputstr,unsigned char *databuf){QChar ch;QString writinf = inputstr.trimmed();QString writinf1 = "";int m = 0;int n = 0;char s;if(writinf.length()<1){return -1;}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;databuf[m++] = writinf1.toInt(&ok,16);writinf1 = "";n = 0;}}else if(s == ' '){}}return m;
}//检测动态库文件是否在运行目录内----------------------------------------------------------------------------------------------------------------------------------------------------------
static bool checkdllos(){
#ifdef Q_OS_WINQLibrary mylib("OUR_MIFARE.dll");if (!mylib.load()){                //判断windows系统下,OUR_MIFARE.dll是否在运行目录内QMessageBox::information(NULL, "提示", "请将OUR_MIFARE.dll文件拷贝到生成exe文件相同目录下!");return false;}else{return true;}
#elseQLibrary mylib("./libOURMIFARE.so");if (!mylib.load()){                //判断linux系统下,libOURMIFARE.so是否正运行目录内QMessageBox::information(NULL, "提示", "请将libOURMIFARE.so文件拷贝到生成的运行文件相同目录下!");return false;}else{return true;}
#endif
}//显示返回的错误代码信息-----------------------------------------------------------------------------------------------------------------------------------------------------------------
static void disperrinf(unsigned char result){switch (result) {case 8:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",未寻到卡,请重新拿开卡后再放到感应区!");break;case 50:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",RATS错误,厂家调试代码,用户不需理会!");break;case 51:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",PPS错误,厂家调试代码,用户不需理会!");break;case 52:QMessageBox::information(NULL, "提示", QString::asprintf("代码:%d", result)+",已进入了14443-4协议状态,可进行CPU卡功能所有操作了!");break;case 53:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",CPU卡功能通讯错误!");break;case 54:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",数据不足,需要接着发送未完成的数据至卡上!");break;case 55:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",发送ACK指令给卡,让卡接着发送数据回来!");break;case 56:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",清空根目录失败!");break;case 57:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",卡片不支持此功能!");break;case 58:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",卡片初始化失败!");break;case 59:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",分配的空间不足!");break;case 60:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",本次操作的实体已存在!");break;case 61:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",无足够空间!");break;case 62:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",文件不存在!");break;case 63:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",权限不足,有可能是用只读密码认证,导致无法更改读写密码或无法写文件!");break;case 64:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",密码不存在,或密钥文件未创建!");break;case 65:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",传送长度错误!");break;case 66:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",Le错误,即接收的数据长度指定过大!");break;case 67:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",功能不支持或卡中无MF 或卡片已锁定!");break;case 68:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",密码认证错识次数过多,该密码已被锁死!");break;case 70:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:case 79:case 80:case 81:case 82:case 83:case 84:case 85:QMessageBox::critical(NULL, "提示", QString::asprintf("密码错误,剩余次数为:%d", result-70)+",如果为0,该密码将锁死,无法再认证!");break;case 86:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",更改后的密码长度必须和创建时的长度一致!");break;case 87:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",应用目录不存在!");break;case 88:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",应用文件不存在!");break;case 89:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",文件号不能超过5!");break;case 90:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",读取文件时返回的长度不足,数据可能不正确!");break;case 91:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",一次读文件的长度不能超过255!");break;case 92:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",一次写文件的长度不能超过247!");break;default:QMessageBox::critical(NULL, "提示", QString::asprintf("错误代码:%d", result)+",未知的错误信息!");break;}
}MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);QPalette pa;pa.setColor(QPalette::WindowText,QColor(255, 0, 0));ui->label_7->setPalette(pa);ui->label_8->setPalette(pa);ui->label_9->setPalette(pa);ui->label_19->setPalette(pa);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_pb_beep_clicked()
{if(!checkdllos()){return;}      //判断运行目录内动态库文件是否存在unsigned char status;if (mypcdbeep != NULL){         //是否成功连接上 pcdbeep()函数status = mypcdbeep(30);if(status==0){}else{disperrinf(status);}} else{QMessageBox::critical(NULL, "提示", "函数‘pcdbeep’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_getdevnum_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char devicenumber[4];    //设备编号缓冲unsigned char status;             //函数返回状态if (mypcdgetdevicenumber != NULL){         //是否成功连接上 pcdgetdevicenumber()函数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);}}else{QMessageBox::critical(NULL, "提示", "函数‘pcdgetdevicenumber’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_request_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char mypiccserial[4];    //卡序列号unsigned char myparam[4];         //参数unsigned char myver[1];           //版本unsigned char mycode[1];          //厂商代码(复旦为90)unsigned char status;             //函数返回状态if (mycpurequest != NULL){        //是否成功连接上 cpurequest()函数status = mycpurequest(mypiccserial,myparam,myver,mycode);if(status==0  || status==52){mypcdbeep(30);QString uidstr=QString::asprintf("%02X%02X%02X%02X", mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3]);QString parstr=QString::asprintf("%02X%02X%02X%02X", myparam[0],myparam[1],myparam[2],myparam[3]);QString verstr=QString::asprintf("%02X", myver[0]);QString codestr=QString::asprintf("%02X", mycode[0]);ui->lineEdit_uid->setText(uidstr);QMessageBox::information(NULL, "提示", "卡号:"+uidstr+",参数:"+parstr+",版本号:"+verstr+",厂商代码:"+codestr+" 的CPU卡已激活进入14443-4协议模式,可以继续以下的功能操作!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpurequest’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_init_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char ctrlword;           //是否先清空卡unsigned char mylen[1];           //密钥长度unsigned char keybuf[20];         //密钥int keylen;int spacesize;                    //空间大小if(ui->checkBox_clear->isChecked()){ctrlword=1;}else{ctrlword=0;}QString writinf = ui->lineEdit_cardkey->text().trimmed();keylen=checkhexdata(writinf,keybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制卡密码!");ui->lineEdit_cardkey->setFocus();return;}mylen[0]=keylen;spacesize=ui->spinBox_maxsize->value();if (mycpursinit != NULL){        //是否成功连接上 cpursinit()函数status = mycpursinit(ctrlword,keybuf,mylen,spacesize);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "CPU卡初始化成功!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursinit’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_addeasyfile_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char fileno;             //文件号unsigned char readkeylen[1];      //只读密钥长度unsigned char readkeybuf[20];     //只读密钥unsigned char rwkeylen[1];        //读写密钥长度unsigned char rwkeybuf[20];       //读写密钥int keylen;int spacesize;                    //空间大小QString keystr;fileno=ui->comboBox_addfile->currentIndex(); //新增加的文件号keystr = ui->lineEdit_readkey->text().trimmed();keylen=checkhexdata(keystr,readkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件只读密码!");ui->lineEdit_readkey->setFocus();return;}readkeylen[0]=keylen;keystr = ui->lineEdit_rwkey->text().trimmed();keylen=checkhexdata(keystr,rwkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件读写密码!");ui->lineEdit_rwkey->setFocus();return;}rwkeylen[0]=keylen;spacesize=ui->spinBox_2->value();if (mycpursfileadd_s != NULL){        //是否成功连接上 cpursfileadd_s()函数status = mycpursfileadd_s(fileno,readkeybuf,readkeylen,rwkeybuf,rwkeylen,spacesize);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "CPU卡创建易写文件成功,需要使用易写函数写入文件数据!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursfileadd_s’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_addfile_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char fileno;             //文件号unsigned char readkeylen[1];      //只读密钥长度unsigned char readkeybuf[20];     //只读密钥unsigned char rwkeylen[1];        //读写密钥长度unsigned char rwkeybuf[20];       //读写密钥int keylen;int spacesize;                    //空间大小QString keystr;fileno=ui->comboBox_addfile->currentIndex();  //新增加的文件号keystr = ui->lineEdit_readkey->text().trimmed();keylen=checkhexdata(keystr,readkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件只读密码!");ui->lineEdit_readkey->setFocus();return;}readkeylen[0]=keylen;keystr = ui->lineEdit_rwkey->text().trimmed();keylen=checkhexdata(keystr,rwkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件读写密码!");ui->lineEdit_rwkey->setFocus();return;}rwkeylen[0]=keylen;spacesize=ui->spinBox_2->value();if (mycpursfileadd != NULL){        //是否成功连接上 cpursfileadd()函数status = mycpursfileadd(fileno,readkeybuf,readkeylen,rwkeybuf,rwkeylen,spacesize);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "CPU卡创建标准文件成功,需使用写标准文件函数写入数据!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursfileadd’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_changkey_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char fileno;             //文件号unsigned char ctrlword;           //控制字unsigned char oldkeylen[1];       //旧密钥长度unsigned char oldkeybuf[20];      //旧密钥unsigned char newkeylen[1];       //新密钥长度unsigned char newkeybuf[20];      //新密钥int keylen;QString keystr;fileno=ui->comboBox_changekeyfile->currentIndex();  //要更改密钥的文件号if(ui->comboBox_changekey->currentIndex()==0){ctrlword=NEWKEYR;       //更改只读密码}else{ctrlword=NEWKEYWR;}   //更改读写密码if(ui->comboBox_authkey->currentIndex()==0){ctrlword=ctrlword+OLDKEYR;      //用只读密码来认证}else{ctrlword=ctrlword+OLDKEYWR;}  //用读写密码来认证keystr = ui->lineEdit_authkey->text().trimmed();keylen=checkhexdata(keystr,oldkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");ui->lineEdit_authkey->setFocus();return;}oldkeylen[0]=keylen;keystr = ui->lineEdit_newkey->text().trimmed();keylen=checkhexdata(keystr,newkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件新密码!");ui->lineEdit_newkey->setFocus();return;}newkeylen[0]=keylen;if (mycpursfilekeychg != NULL){        //是否成功连接上 cpursfilekeychg()函数status = mycpursfilekeychg(fileno,ctrlword,oldkeybuf,oldkeylen,newkeybuf,newkeylen);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "修改文件密码成功");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursfilekeychg’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_read_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char fileno;             //文件号unsigned char ctrlword;           //控制字unsigned char oldkeylen[1];       //旧密钥长度unsigned char oldkeybuf[20];      //旧密钥int staradd;                      //读写起始地址int datalen;                      //读写长度unsigned char rwbuf[8000];        //读写数据缓冲int keylen;QString keystr;fileno=ui->comboBox_rwfile->currentIndex();  //要读写的文件号staradd=ui->spinBox_rwbegin->value();        //读写起始地址datalen=ui->spinBox_rwlen->value();          //读写数据长度if(datalen<1 || datalen>255){QMessageBox::critical(NULL, "提示", "每次读卡最多255字节,请输入正确的读卡长度!");ui->spinBox_rwlen->setFocus();return;}if(ui->comboBox_authrwkey->currentIndex()==0){ctrlword=OLDKEYR;      //用只读密码来认证}else{ctrlword=OLDKEYWR;}  //用读写密码来认证keystr = ui->lineEdit_authkey2->text().trimmed();keylen=checkhexdata(keystr,oldkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");ui->lineEdit_authkey2->setFocus();return;}oldkeylen[0]=keylen;if (mycpursfiledataread != NULL){        //是否成功连接上 cpursfiledataread()函数status = mycpursfiledataread(fileno,ctrlword,oldkeybuf,oldkeylen,staradd,rwbuf,datalen);if(status==0 ){mypcdbeep(30);QString datastr="";for(int i=0;i<datalen;i++){datastr=datastr+QString::asprintf("%02X ", rwbuf[i]);}ui->plainTextEdit->setPlainText(datastr);QMessageBox::information(NULL, "提示", "读取数据成功!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursfiledataread’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_write_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char fileno;             //文件号unsigned char ctrlword;           //控制字unsigned char oldkeylen[1];       //旧密钥长度unsigned char oldkeybuf[20];      //旧密钥int staradd;                      //读写起始地址int datalen;                      //读写长度unsigned char rwbuf[8000];        //读写数据缓冲int keylen;QString keystr;QString datastr;keystr = ui->lineEdit_authkey2->text().trimmed();keylen=checkhexdata(keystr,oldkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");ui->lineEdit_authkey2->setFocus();return;}oldkeylen[0]=keylen;datastr = ui->plainTextEdit->toPlainText().trimmed();datalen=checkhexdata(datastr,rwbuf);if(datalen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制写入数据!");ui->plainTextEdit->setFocus();return;}fileno=ui->comboBox_rwfile->currentIndex();  //要读写的文件号staradd=ui->spinBox_rwbegin->value();        //读写起始地址datalen=ui->spinBox_rwlen->value();          //读写数据长度if(datalen<1 || datalen>247){QMessageBox::critical(NULL, "提示", "每次写卡最多247字节,请输入正确的写卡长度!");ui->spinBox_rwlen->setFocus();return;}if(ui->comboBox_authrwkey->currentIndex()==0){ctrlword=OLDKEYR;      //用只读密码来认证}else{ctrlword=OLDKEYWR;}  //用读写密码来认证if (mycpursfiledatawrite != NULL){        //是否成功连接上 cpursfiledatawrite()函数status = mycpursfiledatawrite(fileno,ctrlword,oldkeybuf,oldkeylen,staradd,rwbuf,datalen);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "写入数据成功!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursfiledatawrite’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_easy_write_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char fileno;             //文件号unsigned char ctrlword;           //控制字unsigned char oldkeylen[1];       //旧密钥长度unsigned char oldkeybuf[20];      //旧密钥int staradd;                      //读写起始地址int datalen;                      //读写长度unsigned char rwbuf[8000];        //读写数据缓冲int keylen;QString keystr;QString datastr;keystr = ui->lineEdit_authkey2->text().trimmed();keylen=checkhexdata(keystr,oldkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制文件认证密码!");ui->lineEdit_authkey2->setFocus();return;}oldkeylen[0]=keylen;datastr = ui->plainTextEdit->toPlainText().trimmed();datalen=checkhexdata(datastr,rwbuf);if(datalen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制写入数据!");ui->plainTextEdit->setFocus();return;}fileno=ui->comboBox_rwfile->currentIndex();  //要读写的文件号staradd=ui->spinBox_rwbegin->value();        //读写起始地址datalen=ui->spinBox_rwlen->value();          //读写数据长度if(ui->comboBox_authrwkey->currentIndex()==0){ctrlword=OLDKEYR;      //用只读密码来认证}else{ctrlword=OLDKEYWR;}  //用读写密码来认证if (mycpursfiledatawrite_s != NULL){        //是否成功连接上 cpursfiledatawrite_s()函数status = mycpursfiledatawrite_s(fileno,ctrlword,oldkeybuf,oldkeylen,staradd,rwbuf,datalen);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "写入数据成功!");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpursfiledatawrite_s’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_clear_clicked()
{if(!checkdllos()){return;}      //判断运行目录内动态库文件是否存在unsigned char status;if (mycpurscardclr != NULL){         //是否成功连接上 cpurscardclr()函数status = mycpurscardclr();if(status==0){mypcdbeep(30);QMessageBox::information(NULL, "提示", "cpu卡强制清空卡成功");}else{if(status==64){QMessageBox::information(NULL, "提示", "此卡为未经过我们cpursinit函数成功初始化的卡");}else{disperrinf(status);}}} else{QMessageBox::critical(NULL, "提示", "函数‘cpurscardclr’未正确载入,请查询DLL文件版本是否正确!");}
}void MainWindow::on_pb_changecardkey_clicked()
{if(!checkdllos()){return;}        //判断运行目录内动态库文件是否存在unsigned char status;             //函数返回状态unsigned char oldkeylen[1];       //旧密钥长度unsigned char oldkeybuf[20];      //旧密钥unsigned char newkeylen[1];       //新密钥长度unsigned char newkeybuf[20];      //新密钥int keylen;QString keystr;keystr = ui->lineEdit_cardoldkey->text().trimmed();keylen=checkhexdata(keystr,oldkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制卡旧密码!");ui->lineEdit_cardoldkey->setFocus();return;}oldkeylen[0]=keylen;keystr = ui->lineEdit_cardnewkey->text().trimmed();keylen=checkhexdata(keystr,newkeybuf);if(keylen<0){QMessageBox::critical(NULL, "提示", "请输入正确的16进制卡新密码!");ui->lineEdit_cardnewkey->setFocus();return;}newkeylen[0]=keylen;if (mycpurscardkeychg != NULL){        //是否成功连接上 cpurscardkeychg()函数status = mycpurscardkeychg(oldkeybuf,oldkeylen,newkeybuf,newkeylen);if(status==0 ){mypcdbeep(30);QMessageBox::information(NULL, "提示", "修改卡片密码成功");}else{disperrinf(status);}}else{QMessageBox::critical(NULL, "提示", "函数‘cpurscardkeychg’未正确载入,请查询DLL文件版本是否正确!");}
}

这篇关于Qt_C++读写FM1208 CPU卡源码、支持windows、Linux系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

水位雨量在线监测系统概述及应用介绍

在当今社会,随着科技的飞速发展,各种智能监测系统已成为保障公共安全、促进资源管理和环境保护的重要工具。其中,水位雨量在线监测系统作为自然灾害预警、水资源管理及水利工程运行的关键技术,其重要性不言而喻。 一、水位雨量在线监测系统的基本原理 水位雨量在线监测系统主要由数据采集单元、数据传输网络、数据处理中心及用户终端四大部分构成,形成了一个完整的闭环系统。 数据采集单元:这是系统的“眼睛”,

10. 文件的读写

10.1 文本文件 操作文件三大类: ofstream:写操作ifstream:读操作fstream:读写操作 打开方式解释ios::in为了读文件而打开文件ios::out为了写文件而打开文件,如果当前文件存在则清空当前文件在写入ios::app追加方式写文件ios::trunc如果文件存在先删除,在创建ios::ate打开文件之后令读写位置移至文件尾端ios::binary二进制方式

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

【C++ Primer Plus习题】13.4

大家好,这里是国中之林! ❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看← 问题: 解答: main.cpp #include <iostream>#include "port.h"int main() {Port p1;Port p2("Abc", "Bcc", 30);std::cout <<

C++包装器

包装器 在 C++ 中,“包装器”通常指的是一种设计模式或编程技巧,用于封装其他代码或对象,使其更易于使用、管理或扩展。包装器的概念在编程中非常普遍,可以用于函数、类、库等多个方面。下面是几个常见的 “包装器” 类型: 1. 函数包装器 函数包装器用于封装一个或多个函数,使其接口更统一或更便于调用。例如,std::function 是一个通用的函数包装器,它可以存储任意可调用对象(函数、函数

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�