在PB中调用IC卡读写器的程序例子代码
读取卡号
Integer i, li_rtn, area, keya1b0
byte ctrlword, serial[4], picckey[6], piccdata0_2[48]
area = 8//操作第8区
keya1b0 = 1//大于表示A密码
ctrlword = ( BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY )//控制字
//旧密码
picckey[1] = 255
picckey[2] = 255
picckey[3] = 255
picckey[4] = 255
picckey[5] = 255
picckey[6] = 255
li_rtn = piccreadex ( ctrlword , serial , area , keya1b0 , picckey , piccdata0_2 )
DebugBreak ()
CHOOSE CASE li_rtn
CASE 0
MsgBox("操作成功")
CASE 8
MsgBox("请将卡放在感应区")
CASE 21 //没有动态库
MsgBox("找不到接口文件ICUSB.DLL和OUR_MIFARE.dll")
CASE ELSE
MsgBox("错误代码" + string(li_rtn))
END CHOOSE
//返回解释
/*
#define ERR_REQUEST 8//寻卡错误
#define ERR_READSERIAL 9//读序列吗错误
#define ERR_SELECTCARD 10//选卡错误
#define ERR_LOADKEY 11//装载密码错误
#define ERR_AUTHKEY 12//密码认证错误
#define ERR_READ 13//读卡错误
#define ERR_WRITE 14//写卡错误
#define ERR_NONEDLL 21//没有动态库
#define ERR_DRIVERORDLL 22//动态库或驱动程序异常
#define ERR_DRIVERNULL 23//驱动程序错误或尚未安装
#define ERR_TIMEOUT 24//操作超时,一般是动态库没有反映
#define ERR_TXSIZE 25//发送字数不够
#define ERR_TXCRC 26//发送的CRC错
#define ERR_RXSIZE 27//接收的字数不够
#define ERR_RXCRC 28//接收的CRC错
*/
写卡
Integer li_rtn, i, area, keya1b0
byte ctrlword, serial[4], picckey[6], piccdata0_2[48]
area = 8//操作第8区
keya1b0 = 1//大于表示A密码
ctrlword = ( BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY )//控制字
//旧密码
picckey[1] = 255
picckey[2] = 255
picckey[3] = 255
picckey[4] = 255
picckey[5] = 255
picckey[6] = 255
for i = 1 to 48
piccdata0_2[i] = i
next
li_rtn = piccwriteex ( ctrlword , serial , area , keya1b0 , picckey , piccdata0_2 )
CHOOSE CASE li_rtn
CASE 0
MsgBox("操作成功")
CASE 8
MsgBox("请将卡放在感应区")
CASE 21 //没有动态库
MsgBox("找不到接口文件ICUSB.DLL和OUR_MIFARE.dll")
CASE ELSE
MsgBox("错误代码" + string(li_rtn))
END CHOOSE
//返回解释
/*
#define ERR_REQUEST 8//寻卡错误
#define ERR_READSERIAL 9//读序列吗错误
#define ERR_SELECTCARD 10//选卡错误
#define ERR_LOADKEY 11//装载密码错误
#define ERR_AUTHKEY 12//密码认证错误
#define ERR_READ 13//读卡错误
#define ERR_WRITE 14//写卡错误
#define ERR_NONEDLL 21//没有动态库
#define ERR_DRIVERORDLL 22//动态库或驱动程序异常
#define ERR_DRIVERNULL 23//驱动程序错误或尚未安装
#define ERR_TIMEOUT 24//操作超时,一般是动态库没有反映
#define ERR_TXSIZE 25//发送字数不够
#define ERR_TXCRC 26//发送的CRC错
#define ERR_RXSIZE 27//接收的字数不够
#define ERR_RXCRC 28//接收的CRC错
*/
修改单区密码
Integer li_rtn, area, keya1b0
byte ctrlword, serial[4], piccoldkey[6], piccnewkey[6]
area = 8//操作第8区
keya1b0 = 1//大于表示A密码
ctrlword = ( BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY )//控制字
//旧密码
piccoldkey[1] = 255
piccoldkey[2] = 255
piccoldkey[3] = 255
piccoldkey[4] = 255
piccoldkey[5] = 255
piccoldkey[6] = 255
//新密码
piccnewkey[1] = 255
piccnewkey[2] = 255
piccnewkey[3] = 255
piccnewkey[4] = 255
piccnewkey[5] = 255
piccnewkey[6] = 255
li_rtn = piccchangesinglekey ( ctrlword , serial , area , keya1b0 , piccoldkey , piccnewkey )
DebugBreak ()
CHOOSE CASE li_rtn
CASE 0
MsgBox("操作成功")
CASE 8
MsgBox("请将卡放在感应区")
CASE 21 //没有动态库
MsgBox("找不到接口文件ICUSB.DLL和OUR_MIFARE.dll")
CASE ELSE
MsgBox("异常")
END CHOOSE
//返回解释
/*
#define ERR_REQUEST 8//寻卡错误
#define ERR_READSERIAL 9//读序列吗错误
#define ERR_SELECTCARD 10//选卡错误
#define ERR_LOADKEY 11//装载密码错误
#define ERR_AUTHKEY 12//密码认证错误
#define ERR_READ 13//读卡错误
#define ERR_WRITE 14//写卡错误
#define ERR_NONEDLL 21//没有动态库
#define ERR_DRIVERORDLL 22//动态库或驱动程序异常
#define ERR_DRIVERNULL 23//驱动程序错误或尚未安装
#define ERR_TIMEOUT 24//操作超时,一般是动态库没有反映
#define ERR_TXSIZE 25//发送字数不够
#define ERR_TXCRC 26//发送的CRC错
#define ERR_RXSIZE 27//接收的字数不够
#define ERR_RXCRC 28//接收的CRC错
*/
读卡器发出声音
pcdbeep(50)
读取设备全球唯一编号,作为加密狗用
String ls_tmp
Integer li_rtn
byte devicenumber[4]
li_rtn = pcdgetdevicenumber ( devicenumber )
if li_rtn = 0 then
/*action*/
ls_tmp = String ((devicenumber[1]) )+"-"+ String ((devicenumber[2]) ) +"-"+ String ((devicenumber[3]) ) +"-"+ String ((devicenumber[4]) )
MsgBox ( ls_tmp )
end if