在powerbulider中讀寫ic卡 在寫相關的信息管理系統時,有時會遇見讀寫相關的外部設備等問題,這類的問題,在powerbulider中實現這類的功能并不是一件難事,現在的相關外部設備廠商在提供產品時,基本都提供了相關編程接口,利用這些接口函數后activex控件,結合powerbulider中外部函數的調用,可以輕松的實現相關功能,以下提供讀寫ic卡實現的基本代碼,以期消除相關編程人員對讀寫外部設備等問題的恐懼心理 外部函數聲明: subroutine postpara(long prot,strig syspara) library “lock739.dll”//傳遞參數,主要傳遞串口信息 function long reset() library “lock739.dll”//讀寫復位 function boolean opencom () library “lock739.dll”//打開串口 subroutine closecom() library “lock739.dll”//關閉串口 function long chkcard() library “lock739.dll”//檢查卡是否到位 function long cmpsc(string sc) library “lock739.dll”//核對密碼 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”//寫卡信息 實例變量: public string sc=’272272272’ 寫卡函數:wf_write(string as_arg1,long al_start,long al_len) /*參數 string as_arg1 寫入的字符串; long al_start 寫入的位置 long al_len 寫入的長度*/ 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(“提示”,”寫卡成功!”) 讀卡函數:wf_read(string as_arg1,long al_start,long al_len) /*參數 string as_arg1 保存讀出信息的字符串; long al_start 開始讀卡入的位置 long al_len 讀卡的長度*/ 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(“提示”,”讀卡成功!”) 顯示錯誤函數:wf_errormessage(long lerror) choose case lerror case 1 messagebox(“提示”,”寫入錯誤或密碼錯誤!”) case 2 messagebox(“提示”,”卡已損壞或參數越界!“) case 3 messagebox(“提示”,”請插卡!”) case 4 messagebox(“提示”,”通訊錯誤!”) case else messagebox(“提示”,”未知錯誤!”) end choose 初始化卡函數wf_initialcard(long al_port) /*參數:long al_port 傳入讀寫器使用的串口*/ psotpara(al_port,””)