本文通過(guò)場(chǎng)上提供的IC卡編程接口實(shí)現(xiàn)了讀寫(xiě)IC卡的功能。
在寫(xiě)相關(guān)的信息管理系統(tǒng)時(shí),有時(shí)會(huì)遇見(jiàn)讀寫(xiě)相關(guān)的外部設(shè)備等問(wèn)題,這類的問(wèn)題,在PowerBulider中實(shí)現(xiàn)這類的功能并不是一件難事,現(xiàn)在的相關(guān)外部設(shè)備廠商在提供產(chǎn)品時(shí),基本都提供了相關(guān)編程接口,利用這些接口函數(shù)后ActiveX控件,結(jié)合PowerBulider中外部函數(shù)的調(diào)用,可以輕松的實(shí)現(xiàn)相關(guān)功能,以下提供讀寫(xiě)IC卡實(shí)現(xiàn)的基本代碼,以期消除相關(guān)編程人員對(duì)讀寫(xiě)外部設(shè)備等問(wèn)題的恐懼心理
外部函數(shù)聲明:
Subroutine PostPara(long prot,strig syspara) library “lock739.dll”//傳遞參數(shù),主要傳遞串口信息
Function long Reset() library “lock739.dll”//讀寫(xiě)復(fù)位
Function Boolean OpenCom () library “lock739.dll”//打開(kāi)串口
Subroutine CloseCom() library “lock739.dll”//關(guān)閉串口
Function long ChkCard() library “lock739.dll”//檢查卡是否到位
Function long CmpSc(string sc) library “lock739.dll”//核對(duì)密碼
Function long WriteSc(string sc) library “lock739.dll”//修改加密卡密碼
Function long ReadSc(string inbuff,long sclen) library “lock739.dll”//度曲加密卡密碼
Function long RdDat(long cardtype,long start,long ilen,ref string inbuff) library “lock739.dll”//讀卡信息
Function long WrDat(long cardtype,long start,long ilen,ref string outbuff)library “lock739.dll”//寫(xiě)卡信息
實(shí)例變量:
public string sc=’272272272’
寫(xiě)卡函數(shù):wf_write(string as_arg1,long al_start,long al_len)
/*參數(shù) string as_arg1 寫(xiě)入的字符串;
long al_start 寫(xiě)入的位置
long al_len 寫(xiě)入的長(zhǎng)度*/
long l_rtn
if opencom()=false then
messagebox(“提示”,”串口連接失敗”)
return
end if
l_rtn=chkcard()
if l_rtn<>0 then
wf_errormessage(l_rtn)
closecom()
return
end if
l_rtn=cmpsc(sc)//sc為密碼
if l_rtn<>0 then
wf_errormessage(l_rtn)
closecom()
return
end if
l_rtn=wrdat(1,al_start,al_len,as_agr1)
if l_rtn<>0 then
wf_errormessage(l_rtn)
closecom()
return
end if
messagebox(“提示”,”寫(xiě)卡成功!”)
讀卡函數(shù):wf_read(string as_arg1,long al_start,long al_len)
/*參數(shù) string as_arg1 保存讀出信息的字符串;
long al_start 開(kāi)始讀卡入的位置
long al_len 讀卡的長(zhǎng)度*/
long l_rtn
if opencom()=false then
messagebox(“提示”,”串口連接失敗”)
return
end if
l_rtn=chkcard()
if l_rtn<>0 then
wf_errormessage(l_rtn)
closecom()
return
end if
l_rtn=rddat(1,al_start,al_len,as_agr1)
if l_rtn<>0 then
wf_errormessage(l_rtn)
closecom()
return
end if
messagebox(“提示”,”讀卡成功!”)
顯示錯(cuò)誤函數(shù):wf_errormessage(long lerror)
choose case lerror
case 1
messagebox(“提示”,”寫(xiě)入錯(cuò)誤或密碼錯(cuò)誤!”)
case 2
messagebox(“提示”,”卡已損壞或參數(shù)越界!“)
case 3
messagebox(“提示”,”請(qǐng)插卡!”)
case 4
messagebox(“提示”,”通訊錯(cuò)誤!”)
case else
messagebox(“提示”,”未知錯(cuò)誤!”)
end choose
初始化卡函數(shù)wf_initialcard(long al_port)
/*參數(shù):long al_port 傳入讀寫(xiě)器使用的串口*/
psotpara(al_port,””)
以上的例子代碼所使用的ic卡為sle4442 加密存儲(chǔ)器卡,讀卡器為wb1000 IC卡讀寫(xiě)器
通過(guò)以上代碼的示例,實(shí)現(xiàn)與外部設(shè)備的通訊,并不是一件很難的時(shí)吧?
新聞熱點(diǎn)
疑難解答
圖片精選