烏班圖(ubuntu )Linux系統(tǒng)身份證閱讀器開發(fā)包(含libwlt2bmp.so身份證相片解碼)
Ubuntu(友幫拓、優(yōu)般圖、烏班圖)是一個以桌面應(yīng)用為主的開源GNU/Linux操作系統(tǒng),Ubuntu 是基于Debian GNU/Linux,支持x86、amd64(即x64)和ppc架構(gòu),由全球化的專業(yè)開發(fā)團隊(Canonical Ltd)打造的。
注意:
此Linux版本是我公司最新的采用USB接口通訊的開發(fā)包,更新了最新的libwlt2bmp.so相片解碼庫,完美支持Linux系統(tǒng),涵蓋了身份證、M1、CPU、IC等多種卡片的Linux系統(tǒng)應(yīng)用示例,包括了身份證相片解碼。
廣東東信智能科技有限公司身份證閱讀器模組模塊,支持身份證、社??āPU卡、M1卡、IC卡、醫(yī)???、磁條卡、銀行卡等多種卡片識別讀取,提供完善的接口SDK二次開發(fā)技術(shù)支持,可提供Linux、單片機、ARM的通訊協(xié)議以及Android、Windows等系統(tǒng)二次開發(fā)包,可以適用于市場上的閘機、門禁、人臉識別考勤機、機器人終端、通道閘等產(chǎn)品使用。
版本:V2018.09.25(USB版本)
應(yīng)用產(chǎn)品:門禁系統(tǒng)、道閘、考勤系統(tǒng)以及人臉識別系統(tǒng)、自助終端、機器人系統(tǒng)等。
Linux身份證閱讀器部分開發(fā)代碼:
#include "../inc/est100.h"
#include <string.h>
#include <stdio.h>
static long handle;
//print a line of characters
static void printchar(char ch, int len)
{
while(len--)
{
printf("%c", ch);
}
printf("\n");
}
static void printchar_txt(char ch, char *pText)
{
printf("%c\t%s\n", ch, pText);
}
static void printByteArray(char *Tag, unsigned char *pSrc, int ilen)
{
inti = 0;
printf( "%s", Tag );
while( i<ilen )
{
printf( "%02X ", pSrc[i] );
i++;
}
printf( "\n" );
}
static void ShowToEdit(const char* tag, const char* msg)
{
printf( "%s\t%s\n", tag, msg );
}
static void CertCard_Test()
{
intnRt, i;
char pName[70]={0};
char pSex[10]={0};
char pNation[10]={0};
char pBirth[50]={0};
char pAddress[100]={0};
char pCertNo[50]={0};
char pDepartment[100]={0};
char pEffectData[50]={0};
char pExpire[20]={0};
char pErrMsg[50]={0};
char pEnName[150] = { 0 };
char pEnNation[50] = { 0 };
char pAuthorCode[150] = { 0 };
char pCardVersion[150] = { 0 };
char pTXZHM[50] = { 0 };
char pTXZQFCS[10] = { 0 };
nRt = PICC_ReadIDCard(handle);
if ( nRt != 0 )
{
printf( "ReadCertCard fail! nRet=%d\n", nRt );
return;
}
if(GetCardType() == 0)
{
GetName(pName);
GetSex(pSex);
GetNation(pNation);
GetBirth(pBirth);
GetAddress(pAddress);
GetCertNo(pCertNo);
GetDepartemt(pDepartment);
GetEffectDate(pEffectData);
GetExpireDate(pExpire);
ShowToEdit( "姓名:", (pName));
ShowToEdit( "性別:", (pSex));
ShowToEdit( "民族:", (pNation));
ShowToEdit( "出生日期:", (pBirth));
ShowToEdit( "地址:", (pAddress));
ShowToEdit( "身份證號:", (pCertNo));
ShowToEdit( "簽發(fā)機關(guān):", (pDepartment));
ShowToEdit( "有效起始日期:", (pEffectData));
ShowToEdit( "有效截止日期:", (pExpire));
}
if(GetCardType() == 1)
{
GetName(pName);
GetEnName(pEnName);
GetSex(pSex);
GetNationalityCode(pEnNation);
GetBirth(pBirth);
GetCertNo(pCertNo);
GetEffectDate(pEffectData);
GetExpireDate(pExpire);
GetCardVersion(pCardVersion);
ShowToEdit( "中文姓名:", (pName));
ShowToEdit( "英文姓名:", (pEnName));
ShowToEdit( "性別:", (pSex));
ShowToEdit( "國籍代碼:", (pEnNation));
ShowToEdit( "永久居留證號碼:", (pCertNo));
ShowToEdit( "出生日期:", (pBirth));
ShowToEdit( "證件簽發(fā)日期:", (pEffectData));
ShowToEdit( "證件終止日期:", (pExpire));
ShowToEdit( "證件版本:", (pCardVersion));
}
if(GetCardType() == 2)
{
GetName(pName);
GetSex(pSex);
GetBirth(pBirth);
GetAddress(pAddress);
GetCertNo(pCertNo);
GetDepartemt(pDepartment);
GetEffectDate(pEffectData);
GetExpireDate(pExpire);
GetTXZHM(pTXZHM);
GetTXZQFCS(pTXZQFCS);
ShowToEdit( "姓名:", (pName));
ShowToEdit( "性別:", (pSex));
ShowToEdit( "出生日期:", (pBirth));
ShowToEdit( "地址:", (pAddress));
ShowToEdit( "身份證號:", (pCertNo));
ShowToEdit( "簽發(fā)機關(guān):", (pDepartment));
ShowToEdit( "有效起始日期:", (pEffectData));
ShowToEdit( "有效截止日期:", (pExpire));
ShowToEdit( "通行證號碼:", (pTXZHM));
ShowToEdit( "通行證簽發(fā)次數(shù):", (pTXZQFCS));
}
char szPhotoPath[255] = { 0 };
sprintf(szPhotoPath, "../list/%s.bmp", pCertNo);
GetBmpFile("../lib/libwltdecode.so", szPhotoPath);
}
static void ICC_CPUCard_Test()
{
intnRt, i;
unsigned char slot = 0x01;
unsigned char cmd[255] = { 0 };
unsigned charresp[255]= { 0 };
unsigned charATR[60] = { 0 };
intlenth_of_cmd;
// Get 8 byte Random
cmd[0] = 0x00;
cmd[1] = 0x84;
cmd[2] = 0x00;
cmd[3] = 0x00;
cmd[4] = 0x08;
lenth_of_cmd = 5;
//CPU Card PowerOn
nRt = ICC_Reader_pre_PowerOn( handle, slot, resp );
if( nRt < 0 )
{
printf( "CPU Card PowerOn fail! ret=%d\n", nRt );
return;
}
printByteArray( "ATR: ", resp, nRt );
printByteArray( "CMD: ", cmd, lenth_of_cmd );
//Send APDU CMD
memset( resp, 0, 250 );
nRt = ICC_Reader_Application( handle, slot, lenth_of_cmd, cmd, resp );
if( nRt < 0 )
{
printf( "send APDU CMD fail! ret=%d\n", nRt );
return;
}
printByteArray( "Resp: ", resp, nRt );
}
static void PICC_CPUCard_Test()
{
int nRt, i;
unsigned char uid[15] = { 0 };
unsigned char cmd[255] = { 0 };
unsigned char resp[255]= { 0 };
unsigned char ATR[60] = { 0 };
int lenth_of_cmd;
// Get 8 byte Random
cmd[0] = 0x00;
cmd[1] = 0x84;
cmd[2] = 0x00;
cmd[3] = 0x00;
cmd[4] = 0x08;
lenth_of_cmd = 5;
//CPU Card PowerOn
if( PICC_Reader_SetTypeA( handle ) != 0 )
{
printf( "PICC_Reader_SetTypeA fail! ret=%d\n", nRt );
return;
}
if( PICC_Reader_Request( handle ) != 0 )
{
printf( "PICC_Reader_Request fail! ret=%d\n", nRt );
return;
}
if( PICC_Reader_anticoll( handle, uid ) != 0 )
{
printf( "PICC_Reader_anticoll fail! ret=%d\n", nRt );
return;
}
if( PICC_Reader_Select( handle, 0x41 ) != 0 )
{
printf( "PICC_Reader_Select fail! ret=%d\n", nRt );
return;
}
nRt = PICC_Reader_PowerOnTypeA( handle, resp );
if( nRt < 0 )
{
printf( "TypeA CPU Card PowerOn fail! ret=%d\n", nRt );
return;
}
printByteArray( "ATR: ", resp, nRt );
printByteArray( "CMD: ", cmd, lenth_of_cmd );
memset( resp, 0, 250 );
nRt = PICC_Reader_Application( handle, lenth_of_cmd, cmd, resp );
if( nRt < 0 )
{
printf( "send APDU CMD fail! ret=%d\n", nRt );
return;
}
printByteArray( "Resp: ", resp, nRt );
}
static void M1Card_Test()
{
int nRt, i;
unsigned char uid[15]= { 0 };
unsigned char password[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
unsigned char resp[255]= { 0 };
unsigned charaddr= 0x04;
unsigned charsncr= 0x01;
unsigned charmode= 0x61;
//CPU Card PowerOn
if( PICC_Reader_SetTypeA( handle ) != 0 )
{
printf( "PICC_Reader_SetTypeA fail! ret=%d\n", nRt );
return;
}
if( PICC_Reader_Request( handle ) != 0 )
{
printf( "PICC_Reader_Request fail! ret=%d\n", nRt );
return;
}
if( PICC_Reader_anticoll( handle, uid ) != 0 )
{
printf( "PICC_Reader_anticoll fail! ret=%d\n", nRt );
return;
}
if( PICC_Reader_Select( handle, 0x41 ) != 0 )
{
printf( "PICC_Reader_Select fail! ret=%d\n", nRt );
return;
}
printByteArray( "UID: ", uid, 4 );
nRt = PICC_Reader_Authentication_Pass( handle, mode, sncr, password );
if ( nRt != 0 )
{
printf( "PICC_Reader_Authentication_Pass fail! ret=%d\n", nRt );
return;
}
nRt = PICC_Reader_Read( handle, addr, resp );
if( nRt != 0 )
{
printf( "PICC_Reader_Read fail! ret=%d\n", nRt );
return;
}
printByteArray( "Data: ", resp, 16 );
}
int main(void)
{
long nRt;
intnval;
handle = ICC_Reader_Open( "USB1" );
if( handle < 0 )
{
printf( "open fail! \n" );
return 0;
}
printchar( '#', 80 );
printchar_txt( '#', "please choose the action you want:" );
printchar_txt( '#', "1.Select ICC CPU Card." );
printchar_txt( '#', "2.Select PICC CPU(A) Card." );
printchar_txt( '#', "3.Select M1 Card." );
printchar_txt( '#', "4.Select CertCard." );
printchar( '#', 80 );
scanf( "%d", &nval );
switch( nval )
{
case 1:
{
printf( "\tICC_CPU_CARD.\n" );
ICC_CPUCard_Test();
}
break;
case 2:
{
printf( "\tPICC_CPU(A)_CARD.\n" );
PICC_CPUCard_Test();
}
break;
case 3:
{
printf( "\tM1_CARD.\n" );
M1Card_Test();
}
break;
case 4:
{
printf( "\tCertCard.\n" );
CertCard_Test();
}
break;
default:
printf( "enter err!\n" );
break;
}
ICC_PosBeep( handle, 10 );
ICC_Reader_Close(handle);
return 0;
}