首页 > 其他分享 >VFP读写NFC标签Ntag卡

VFP读写NFC标签Ntag卡

时间:2023-01-07 18:39:47浏览次数:39  
标签:mypiccdata NFC Value Ntag && pagF1 page2 thisform VFP


本示例使用的读写器:Android Linux RFID读写器NFC发卡器WEB可编程NDEF文本/智能海报

声明函数:

set proc to funprogram

declare integer pcdbeep in OUR_MIFARE.dll integer xms &&让设备发出声响
declare integer pcdgetdevicenumber in OUR_MIFARE.dll string @pdevicenumber &&读取设备编号
declare integer piccrequest_ul in OUR_MIFARE.dll string @mypiccserial &&寻卡选卡激活卡
declare integer piccread_ul in OUR_MIFARE.dll integer blockaddr,string @mypiccdata &&读块
declare integer piccwrite_ul in OUR_MIFARE.dll integer blockaddr,string @mypiccdata &&写块
declare integer piccauthkey_ntag in OUR_MIFARE.dll string @picckey,string @piccntagpack &&NTAG21x密码认证
declare integer piccgetversion_ntag in OUR_MIFARE.dll string @piccversiondata &&读取卡版本信息
declare integer piccreadsig_ntag in OUR_MIFARE.dll string @piccversiondata &&读取卡的签字信息
declare integer piccreadcnt_ntag in OUR_MIFARE.dll string @picccntdata &&读取卡的单向操作计数器(操作流水号)
declare integer picclock_ntag in OUR_MIFARE.dll integer locktype,string @serial &&锁定页数据
declare integer piccinit_ntag in OUR_MIFARE.dll integer ctrlword,string @serial,string @picckey,string @piccdata &&初始化卡
declare integer piccreadex_ntag in OUR_MIFARE.dll integer ctrlword,string @serial,string @picckey,integer blockaddr,integer blocksize1,string @piccdata &&轻松读卡
declare integer piccwriteex_ntag in OUR_MIFARE.dll integer ctrlword,string @serial,string @picckey,integer blockaddr,integer blocksize1,string @piccdata &&轻松写卡

thisform.pagF1.page1.text3.Value="00000000"
thisform.pagF1.page1.text6.Value="12345678"

thisform.pagF1.page2.combo1.AddItem ("开启密码保护功能")
thisform.pagF1.page2.combo1.AddItem ("取消密码保护功能")
thisform.pagF1.page2.combo1.ListIndex =1

thisform.pagF1.page2.text1.Value="12345678"
thisform.pagF1.page2.text2.Value=30
thisform.pagF1.page2.text3.Value=0
thisform.pagF1.page2.text5.Value="12345678"
thisform.pagF1.page2.text6.Value="12345678"
thisform.pagF1.page2.text7.Value=30
thisform.pagF1.page2.text8.Value=10

VFP读写NFC标签Ntag卡_VFP NFC

 初始化Ntag卡,设置卡片是否需要认证密码读、写

mypiccserial=spac(7)   &&返回7字节卡序列号
mypicckey=SPACE(4) &&卡认证密码
mypiccdata=SPACE(16) &&读卡的数据缓冲,Ultralight卡及NTAG21x卡的数组长度必须为16个字节,写卡的为4个字节

IF thisform.pagF1.page2.check1.Value >0
IF LEN(ALLTRIM(thisform.pagF1.page2.text6.Value))<>8
= MESSAGEBOX(' 卡密码必须为8个字符!',16,'提示:')
thisform.pagF1.page2.text6.SetFocus
RETURN
ENDIF
Pas1str=ALLTRIM(thisform.pagF1.page2.text6.Value)
mypicckey=""
FOR i=1 TO 4
mypicckey=mypicckey+CHR(HexToDec(SUBSTR(Pas1str,i*2-1,2)+"00"))
NEXT
myctrlword=16 &&需要密码
ELSE
myctrlword=0
ENDIF

IF thisform.pagF1.page2.combo1.ListIndex =1
IF LEN(ALLTRIM(thisform.pagF1.page2.text1.Value))<>8
= MESSAGEBOX(' 卡密码必须为8个字符!',16,'提示:')
thisform.pagF1.page2.text1.SetFocus
RETURN
ENDIF

mypiccdata=CHR(0) &&MIRROR
mypiccdata=mypiccdata+CHR(0) &&RFUI
mypiccdata=mypiccdata+CHR(0) &&MIRROR_PAGE
mypiccdata=mypiccdata+CHR(thisform.pagF1.page2.text2.Value) &&AUTH0
myctrlword=myctrlword+1

ACCESS=MOD(thisform.pagF1.page2.text3.Value, 8)
IF thisform.pagF1.page2.check2.Value >0
ACCESS=ACCESS+128
ENDIF
mypiccdata=mypiccdata+CHR(ACCESS) &&ACCESS
mypiccdata=mypiccdata+CHR(0)+CHR(0)+CHR(0) &&启用计数器
myctrlword=myctrlword+2

