FR100IC卡读写器
API
编程说明
版本1.00
Table of Contents
1概述4
1.1API文件说明:4
1.2适用操作系统:4
1.3适用开发语言:4
2API函数5
2.1设备通用函数5
2.1.1int_stdcall IFD_GetDLL_Ver(char*rVER)5
2.1.2int_stdcall IFD_SetDLL_CommKEY(unsigned char*key)5
2.1.3int_stdcall IFD_SetDLL_CommMode(unsigned char mode)5
2.1.4int_stdcall IFD_InitComm(char*portname,unsigned long baud)5
2.1.5int_stdcall IFD_ExitComm()6
2.1.6int_stdcall IFD_GetDevice_Ver(unsigned char*rData,unsigned char*rLen)6
2.1.7int_stdcall IFD_ResetDevice()6
2.1.8int_stdcall IFD_Control_LED(unsigned char LedCtrlMode,unsigned char LED1,unsigned char LED2)6
2.1.9int_stdcall IFD_Control_Buzzer(unsigned char*cBeepData,unsigned char cLen)7
2.1.10int_stdcall IFD_SetDevice_Baud(unsigned char baud)7
2.1.11int_stdcall IFD_SetDevice_CommKEY(unsigned char*key)8
2.2卡座通用函数8
2.2.1int_stdcall IFD_Select_ICC(unsigned char IccNumber)8
2.2.2int_stdcall IFD_PowerON_ICC()8
2.2.3int_stdcall IFD_PowerDown_ICC()8
2.2.4int_stdcall IFD_Get_CardStatus(unsigned char*rCardStatus,unsigned char*rLen)8
2.2.5int_stdcall IFD_Get_CardStatus(unsigned char*rCardStatus,unsigned char*rLen)9
2.2.6int_stdcall IFD_AutoPowerON(unsigned char mode)9
2.3CPU卡专用函数9
2.3.1int_stdcall IFD_CPUCARD_Reset(unsigned char*rData,unsigned char*rLen)9
2.3.2int_stdcall IFD_CPUCARD_ExchangeAPDU(unsigned char*cData,unsigned char cLen,unsigned char*rData,unsigned char*rLen)9
2.4AT24Cxx系列卡专用函数10
2.4.1int_stdcall IFD_AT24C01_Reset()10
2.4.2int_stdcall IFD_AT24C01_Read(unsigned int Address,unsigned char Len,unsigned char*rData)10
2.4.3int_stdcall IFD_AT24C01_Write(unsigned int Address,unsigned char Len,unsigned char*cData)10
2.4.4int_stdcall IFD_AT24C01_Reset()11
2.4.5int_stdcall IFD_AT24C01_Read(unsigned int Address,unsigned char Len,unsigned char*rData)11
2.4.6int_stdcall IFD_AT24C01_Write(unsigned int Address,unsigned char Len,unsigned char*cData)11
2.5SLE4442/4432卡专用函数12
2.5.1int_stdcall IFD_SLE4442_Reset(unsigned char*rData,unsigned char*rLen)12
2.5.2int_stdcall IFD_SLE4442_Read(unsigned int Address,unsigned char Len,unsigned char*rData)12
2.5.3int_stdcall IFD_SLE4442_Write(unsigned int Address,unsigned char Len,unsigned char*cData)12
2.5.4int_stdcall IFD_SLE4442_Read_ProtectZone(unsigned int Address,unsigned char Len,unsigned char*rData)13
2.5.5int_stdcall IFD_SLE4442_Write_ProtectZone(unsigned int Address,unsigned char Len,unsigned char*cData)13
2.5.6int_stdcall IFD_SLE4442_Verify_PSC(unsigned char psc1,unsigned char psc2,unsigned char psc3)13
2.5.7int_stdcall IFD_SLE4442_Update_PSC(unsigned char psc1,unsigned char psc2,unsigned char psc3)13
2.5.8int_stdcall IFD_SLE4442_Read_PSC(unsigned char*rPSC,unsigned char*rLen)14
2.5.9int_stdcall IFD_SLE4442_Read_EC(unsigned char*rEC,unsigned char*rLen)14
2.5.10int_stdcall IFD_SLE4442_Update_EC(unsigned char EC)14
2.6SLE4428/4418卡专用函数15
2.6.1int_stdcall IFD_SLE4428_Reset(unsigned char*rData,unsigned char*rLen)15
2.6.2int_stdcall IFD_SLE4428_Read(unsigned int Address,unsigned char Len,unsigned char*rData)15
2.6.3int_stdcall IFD_SLE4428_Write(unsigned int Address,unsigned char Len,unsigned char*cData)15
2.6.4int_stdcall IFD_SLE4428_Read_PB(unsigned int Address,unsigned char Len,unsigned char*rData)15
2.6.5int_stdcall IFD_SLE4428_Write_PB(unsigned int Address,unsigned char Len,unsigned char*cData)16
2.6.6int_stdcall IFD_SLE4428_Compare_PB(unsigned int Address,unsigned char Len,unsigned char*cData)16
2.6.7int_stdcall IFD_SLE4428_Verify_PSC(unsigned char psc1,unsigned char psc2)16
2.6.8int_stdcall IFD_SLE4428_Update_PSC(unsigned char psc1,unsigned char psc2)17
2.6.9int_stdcall IFD_SLE4428_Read_PSC(unsigned char*rPSC,unsigned char*rLen)17
2.6.10int_stdcall IFD_SLE4428_Read_EC(unsigned char*rEC,unsigned char*rLen)17
2.6.11int_stdcall IFD_SLE4428_Update_EC(unsigned char EC)17
3返回状态/错误代码19
附录:SLE4442卡读流程20
SSSE32.DLL是一个基于Windows的32位动态链接库文件,目的是方便客户进行二次开发。其使用的方法与Windows标准的.DLL文件一样。
1.1API文件说明:
SSSE32.h API函数原型定义
SSSE32.dll API函数的动态链接库
EasyD12.dll USB动态辅助链接库
1.2适用操作系统:
Windows NT:需要NT3.1版或以后版本
Windows:需要Windows98、Windows2000或以后版本
1.3适用开发语言:
Visual C++5.0及以后版本
Visual Basic 5.0及以后版本
Visual C++Builder5.0及以后版本
DELPHI3.0及以后版本
PowerBuilder6.0及以后版本
其它Windowns32位开发工具
2.1设备通用函数
2.1.1int_stdcall IFD_GetDLL_Ver(char*rVER)
功能:读函数库版本号
参数:*rVER[OutPut]:存放读出的函数库版本号。
2.1.2int_stdcall IFD_SetDLL_CommKEY(unsigned char*key)
功能:读函数库加密通讯密钥
参数:*key[Input]:存放128字节的加密通讯密钥。
2.1.3int_stdcall IFD_SetDLL_CommMode(unsigned char mode)
功能:读函数库与读卡器的通讯方式
参数:mode[Input]:通讯方式,0表示明码通讯,1表示加密通讯。
注:函数库默认明码通讯方式,如果采用明码通讯,不需调用该函数。
2.1.4int_stdcall IFD_InitComm(char*portname,unsigned long baud)
功能:初始化通讯端口
参数:
*portname[Input]:通讯端口的名称,可选COM1~COM6及USB。
baud[Input]:通讯波特率选择,可选9600,19200,38400,57600及115200.当端口为USB时,该参数无效。例:
status=IFD_InitComm(“COM1”,9600);//初始化串口1,通讯波特率为9600
status=IFD_InitComm(“USB”,9600);//初始化USB通讯端口
2.1.5int_stdcall IFD_ExitComm()
功能:关闭通讯端口
2.1.6int_stdcall IFD_GetDevice_Ver(unsigned char*rData,unsigned char*rLen)
功能:读取读写器固件版本号
参数:
*rData[OutPut]:读写器固件版本号信息
*rLen[OutPut]:*rData的长度
2.1.7int_stdcall IFD_ResetDevice()
功能:读卡器软复位。
2.1.8int_stdcall IFD_Control_LED(unsigned char LedCtrlMode,unsigned char LED1,unsigned char LED2)
功能:控制LED灯状态
参数:
LedCtrlMode[In Put]:LED的控制方式,0表示自动指示IC1的上电状态,1表示自动指示IC卡2的上电状态,2表示用户控制LED。LED1[In Put]:控制LED1的状态,0表示关闭,1表示点亮,2表示保持原状态。
LED2[In Put]:控制LED1的状态,0表示关闭,1表示点亮,2表示保持原状态。
注:参数LED1、LED2只有在LedCtrlMode=2的情况下才有效。上电时默认LED指示IC卡1的上电状态。
例:
status=IFD_Control_LED(1,0,0);//LED指示IC卡2的上电状态
status=IFD_Control_LED(2,0,1);//用户控制LED,LED1关闭,LED2点亮。
status=IFD_Control_LED(2,2,0);//用户控制LED,LED1保持原状态,LED2关闭。
2.1.9int_stdcall IFD_Control_Buzzer(unsigned char*cBeepData,unsigned char cLen)
功能:控制蜂鸣器的响声
参数:
*cBeepData[In Put]:蜂鸣器的时间,1单位=10ms.第一个值表示响的时间,第二个值表示停的时间
cLen[In Put]:*cBeepData的长度
例:
cBD[0]=50;status=IFD_Control_Buzzer(cBD,1);//蜂鸣器响500ms
cBD[0]=10;cBD[1]=5;cBD[2]=15;status=IFD_Control_Buzzer(cBD,3);//蜂鸣器响二声,响100ms,停50ms,再响150ms
cBD[0]=10;cBD[1]=5;cBD[2]=15;cBD[3]=5;cBD[4]=25;status=IFD_Control_Buzzer(cBD,5);//蜂鸣器响三声,响100ms,停50ms,再响150ms,停50ms,再响250ms
2.1.10int_stdcall IFD_SetDevice_Baud(unsigned char baud)
功能:修改读卡器通讯波特率
参数:baud[Input]:波特率选择,0表示9600,1表示19200,2表示38400,3表示57600,4表示115200.
注:
读卡器出厂默认波特率为9600.数据掉电能保持。
修改后需重新上电或调用复位命令后才有效。
数据掉电能保持。
2.1.11int_stdcall IFD_SetDevice_CommKEY(unsigned char*key)
功能:设置读卡器在加密通讯模式下的通讯密钥
参数:*key[Input]:通讯密钥,128个字节
注:数据掉电能保持。
2.2卡座通用函数
2.2.1int_stdcall IFD_Select_ICC(unsigned char IccNumber)
功能:选择当前操作的IC卡座
参数:IccNumber[Input]:当前IC卡座号,0表示主IC卡座,1表示操作员卡座,2表示SAM1,3表示SAM2
2.2.2int_stdcall IFD_PowerON_ICC()
功能:给当前IC卡座上电
参数:-
2.2.3int_stdcall IFD_PowerDown_ICC()
功能:给当前IC卡座下电
参数:-
2.2.4int_stdcall IFD_Get_CardStatus(unsigned char*rCardStatus,unsigned char*rLen)
功能:查询卡座是否有卡
参数:
*rCardStatus[OutPut]:第一个字节表示主卡座是否有卡,第二个字节表是操作员卡座是否有卡。0表示无卡,1表示有卡。
*rLen[OutPut]:rCardStatus的长度。
2.2.5int_stdcall IFD_Get_CardStatus(unsigned char*rCardStatus,unsigned char*rLen)
功能:查询卡座是否有卡
参数:
*rCardStatus[OutPut]:第一个字节表示主卡座是否有卡,第二个字节表是操作员卡座是否有卡。0表示无卡,1表示有卡。
*rLen[OutPut]:rCardStatus的长度。
2.2.6int_stdcall IFD_AutoPowerON(unsigned char mode)
功能:允许/禁止插卡自动上电功能
参数:mode[Input]:0表示禁止,1表示允许.读卡器默认允许状态。
2.3CPU卡专用函数
2.3.1int_stdcall IFD_CPUCARD_Reset(unsigned char*rData,unsigned char*rLen)
功能:复位CPU卡
参数:
*rData[Output]:返回卡复位信息。
*rLen[Output]:rData的长度。
2.3.2int_stdcall IFD_CPUCARD_ExchangeAPDU(unsigned char*cData,unsigned char cLen,unsigned char*rData,unsigned char*rLen)
功能:CPU卡Exchange操作。
参数:
*cData[Input]:发给CPU卡的数据。
cLen[Input]:cData的长度。
*rData[Output]:CPU卡返回的数据。
*rLen[Output]:rData的长度。
2.4AT24Cxx系列卡专用函数
2.4.1int_stdcall IFD_AT24C01_Reset()
功能:复位AT24C01/02/04/08/16卡
参数:-
2.4.2int_stdcall IFD_AT24C01_Read(unsigned int Address,unsigned char Len,unsigned char*rData)功能:读AT24C01/02/04/08/16卡。
参数:
Address[Input]:读开始地址
Len[Input]:读数据的长度。
*rData[Output]:读到的卡数据。
2.4.3int_stdcall IFD_AT24C01_Write(unsigned int Address,unsigned char Len,unsigned char*cData)功能:写AT24C01/02/04/08/16卡。
参数:
Address[Input]:开始地址
Len[Input]:写数据的长度。
*cData[Iutput]:要写到卡的数据。
2.4.4int_stdcall IFD_AT24C01_Reset()
功能:复位AT24C32/64/128/256卡
参数:-
2.4.5int_stdcall IFD_AT24C01_Read(unsigned int Address,unsigned char Len,unsigned char*rData)功能:读AT24C32/64/128/256卡。
参数:
Address[Input]:读开始地址
Len[Input]:读数据的长度。
*rData[Output]:读到的卡数据。
2.4.6int_stdcall IFD_AT24C01_Write(unsigned int Address,unsigned char Len,unsigned char*cData)功能:写AT24C32/64/128/256卡。
参数:
Address[Input]:开始地址
Len[Input]:写数据的长度。
*cData[Iutput]:要写到卡的数据。
2.5SLE4442/4432卡专用函数
2.5.1int_stdcall IFD_SLE4442_Reset(unsigned char*rData,unsigned char*rLen)
功能:复位SLE44x2卡
参数:
*rData[Output]:返回卡复位信息。
*rLen[Output]:rData的长度。
2.5.2int_stdcall IFD_SLE4442_Read(unsigned int Address,unsigned char Len,unsigned char*rData)功能:读SLE44x2卡主存储区数据
参数:
Address[Input]:开始地址
Len[Input]:长度
*rData[Output]:读到的卡数据,个数等于Len。
2.5.3int_stdcall IFD_SLE4442_Write(unsigned int Address,unsigned char Len,unsigned char*cData)功能:写数据到SLE44x2卡主存储区
参数:
Address[Input]:开始地址
Len[Input]:长度
*cData[Output]:要写到卡的数据,个数等于Len。
2.5.4int_stdcall IFD_SLE4442_Read_ProtectZone(unsigned int Address,unsigned char Len,unsigned char*rData)功能:读SLE44x2卡保护存储区数据
参数:
Address[Input]:开始地址
Len[Input]:长度
*rData[Output]:读到的卡数据,个数等于Len。
2.5.5int_stdcall IFD_SLE4442_Write_ProtectZone(unsigned int Address,unsigned char Len,unsigned char*cData)功能:写数据到SLE44x2卡保护存储区
参数:
Address[Input]:开始地址
Len[Input]:长度
*cData[Output]:要写到卡的数据,个数等于Len。
注:写保护存储区是一个不可逆的操作,将使部分主存储区的数据变成只读的,不可再更改,小心!
2.5.6int_stdcall IFD_SLE4442_Verify_PSC(unsigned char psc1,unsigned char psc2,unsigned char psc3)
功能:校验SLE4442卡密码
参数:psc1,psc2,psc3[Input]:3字节的卡密码
注:SLE4442卡必须校验密码成功才能进行写操作。
2.5.7int_stdcall IFD_SLE4442_Update_PSC(unsigned char psc1,unsigned char psc2,unsigned char psc3)
功能:更改SLE4442卡密码
参数:psc1,psc2,psc3[Input]:3字节的卡密码
注:SLE4442卡必须校验密码成功才能更改卡密码。
2.5.8int_stdcall IFD_SLE4442_Read_PSC(unsigned char*rPSC,unsigned char*rLen)
功能:读取SLE4442卡密码
参数:
*rPSC[Output]:读取的卡密码
*rLen[Output]:rPSC的长度。
注:SLE4442卡必须校验密码成功才能正确读取卡密码,否则读取来的将是0x000x000x00。
2.5.9int_stdcall IFD_SLE4442_Read_EC(unsigned char*rEC,unsigned char*rLen)
功能:读取SLE4442卡错误计数器
参数:
*rEC[Output]:读取的错误计数器数据
*rLen[Output]:rEC的长度,一般等于1。
2.5.10int_stdcall IFD_SLE4442_Update_EC(unsigned char EC)
功能:写SLE4442卡错误计数器
参数:rEC[Input]:错误计数器数据
注:如果SLE4442卡的错误计数器等于0,则整张卡被锁死,不能更改任何数据。所以更改错误计数器必须谨慎。
2.6SLE4428/4418卡专用函数
2.6.1int_stdcall IFD_SLE4428_Reset(unsigned char*rData,unsigned char*rLen)
功能:复位SLE4428/18卡
参数:
*rData[Output]:返回卡复位信息。
*rLen[Output]:rData的长度。
2.6.2int_stdcall IFD_SLE4428_Read(unsigned int Address,unsigned char Len,unsigned char*rData)
功能:读SLE4428/18卡数据
参数:
Address[Input]:开始地址
Len[Input]:长度
*rData[Output]:读到的卡数据,个数等于Len。
2.6.3int_stdcall IFD_SLE4428_Write(unsigned int Address,unsigned char Len,unsigned char*cData)功能:写数据到SLE4428/18卡
参数:
Address[Input]:开始地址
Len[Input]:长度
*cData[Output]:要写到卡的数据,个数等于Len。
2.6.4int_stdcall IFD_SLE4428_Read_PB(unsigned int Address,unsigned char Len,unsigned char*rData)
功能:SLE4428/18卡带保护位读操作
参数:
Address[Input]:开始地址
Len[Input]:长度
*rData[Output]:读到的卡数据,个数等于2*Len。rDtata[2*n]为卡数据,rDtata[2*n+1]为卡数据的保护状态,0表示受保护,不可更改(只读)。其它值表示没有被保护,数据可更改。
2.6.5int_stdcall IFD_SLE4428_Write_PB(unsigned int Address,unsigned char Len,unsigned char*cData)
功能:带保护位写数据到SLE4428/18卡,即写数据后将其变为只读的。
参数:
Address[Input]:开始地址
Len[Input]:长度
*cData[Output]:要写到卡的数据,个数等于Len。
2.6.6int_stdcall IFD_SLE4428_Compare_PB(unsigned int Address,unsigned char Len,unsigned char*cData)
功能:SLE4428/18卡比较数据操作,如输入数据与卡数据一致则将其变为只读的。
参数:
Address[Input]:开始地址
Len[Input]:长度
*cData[Output]:要比较的数据,个数等于Len。
2.6.7int_stdcall IFD_SLE4428_Verify_PSC(unsigned char psc1,unsigned char psc2)
功能:校验SLE4428卡密码
参数:psc1,psc2[Input]:2字节的卡密码
注:SLE4428卡必须校验密码成功才能进行写操作。
2.6.8int_stdcall IFD_SLE4428_Update_PSC(unsigned char psc1,unsigned char psc2)功能:更改SLE4428卡密码
参数:psc1,psc2[Input]:2字节的卡密码
注:SLE4428卡必须校验密码成功才能更改卡密码。
2.6.9int_stdcall IFD_SLE4428_Read_PSC(unsigned char*rPSC,unsigned char*rLen)功能:读取SLE4428卡密码
参数:
*rPSC[Output]:读取的卡密码
*rLen[Output]:rPSC的长度。
注:SLE4428卡必须校验密码成功才能读取正确的卡密码.
2.6.10int_stdcall IFD_SLE4428_Read_EC(unsigned char*rEC,unsigned char*rLen)功能:读取SLE4428卡错误计数器
参数:
*rEC[Output]:读取的错误计数器数据
*rLen[Output]:rEC的长度,一般等于1。
2.6.11int_stdcall IFD_SLE4428_Update_EC(unsigned char EC)
功能:写SLE4428卡错误计数器
参数:rEC[Input]:错误计数器数据
注:如果SLE4428卡的错误计数器等于0,则整张卡被锁死,不能更改任何数据。所以更改错误计数器必须谨慎。
3返回状态/错误代码
#define CODE_OK0x00//成功
#define CODE_ParaErr0x11//命令或参数错
#define CODE_NOICC0x12//当前卡座没卡
#define CODE_NOPOWER0x13//当前卡没上电
#define CODE_ApduLenErr0x14//CPU卡操作时APDU长度出错#define CODE_ERRACCESS0x15//卡操作出错
#define CODE_LOCKEDICC0x16//卡已锁死
#define CODE_ERRPSC0x17//卡密码错
#define Code_TimeoutErr0xFF//通讯超时
#define Code_RetFrameErr0xFE//读卡器返回数据包出错
#define Code_SetCommPortErr0xFD//打开通讯端口出错
附录:SLE4442卡读流程
void main()
{
unsigned char status;
unsigned char buff[256];
unsigned char len;
//初始化通讯端口
status=IFD_InitComm("COM1",9600);
if(status)
{
//printf("打开COM1出错");
return;
}
//查询是否插卡
while(1)
{
stu=IFD_Get_CardStatus(buff,&len);
if(stu)return;
if(bff[0]!=0)break;//主IC卡座有插卡,去下一步操作
}
//选择主卡座为当前卡座
status=IFD_Select_ICC(0);//读卡器在默认状态下,当前卡座为主卡座,可省略这一步if(status)return;