pb调用精伦电子sdtapi.dll读卡函数的心得

函数原型:

1、端口初始化函数

   原    型:int InitComm (int iPort)

   说    明:本函数用于打开串口或USB并检测读卡设备是否就绪。

   参    数:iPort:设置串口、USB、USB-HID(免驱动)接口

串口

1 – 16(十进制)

例如:

1: 1(COM1)

2:2(COM2)

USB

1001

1001

 

    返 回值:

意义

1

正确

其它

错误

2、端口关闭接口

   原    型:int CloseComm(void)

   说    明:本函数用于关闭已打开的端口,一般在调用InitComm成功并完成读卡任务后调用。

   参    数:无

   返 回 值:

意义

1

正确

其它

错误

    注意:如果不再使用已打开的端口,必须使用CloseComm函数关闭端口。

3、找IC

   原    型:int Routon_IC_FindCard();

   说    明:本函数用于寻卡。

   参    数: 无。

   返 回 值:

             

意义

1

正确

0

错误

 

4、读IC卡序列号高级函数

    原    型:int Routon_IC_HL_ReadCardSN(char * SN);

    说    明:本函数用于读取IC卡的序列号,自动完成找卡、选卡等过程。

    参    数: SN [out] 字符指针,需要在调用时分配内存,字节数不小于16。

    返回值:         

意义

1

正确

0

错误

5、读IC卡区块高级函数

   原    型:int Routon_IC_HL_ReadCard (int SID,int BID,int KeyType,unsigned char * Key,unsigned  char * data);

   说    明:本函数用于读取IC卡指定扇区的数据内容,自动完成找卡、选卡、认证等过程。

   参    数:

  SID为扇区号,0-15之间(对M1S50卡)。

  BID为块号,0-3之间。

  KeyType为密钥类型,两种:0x60 keyA,0x61 keyB。

  Key为密钥。

  data为读取到的数据内容,需要在调用时分配内存,字节数不小于16

 

PB外部函数定义:

function int InitComm (int iPort) library "sdtapi.dll" alias for "InitComm;ansi"
function int CloseComm() library "sdtapi.dll" alias for "CloseComm;ansi"

function int Routon_IC_FindCard() library "sdtapi.dll" alias for "Routon_IC_FindCard;ansi"
function int Routon_IC_HL_ReadCardSN(ref string SN) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCardSN;ansi"
library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi"
function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref longlong Key, ref ulong data[16]) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi"

 

PB调用程序:

long li_Port,ll_rtn
string ls_sn=space(300),ls_key
//
初始化通讯口
//
打开端口
st_17.text=''
li_Port=1001
ll_rtn=InitComm(li_Port)//端口初始化
if ll_rtn<>1 then
  messagebox('提示','端口初始化失败!')

  return -1
end if
//
寻卡请求
ll_rtn=Routon_IC_FindCard()
if ll_rtn<>1 then
  messagebox('
提示','寻卡请求失败!')
  CloseComm()
  return -1
end if
ll_rtn=Routon_IC_HL_ReadCardSN(ls_sn)
if ll_rtn<>1 then
  messagebox('提示','读IC卡序列号失败!')
  CloseComm()
  return -1
end if
//读IC卡区块高级函数
//ls_key="~hff~hff~hff~hff~hff~hff~h00"
//ls_key="~hff~hff~hff~hff~hff~hff"
//ls_key="0xffffffffffff"
longlong ll_key
ll_key =  281474976710655
ulong ls_data[16] //卡数据缓冲
//ulong key[6]
//key[1] =255
//key[2] =255
//key[3] =255
//key[4] =255
//key[5] =255
//key[6] =255
ll_rtn=Routon_IC_HL_ReadCard(0,0,96,ll_key,ls_data[])
if ll_rtn<>1 then
 messagebox('提示','读IC卡区块失败!')
 CloseComm()
 return -1
end if
CloseComm()

return 1
 

测试过程:

1、function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref string Key,ref string data) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi" 

参数:ls_key="~hff~hff~hff~hff~hff~hff~h00" 或 ls_key="~hff~hff~hff~hff~hff~hff"

ll_rtn=Routon_IC_HL_ReadCard(0,0,96,ls_key,ls_data)

ll_rtn=-3

失败

2、function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref longlong Key,ref string data) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi" 

参数:ll_key=281474976710655

ll_rtn=Routon_IC_HL_ReadCard(0,0,96,ls_key,ls_data)

ll_rtn=1成功,ls_data乱码,失败

3、function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref ulong Key[],ref ulong data[]) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi" 

参数:ulong ls_data[] //卡数据缓冲

ulong key[6]
key[1] =255
key[2] =255
key[3] =255
key[4] =255
key[5] =255
key[6] =255

ll_rtn=Routon_IC_HL_ReadCard(0,0,96,key[],ls_data[])

ll_rtn=-3,失败

4、function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref ulong Key[],ref ulong data[]) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi" 

参数:ulong ls_data[16] //卡数据缓冲

ulong key[6]
key[1] =255
key[2] =255
key[3] =255
key[4] =255
key[5] =255
key[6] =255

ll_rtn=Routon_IC_HL_ReadCard(0,0,96,key[],ls_data[])

ll_rtn=-3,失败

5、function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref longlong Key,ref ulong data[]) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi" 

参数:ulong ls_data[] //卡数据缓冲

ll_key=281474976710655

ll_rtn=Routon_IC_HL_ReadCard(0,0,96,ll_key,ls_data[])

ll_rtn=1,ls_data[]只有ls_data[1],失败

6、function long Routon_IC_HL_ReadCard (long SID,long BID,long KeyType, ref longlong Key,ref ulong data[16]) library "sdtapi.dll" alias for "Routon_IC_HL_ReadCard;ansi" 

参数:ulong ls_data[16] //卡数据缓冲

ll_key=281474976710655

ll_rtn=Routon_IC_HL_ReadCard(0,0,96,ll_key,ls_data[])

ll_rtn=1,成功。 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值