Pas1str=ALLTRIM(thisform.pagF1.page2.text1.Value)
FOR i=1 TO 4
mypiccdata=mypiccdata+CHR(HexToDec(SUBSTR(Pas1str,i*2-1,2)+"00"))
NEXT

mypiccdata=mypiccdata+CHR(22) &&PACK
mypiccdata=mypiccdata+CHR(22) &&PACK
mypiccdata=mypiccdata+CHR(0) &&RFUI
mypiccdata=mypiccdata+CHR(0) &&RFUI
myctrlword=myctrlword+4
ELSE
mypiccdata=CHR(0) &&MIRROR
mypiccdata=mypiccdata+CHR(0) &&RFUI
mypiccdata=mypiccdata+CHR(0) &&MIRROR_PAGE
mypiccdata=mypiccdata+CHR(255) &&AUTH0
myctrlword=myctrlword+1

FOR i=5 TO 16
mypiccdata=mypiccdata+CHR(0)
NEXT
myctrlword=myctrlword+2
ENDIF

&&-------------------------------------------------------------- 显示16进制的串口调试指令
comedc=22
dispstr="1D16"

dispstr=dispstr+LEFT(DecToHex(myctrlword),2)
comedc=BITXOR(comedc,myctrlword)

FOR i=1 TO 7
dispstr=dispstr+"00"
comedc=BITXOR(comedc,0)
NEXT

FOR i=1 TO 4
dispstr=dispstr+LEFT(DecToHex(ASC(SUBSTR(mypicckey,i,1))),2)
comedc=BITXOR(comedc,ASC(SUBSTR(mypicckey,i,1)))
NEXT

FOR i=1 TO 16
dispstr=dispstr+LEFT(DecToHex(ASC(SUBSTR(mypiccdata,i,1))),2)
comedc=BITXOR(comedc,ASC(SUBSTR(mypiccdata,i,1)))
NEXT

dispstr=dispstr+LEFT(DecToHex(comedc),2)
thisform.pagF1.page2.edit2.Value =dispstr
&&--------------------------------------------------------------------

QuestRec= piccinit_ntag(myctrlword,@mypiccserial,@mypicckey,@mypiccdata)
DO case
CASE QuestRec=0
=pcdbeep(50)
CardIdH=""
FOR i=1 TO 7
CardIdH=CardIdH+LEFT(DecToHex(ASC(SUBSTR(mypiccserial,i,1))),2)
NEXT
thisform.pagF1.page2.text4.Value =CardIdH
= MESSAGEBOX('卡号:'+CardIdH +",初始化卡成功!",64,'提示:')
CASE QuestRec=8
= MESSAGEBOX(' 请将卡放在感应区! ',16,'提示:')
CASE QuestRec=12
= MESSAGEBOX(' 密码错误! ',16,'提示:')
CASE QuestRec=14
= MESSAGEBOX(' 设置失败,可能需要验证密码! ',16,'提示:')
CASE QuestRec=23
= MESSAGEBOX(' 请连上USB 读写器! ',16,'提示:')
OTHERWISE
= MESSAGEBOX(' 操作失败,错误代码:'+STR(QuestRec),16,'提示:')
ENDCASE

 轻松读卡操作:

mypiccserial=spac(7)   &&返回7字节卡序列号
mypicckey=SPACE(4) &&卡认证密码
mypiccdata=SPACE(48) &&读卡的数据缓冲

IF thisform.pagF1.page2.check3.Value >0
IF LEN(ALLTRIM(thisform.pagF1.page2.text5.Value))<>8
= MESSAGEBOX(' 卡密码必须为8个字符!',16,'提示:')
thisform.pagF1.page2.text5.SetFocus
RETURN
ENDIF

Pas1str=ALLTRIM(thisform.pagF1.page2.text5.Value)
mypicckey=""
FOR i=1 TO 4
mypicckey=mypicckey+CHR(HexToDec(SUBSTR(Pas1str,i*2-1,2)+"00"))
NEXT
myctrlword=16 &&需要密码
ELSE
mypicckey=CHR(0)+CHR(0)+CHR(0)+CHR(0)
myctrlword=0
ENDIF

myblockaddr=thisform.pagF1.page2.text7.Value
myblocksize=thisform.pagF1.page2.text8.Value

IF myblocksize=0 OR myblocksize>12
= MESSAGEBOX('读卡页数据要大于0小于12!',16,'提示:')
thisform.pagF1.page2.text8.SetFocus
RETURN
ENDIF

&&-------------------------------------------------------------- 显示16进制的串口调试指令
comedc=27
dispstr="0F1B"

