本示例使用的发卡器:https://item.taobao.com/item.htm?id=615391857885&spm=a1z10.5-c.w4002-21818769070.11.60ad789erlonvk
近场通信(Near Field Communication,简称NFC),是一种新兴的技术,使用了NFC技术的设备(例如移动电话)可以在彼此靠近的情况下进行数据交换,是由非接触式射频识别(RFID)及互连互通技术整合演变而来的,通过在单一芯片上集成感应式读卡器、感应式卡片和点对点通信的功能,利用移动终端实现移动支付、电子票务、门禁、移动身份识别、防伪等应用。近场通信技术是由诺基亚(Nokia)、飞利浦(Philips)和索尼(Sony)共同制定的标准 ,在ISO 18092、ECMA 340和ETSI TS 102 190框架下推动标准化,同时也兼容应用广泛的ISO 14443 、Type-A、ISO 15693、B以及Felica标准非接触式智能卡 的基础架构。
NDEF 全称 NFC data exchange format 即 nfc 数据交换格式,是一种标准化的数据格式,可用于在任何兼容的NFC设备与另一个NFC设备或标签之间交换信息。数据格式由NDEF消息和NDEF记录组成 。
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget,QMessageBox
from PyQt5.QtGui import QFont
from NDEFTagTools import Ui_Frame
import sys
import struct # struct的pack函数把任意数据类型变成字符串
import ctypes # 调用DLL动态库要有这个引用
#'为防止测试时忘记卡片密码,本系统统一使用密码为 197402020111 ,MifareClassic的密码6字节 ,forumtype2标签的密码是前4个字节,密码为 19740202
oldpicckey = bytes.fromhex('197402020111')
newpicckey = bytes.fromhex('197402020111')
class MainWindow(QtWidgets.QMainWindow, Ui_Frame):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.pushButton_clearinf.clicked.connect(self.pushButton_clearinf_clicked)
self.pushButton_beep.clicked.connect(self.pushButton_beep_clicked)
self.pushButton_getdevnum.clicked.connect(self.pushButton_getdevnum_clicked)
self.pushButton_clearbuff.clicked.connect(self.pushButton_clearbuff_clicked)
self.pushButton_writetag.clicked.connect(self.pushButton_writetag_clicked)
self.comboBox_seleapp.currentTextChanged.connect(self.comboBox_seleapp_currentindexchanged)
self.pushButton_text.clicked.connect(self.pushButton_text_clicked)
self.pushButton_App.clicked.connect(self.pushButton_App_clicked)
self.pushButton_Url.clicked.connect(self.pushButton_Url_clicked)
self.pushButton_Map.clicked.connect(self.pushButton_Map_clicked)
self.pushButton_Bluetooth.clicked.connect(self.pushButton_Bluetooth_clicked)
self.pushButton_Wifi.clicked.connect(self.pushButton_Wifi_clicked)
self.pushButton_Card.clicked.connect(self.pushButton_Card_clicked)
self.pushButton_Data.clicked.connect(self.pushButton_Data_clicked)
self.pushButton_Call.clicked.connect(self.pushButton_Call_clicked)
self.pushButton_readtag.clicked.connect(self.pushButton_readtag_clicked)
self.pushButton_cleatag.clicked.connect(self.pushButton_cleatag_clicked)
self.checkBox_later.toggled.connect(self.checkBox_later_toggled)
def pushButton_clearinf_clicked(self):
self.listWidget.clear()
self.plainTextEdit_taginf.setPlainText('')
def checkBox_later_toggled(self):
if self.checkBox_later.isChecked():
answ=QMessageBox.warning(self,'警告',' ISO15693协议标签锁定保护后就不能再解锁修改!请问确定要开启锁定保护功能吗?',QMessageBox.Yes|QMessageBox.No)
if answ==QMessageBox.No:
self.checkBox_later.setChecked(False)
def ListErrInf(self,Errcode):
if (Errcode == 8):
self.ListBottom('错误代码:8,未寻到卡,请重新拿开卡后再放到感应区!')
elif (Errcode == 1):
self.ListBottom('错误代码:1,0~2块都没读出来,可能刷卡太块。但卡序列号已被读出来!')
elif (Errcode == 2):
self.ListBottom('错误代码:2,第0块已被读出,但1~2块读取失败。卡序列号已被读出来!')
elif (Errcode == 3):
self.ListBottom('错误代码:3,第0、1块已被读出,但2块读取失败。卡序列号已被读出来!')
elif (Errcode == 9):
self.ListBottom('错误代码:9,有多张卡在感应区,寻卡过程中防冲突失败,读序列吗错误!')
elif (Errcode == 10):
self.ListBottom('错误代码:10,该卡可能已被休眠,无法选中卡片!')
elif (Errcode == 11):
self.ListBottom('错误代码:11,密码装载失败!')
elif (Errcode == 12):
self.ListBottom('错误代码:12,标签密码认证错误!')
elif (Errcode == 13):
self.ListBottom('错误代码:13,读指定块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!')
elif (Errcode == 14):
self.ListBottom('错误代码:14,写标签失败,可能需要验证密码!')
elif (Errcode == 21):
self.ListBottom('错误代码:21,没有动态库!')
elif (Errcode == 22):
self.ListBottom('错误代码:22,动态库或驱动程序异常!')
elif (Errcode == 23):
self.ListBottom('错误代码:23,(表示未检测到免驱动读写器!)(有驱动读写器表示驱动程序错误或未检测到有驱读写器!)')
elif (Errcode == 24):
self.ListBottom('错误代码:24,操作超时,一般是动态库没有反映!')
elif (Errcode == 25):
self.ListBottom('错误代码:25,发送字数不够!')
elif (Errcode == 26):
self.ListBottom('错误代码:26,发送的CRC错!')
elif (Errcode == 27):
self.ListBottom('错误代码:27,接收的字数不够!')
elif (Errcode == 28):
self.ListBottom('错误代码:28,接收的CRC错!')
elif (Errcode == 45):
self.ListBottom('错误代码:45,此卡不支持更改UID号或UID块已被锁定!')
elif (Errcode == 46):
self.ListBottom('错误代码:46,标签存储空间不足!')
elif (Errcode == 254):
self.ListBottom('错误代码:254,标签存储空间不足!')
elif (Errcode == 255):
self.ListBottom('错误代码:255,暂不支持长度大于255字节的信息写入!')
else:
self.ListBottom('未知错误,错误代码:' + str(Errcode))
def comboBox_seleapp_currentindexchanged(self):
packstr=self.comboBox_seleapp.currentText().strip()
FieldsList = packstr.split('|')
self.lineEdit_appname.setText(FieldsList[1])
def ListBottom(self,dispinf):
if self.listWidget.count()>50:
self.listWidget.clear()
self.listWidget.addItem(dispinf)
self.listWidget.scrollToBottom()
seleid = self.listWidget.count() - 1
self.listWidget.item(seleid).setSelected(True)
def pushButton_beep_clicked(self):
status = Objdll.pcdbeep(50) % 256
if status == 0:
self.ListBottom("读写器已执行响声指令!")
else:
self.ListErrInf(status)
def pushButton_getdevnum_clicked(self):
devno = bytes(4) # 声明4个字节缓冲
status = Objdll.pcdgetdevicenumber(devno) % 256
if (status == 0):
Objdll.pcdbeep(38)
SerialNum = ''
for num in range(0, len(devno)):
SerialNum = SerialNum + '%03d' % (devno[num])
if (num < len(devno) - 1):
SerialNum = SerialNum + '-'
self.ListBottom('读取设备编号成功,设备编号:' + SerialNum)
else:
self.ListErrInf(status)
def pushButton_clearbuff_clicked(self):
Objdll.tagbuf_forumtype4_clear()
Objdll.tagbuf_clear()
self.ListBottom('NDEF写卡缓冲区数据清除成功!' )
def checkcardtype(self): #检测NFC标签类型
myctrlword=0
devno = bytes(4) # 声明4个字节缓冲
mypiccserial= bytes(8) # 声明8个字节缓冲
mypicckey=bytes(6) # 声明6个字节缓冲
mypicdata=bytes(48)
mypiccseriallen=bytes(2)
try:
status = Objdll.pcdgetdevicenumber(devno) % 256
if (status == 0):
status = Objdll.piccreadex_ntag(myctrlword, mypiccserial, mypicckey, 4, 1, mypicdata) % 256
if (status == 0):
return 1 #forumtype2 Ntag2标签
else:
status = Objdll.iso15693readex(myctrlword,0,1,1, mypiccserial,mypicdata) % 256
if (status == 0):
return 2 #forumtype5 15693标签
else:
myctrlword = 23
mypicckey=bytes([255,255,255,255,255,255])
status = Objdll.piccreadex(myctrlword,mypiccserial,0,1,mypicckey,mypicdata) % 256
if (status == 0):
return 3 #MifareClissic标签,出厂全新状态
else:
mypicckey = bytes([160, 161, 162, 163, 164, 165])
status = Objdll.piccreadex(myctrlword, mypiccserial, 0, 1, mypicckey, mypicdata) % 256
if (status == 0):
return 3 #MifareClissic标签,已经写有NDEF数据
else:
myctrlword = 0
status = Objdll.forumtype4request(myctrlword, mypiccserial, mypiccseriallen) % 256
if (status == 0 or status == 52):
return 4 #forumtype4 标签
else:
return -1 #其他未知型号标签
else:
return 23 #未连接到发卡器
except:
return 23
def WriteTag(self,funcname): #将NDEF缓冲区数据写入各种不同类型的NFC标签,清除标签内NDEF数据
mypiccserial = bytes(8)
mypiccseriallen=bytes(1)
try:
cardtyep = self.checkcardtype() #判断发卡器上的标签类型
if(cardtyep==1): #写forumtype2 Ntag2标签
if self.checkBox_before.isChecked():
myctrlword = 16
else:
myctrlword = 0
status = Objdll.forumtype2_write_ndeftag(myctrlword, mypiccserial, oldpicckey) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'ForumType2,UID:'
for num in range(0, 7):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:'+cardno)
if (self.checkBox_before.isChecked() and not self.checkBox_later.isChecked()) or (not self.checkBox_before.isChecked() and self.checkBox_later.isChecked() or (self.checkBox_before.isChecked() and self.checkBox_later.isChecked())):
self.NtagkeyEn()
else:
self.ListErrInf(status)
elif(cardtyep==2): #写forumtype5 15693标签
myctrlword = 0
afi=0
status = Objdll.forumtype5_write_ndeftag(myctrlword,afi, mypiccserial) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'ForumType5,UID:'
for num in range(0, 8):
cardno = cardno + '%02X' % (mypiccserial[num])
if self.checkBox_later.isChecked(): #15693卡锁定块数据后只能读取不可再修改,为防止卡片锁死,请谨慎锁定
Objdll.iso15693lockblock(0,1,mypiccserial)
self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif (cardtyep == 3): # 写MifareClassic标签
if(funcname=='NDEF_Clear'):
if self.checkBox_before.isChecked():
myctrlword = 210
else:
myctrlword = 146
status = Objdll.piccclear_ndeftag(myctrlword, mypiccserial, oldpicckey) % 256
else:
if self.checkBox_before.isChecked():
myctrlword = 210
else:
myctrlword = 146
if self.checkBox_later.isChecked(): #写标签后给标签加密保护
myctrlword=myctrlword+4
status = Objdll.piccwrite_ndeftag(myctrlword, mypiccserial, oldpicckey,newpicckey) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'MifareClass,UID:'
for num in range(0, 4):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif(cardtyep==4): #写forumtype4 标签
if self.checkBox_before.isChecked():
myctrlword = 64
else:
myctrlword = 0
status = Objdll.forumtype4_write_ndeftag(myctrlword, mypiccserial,mypiccseriallen,newpicckey) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'ForumType4,UID:'
for num in range(0, mypiccseriallen[0]):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif (cardtyep == 23):
self.ListErrInf(23)
else:
self.ListErrInf(8)
except:
self.ListErrInf(8)
def ReadTag(self,funcname): # 读取各种不同类型的NFC标签的NDEF数据
mypiccserial = bytes(8)
mypiccseriallen = bytes(1)
mypiccdata = bytes(2048)
revstrlen = bytes(2)
recordnumber = bytes(2)
try:
cardtyep = self.checkcardtype() #判断发卡器上的标签类型
if (cardtyep == 1): # 读forumtype2 Ntag2标签
if self.checkBox_before.isChecked():
myctrlword = 16
else:
myctrlword = 0
status = Objdll.forumtype2_read_ndeftag(myctrlword, mypiccserial, oldpicckey) % 256
if(status==0):
Objdll.pcdbeep(38)
cardno = 'ForumType2,UID:'
for num in range(0, 7):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('读取NDEF标签数据成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif(cardtyep==2): #读forumtype5 15693标签
myctrlword = 0
afi=0
status = Objdll.forumtype5_read_ndeftag(myctrlword,afi, mypiccserial) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'ForumType5,'
for num in range(0, 8):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('读取NDEF标签数据成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif (cardtyep == 3): # 读MifareClassic标签
if self.checkBox_before.isChecked():
myctrlword = 208
else:
myctrlword = 144
status = Objdll.piccread_ndeftag(myctrlword, mypiccserial, oldpicckey) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'MifareClass,'
for num in range(0, 4):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('读取NDEF标签数据成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif(cardtyep==4): #读forumtype4 标签
if self.checkBox_before.isChecked():
myctrlword = 64
else:
myctrlword = 0
status = Objdll.forumtype4_read_ndeftag(myctrlword, mypiccserial,mypiccseriallen,oldpicckey) % 256
if (status == 0):
Objdll.pcdbeep(38)
cardno = 'ForumType4,'
for num in range(0, mypiccseriallen[0]):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('读取NDEF标签数据成功!标签类型:' + cardno)
else:
self.ListErrInf(status)
elif (cardtyep == 23):
self.ListErrInf(23)
else:
self.ListErrInf(8)
if (status == 0):
Objdll.tagbuf_read(mypiccdata,revstrlen,recordnumber)
strlen=revstrlen[0]+revstrlen[1]*256
strinf=mypiccdata[0:strlen]
ndefstr=strinf.decode('gbk')
self.plainTextEdit_taginf.setPlainText(ndefstr)
except:
self.ListErrInf(8)
def NtagkeyEn(self): #开启或关闭Ntag标签的密钥保护功能
mypiccserial=bytes(8)
if self.checkBox_before.isChecked(): #操作已经加密保护的ntag2x卡
myctrlword=16
else:
myctrlword=0
if self.checkBox_later.isChecked(): #需要开启Ntag卡的加密保护功能
mypiccdata=bytes.fromhex('0000000400000000')
mypiccdata=mypiccdata + newpicckey[0:4]
mypiccdata = mypiccdata +bytes.fromhex('16160000')
myctrlword=myctrlword+7
status = Objdll.piccinit_ntag(myctrlword, mypiccserial, oldpicckey, mypiccdata)
if status == 0:
cardno = 'ForumType2,UID:'
for num in range(0, 7):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('NDEF标签加密锁定保护成功!标签类型:' + cardno)
else:
self.ListBottom('NDEF标签加密锁定保护失败!错误代码%d:' %(status))
else:
mypiccdata = bytes.fromhex('000000FF000000000000000000000000') #关闭Ntag卡的密钥保护功能
myctrlword = myctrlword + 3
status=Objdll.piccinit_ntag(myctrlword,mypiccserial,oldpicckey,mypiccdata)
if status == 0:
cardno = 'ForumType2,UID:'
for num in range(0, 7):
cardno = cardno + '%02X' % (mypiccserial[num])
self.ListBottom('NDEF标签解密去除锁定保护成功!标签类型:' + cardno)
else:
self.ListBottom('NDEF标签解密去除锁定保护失败!错误代码%d:' %(status))
def pushButton_writetag_clicked(self):
self.WriteTag('NDEF缓冲区数据')
def pushButton_text_clicked(self):
languagecodestr = "en".encode('gbk')
textstr=self.lineEdit_text.text().strip().encode('gbk')
if len(textstr)<1:
QMessageBox.critical(self,'提示','请输入要加入写卡缓冲区的文本信息!',QMessageBox.Yes)
self.lineEdit_text.setFocus()
return
else:
status = Objdll.tagbuf_addtext(languagecodestr, len(languagecodestr), textstr, len(textstr)) % 256
if status == 0:
self.ListBottom("文本信息加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("文本信息加入NDEF写卡缓冲区失败!")
def pushButton_App_clicked(self):
packagestr = self.lineEdit_appname.text().strip().encode('gbk')
if len(packagestr)<1:
QMessageBox.critical(self,'提示','请输入要加入写卡缓冲区的自启动APP程序包名!',QMessageBox.Yes)
self.lineEdit_appname.setFocus()
return
else:
status = Objdll.tagbuf_addapp(packagestr, len(packagestr)) % 256
if status == 0:
self.ListBottom("自启动APP名称加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("自启动APP名称加入NDEF写卡缓冲区失败!")
def pushButton_Url_clicked(self):
languagecodestr = "en".encode('gbk')
titlestr=self.lineEdit_title.text().strip().encode('gbk')
uriheaderindex = self.comboBox_headindex.currentIndex()
uristr=self.lineEdit_uri.text().strip().encode('gbk')
if len(uristr)<1:
QMessageBox.critical(self,'提示','请输入要加入写卡缓冲区的网址URI!',QMessageBox.Yes)
self.lineEdit_uri.setFocus()
return
else:
status = Objdll.tagbuf_adduri(languagecodestr, len(languagecodestr), titlestr, len(titlestr), uriheaderindex,uristr, len(uristr)) % 256
if status == 0:
self.ListBottom("网址URL加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("网址URL加入NDEF写卡缓冲区失败!")
def pushButton_Map_clicked(self):
languagecodestr = "en".encode('gbk')
titlestr=self.lineEdit_mapname.text().strip().encode('gbk')
latitude=self.lineEdit_latitude.text().strip()
longitude=self.lineEdit_longitude.text().strip()
mapcoord = ("geo:" + latitude + "," + longitude).encode('gbk')
status = Objdll.tagbuf_adduri(languagecodestr, len(languagecodestr), titlestr, len(titlestr), 0, mapcoord,len(mapcoord)) % 256
if status == 0:
self.ListBottom("地图坐标加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("地图坐标加入NDEF写卡缓冲区失败!")
def pushButton_Bluetooth_clicked(self):
try:
macname = self.lineEdit_Bluetoothname.text().strip() .encode('gbk')
maclist = self.lineEdit_Bluetoothmac.text().strip().split(':')
if (len(maclist) == 6):
macbuf = bytes(
[eval('0x' + maclist[0]), eval('0x' + maclist[1]), eval('0x' + maclist[2]), eval('0x' + maclist[3]),
eval('0x' + maclist[4]), eval('0x' + maclist[5])])
status = Objdll.tagbuf_addbluetooth(macname, len(macname), macbuf) % 256
if status == 0:
self.ListBottom("蓝牙连接信息加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("蓝牙连接信息加入NDEF写卡缓冲区失败!")
else:
QMessageBox.critical(self, '提示', '蓝牙MAC地址输入错误!', QMessageBox.Yes)
self.lineEdit_Bluetoothmac.setFocus()
except:
QMessageBox.critical(self, '提示', '蓝牙MAC地址输入错误!', QMessageBox.Yes)
self.lineEdit_Bluetoothmac.setFocus()
def pushButton_Wifi_clicked(self):
ssidstr = self.lineEdit_hostname.text().strip().encode('gbk')
if len(ssidstr)<1:
QMessageBox.critical(self,'提示','请输入要加入写卡缓冲区的热点名称!',QMessageBox.Yes)
self.lineEdit_hostname.setFocus()
return
authtype=self.comboBox_auth.currentIndex()
crypttype=self.comboBox_Calculation.currentIndex()
keystr=self.lineEdit_password.text().strip().encode('gbk')
status = Objdll.tagbuf_addwifi(ssidstr, len(ssidstr), authtype, crypttype, keystr, len(keystr)) % 256
if status == 0:
self.ListBottom("WIFI热点信息加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("WIFI热点信息加入NDEF写卡缓冲区失败!")
def pushButton_Card_clicked(self):
infostr = "BEGIN:VCARD" + "\n"
infostr = infostr + "VERSION:3.0" + "\n"
infostr = infostr + "FN:"+self.lineEdit_name.text().strip()+ "\n"
infostr = infostr + "TEL:" +self.lineEdit_tel.text().strip()+ "\n"
infostr = infostr + "ORG:" +self.lineEdit_unilname.text().strip()+ "\n"
infostr = infostr + "ADR:" +self.lineEdit_address.text().strip()+ "\n"
infostr = infostr + "EMAIL:" +self.lineEdit_email.text().strip()+ "\n"
infostr = infostr + "URL:" +self.lineEdit_net.text().strip()+ "\n"
infostr = infostr + "END:VCARD"
businesscard = infostr.encode('gbk')
status = Objdll.tagbuf_addbusinesscard(businesscard, len(businesscard)) % 256
if status == 0:
self.ListBottom("电子名片信息加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("电子名片信息加入NDEF写卡缓冲区失败!")
def pushButton_Data_clicked(self):
typestr = self.lineEdit_datatype.text().strip().encode('gbk')
datastr = self.lineEdit_data.text().strip().encode('gbk')
status = Objdll.tagbuf_adddata(typestr, len(typestr), datastr, len(datastr)) % 256
if status == 0:
self.ListBottom("自定义数据类型加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("自定义数据类型加入NDEF写卡缓冲区失败!")
def pushButton_Call_clicked(self):
languagecodestr = "en".encode('gbk')
titlestr = "".encode('gbk')
CallNumber=self.lineEdit_callnum.text().strip().encode('gbk')
status = Objdll.tagbuf_adduri(languagecodestr, len(languagecodestr), titlestr, len(titlestr), 5, CallNumber,len(CallNumber)) % 256
if status == 0:
self.ListBottom("呼叫电话加入NDEF写卡缓冲区成功,可继续添加标签信息到缓冲区,也可以将缓冲区现有信息写入标签!")
else:
self.ListBottom("呼叫电话加入NDEF写卡缓冲区失败!")
def pushButton_readtag_clicked(self):
#Objdll.tagbuf_forumtype4_clear()
#Objdll.tagbuf_clear()
self.plainTextEdit_taginf.setPlainText('')
self.ReadTag('NDEF_ReadInfo')
def pushButton_cleatag_clicked(self):
Objdll.tagbuf_forumtype4_clear()
Objdll.tagbuf_clear()
self.checkBox_later.setChecked(False)
self.WriteTag('NDEF_Clear')
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWindow = MainWindow()
screen = QDesktopWidget().screenGeometry()
size = mainWindow.geometry()
# 获得窗口相关坐标
newLeft = (screen.width() - size.width()) // 2
newTop = (screen.height() - size.height()) // 2
# 移动窗口使其居中
mainWindow.pushButton_clearbuff.setStyleSheet("color:red;")
mainWindow.pushButton_writetag.setStyleSheet("color:blue;")
mainWindow.move(newLeft, newTop)
if sys.platform == 'linux' or sys.platform == 'mac':
# Linux加载当前目录下的so库
dllfile = sys.path[0] + '/libOURMIFARE.so'
Objdll = ctypes.cdll.LoadLibrary(dllfile)
else:
# windows系统加载当前目录下的DLL库
dllfile = sys.path[0] + '\OUR_MIFARE.dll'
Objdll = ctypes.windll.LoadLibrary(dllfile)
mainWindow.show()
sys.exit(app.exec_())