dispstr=dispstr+LEFT(DecToHex(myctrlword),2)
comedc=BITXOR(comedc,myctrlword)

FOR i=1 TO 7
dispstr=dispstr+"00"
comedc=BITXOR(comedc,0)
NEXT

FOR i=1 TO 4
dispstr=dispstr+LEFT(DecToHex(ASC(SUBSTR(mypicckey,i,1))),2)
comedc=BITXOR(comedc,ASC(SUBSTR(mypicckey,i,1)))
NEXT

dispstr=dispstr+LEFT(DecToHex(myblockaddr),2)
comedc=BITXOR(comedc,myblockaddr)

dispstr=dispstr+LEFT(DecToHex(myblocksize),2)
comedc=BITXOR(comedc,myblocksize)

dispstr=dispstr+LEFT(DecToHex(comedc),2)
thisform.pagF1.page2.edit2.Value =dispstr
&&--------------------------------------------------------------------

QuestRec= piccreadex_ntag(myctrlword,@mypiccserial,@mypicckey,myblockaddr,myblocksize,@mypiccdata)
DO case
CASE QuestRec=0
=pcdbeep(50)
CardIdH=""
FOR i=1 TO 7
CardIdH=CardIdH+LEFT(DecToHex(ASC(SUBSTR(mypiccserial,i,1))),2)
NEXT
thisform.pagF1.page2.text4.Value =CardIdH

CardDa=""
FOR i=1 TO myblocksize*4
CardDa=CardDa+LEFT(DecToHex(ASC(SUBSTR(mypiccdata,i,1))),2)
NEXT
thisform.pagF1.page2.edit1.Value =CardDa

CASE QuestRec=8
= MESSAGEBOX(' 请将卡放在感应区! ',16,'提示:')
CASE QuestRec=23
= MESSAGEBOX(' 请连上USB 读写器! ',16,'提示:')
OTHERWISE
= MESSAGEBOX(' 操作失败,错误代码:'+STR(QuestRec),16,'提示:')
ENDCASE

 轻松写卡操作

mypiccserial=spac(7)   &&返回7字节卡序列号
mypicckey=SPACE(4) &&卡认证密码
mypiccdata=SPACE(48) &&读卡的数据缓冲

IF thisform.pagF1.page2.check3.Value >0
IF LEN(ALLTRIM(thisform.pagF1.page2.text5.Value))<>8
= MESSAGEBOX(' 卡密码必须为8个字符!',16,'提示:')
thisform.pagF1.page2.text5.SetFocus
RETURN
ENDIF

Pas1str=ALLTRIM(thisform.pagF1.page2.text5.Value)
mypicckey=""
FOR i=1 TO 4
mypicckey=mypicckey+CHR(HexToDec(SUBSTR(Pas1str,i*2-1,2)+"00"))
NEXT
myctrlword=16 &&需要密码
ELSE
mypicckey=CHR(0)+CHR(0)+CHR(0)+CHR(0)
myctrlword=0
ENDIF

myblockaddr=thisform.pagF1.page2.text7.Value
myblocksize=thisform.pagF1.page2.text8.Value

IF myblocksize=0 OR myblocksize>11
= MESSAGEBOX('写卡页数据要大于0小于12!',16,'提示:')
thisform.pagF1.page2.text8.SetFocus
RETURN
ENDIF

IF LEN(ALLTRIM(thisform.pagF1.page2.edit1.Value))<myblocksize*4*2
answ= MESSAGEBOX(' 写卡数据不足,是否要自动补0?',0+32+0,'提示:')
IF answ<>1 THEN
RETURN
ELSE
thisform.pagF1.page2.edit1.Value=LEFT(ALLTRIM(thisform.pagF1.page2.edit1.Value)+"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",myblocksize*4*2)
ENDIF
ENDIF

writstr=ALLTRIM(thisform.pagF1.page2.edit1.Value)
mypiccdata=""
FOR i=1 TO myblocksize*4
mypiccdata=mypiccdata+CHR(HexToDec(SUBSTR(writstr,i*2-1,2)+"00"))
NEXT

&&-------------------------------------------------------------- 显示16进制的串口调试指令
comedc=28
dispstr="3B1C"

dispstr=dispstr+LEFT(DecToHex(myctrlword),2)
comedc=BITXOR(comedc,myctrlword)

FOR i=1 TO 7
dispstr=dispstr+"00"
comedc=BITXOR(comedc,0)
NEXT

FOR i=1 TO 4
dispstr=dispstr+LEFT(DecToHex(ASC(SUBSTR(mypicckey,i,1))),2)
comedc=BITXOR(comedc,ASC(SUBSTR(mypicckey,i,1)))
NEXT

dispstr=dispstr+LEFT(DecToHex(myblockaddr),2)
comedc=BITXOR(comedc,myblockaddr)

dispstr=dispstr+LEFT(DecToHex(myblocksize),2)
comedc=BITXOR(comedc,myblocksize)

FOR i=1 TO myblocksize*4
dispstr=dispstr+LEFT(DecToHex(ASC(SUBSTR(mypiccdata,i,1))),2)
comedc=BITXOR(comedc,ASC(SUBSTR(mypiccdata,i,1)))
NEXT

FOR i=myblocksize*4+1 TO 44
dispstr=dispstr+"00"
comedc=BITXOR(comedc,0)
NEXT


dispstr=dispstr+LEFT(DecToHex(comedc),2)
thisform.pagF1.page2.edit2.Value =dispstr
&&--------------------------------------------------------------------

QuestRec= piccwriteex_ntag(myctrlword,@mypiccserial,@mypicckey,myblockaddr,myblocksize,@mypiccdata)
DO case
CASE QuestRec=0
=pcdbeep(50)
CardIdH=""
FOR i=1 TO 7
CardIdH=CardIdH+LEFT(DecToHex(ASC(SUBSTR(mypiccserial,i,1))),2)
NEXT
thisform.pagF1.page2.text4.Value =CardIdH


CASE QuestRec=8
= MESSAGEBOX(' 请将卡放在感应区! ',16,'提示:')
CASE QuestRec=23
= MESSAGEBOX(' 请连上USB 读写器! ',16,'提示:')
OTHERWISE
= MESSAGEBOX(' 操作失败,错误代码:'+STR(QuestRec),16,'提示:')
ENDCASE


标签:mypiccdata,NFC,Value,Ntag,&&,pagF1,page2,thisform,VFP
From: https://blog.51cto.com/RongShi/5995683

相关文章

  • NFC 读取卡信息(流程示例2),以公交卡为例
    公交卡的结构1.SELECT选择MF(可不选)可以不选默认也会被选中,但是可以通过这个指令获得文件控制信息FCI发送00A40000023F00接收6f12840e315055422e5359......
  • #盲盒+码# 【FFH】 Harmony3.0如何实现NFC碰一碰配置
    本文正在参加「盲盒」+码有奖征文活动最近更新了HarmonyOS3.0系统,按照过去的方法配置NFC碰一碰方法配置应用,发现出现了一些问题,在一些摸索测试中总结了一套最新最简洁的配......
  • What are the advantages of NB-IoT in the shared bicycle project?
    NB-IoT isabrand-newnarrowbandIoTtechnologybasedonthecellularnetwork,focusingonalow-powerwide-areanetwork,operatingbasedonalicensedspectr......
  • RFID 卡 NFC 卡的分类
    小区门禁卡,办一个50,2个就是100,太贵了。常用的卡是M1卡,有16个扇区,每个扇区能存储64个字节,正好就是1024个字节,就是1KB卡的分类:ID卡:最普通的卡,0扇区内容,只能读,不能写,写......
  • NFC芯片DP1363F兼容LRC663/RC522支持18092/15693协议多设备读卡超高性价比
    DP1363是一款高度集成的非接触读写芯片,集强大的多协议支持、最高射频输出功率、以及突破性技术低功耗卡片检测等优势一身,满足市场对更高集成度、更小外壳和互操作性的需求,......
  • NFC 读卡器ACR122U-A9接入Ubuntu 18.04系统
    虚拟机环境:VirtualBox图形用户界面 版本6.0.24r139119系统环境:18.04.1-Ubuntu需求:在Ubuntu环境下,接入NFC读卡器ACR122U接入方式:pcsc-lite封装了访问使用SCardAP......
  • NFC刷卡芯片系列技术问题汇总
    继之前我们在《智能门锁》里有提到使用的几款13.56M刷卡芯片,本期我们先来讲讲13.56M标配版的几款芯片会遇到的一些常见问题解答。标配版有:SI522/SI522A/SI523;低配版有:CI5......
  • NFC协议超低功耗检卡能非接触式读卡芯片SI512
    Si512是一个高度集成的NFC前端,支持13.56MHz下的多种主动/被动模式非接触式通信方法和协议,支持自动载波侦测功能(ACD)。Si512前端有5种工作模式:•读写器模式,支持ISO14443A/......
  • NFC门禁卡模拟
    使用nfc模拟全加密门卡过程1、门禁卡大多采用IC制卡和ID制卡ID卡:内部仅存储一个卡号信息,无加密区域。由于手机、手环无法模拟该卡种,所以这里不做讨论和扩展IC卡:本身具......
  • 【VFP】如何将超大数据的EXCEL表转换为DBF表
    经常进行计算机处理的工作人员,有时候需要用VFP来快速处理EXCEL电子表格里数据。如果EXCEL数据少的话,可以直接打开数据表,将文件另存为”EXCEL5.0/95",然后在VFP里从文件菜单......