EST系列身份證閱讀器讀卡器Python語言二次開發demo上線
人工智能的興起,最近這段時間碰到很多開發工程師咨詢Python語言二次開發使用身份證閱讀器的問題,這次特增加了Python語言的demo,供大家參考使用。
Python讀取身份證示例圖
1.說明:
appMain.py為程序主文件,運行工程源程序必須安裝python3+PyQt5運行環境,依賴庫dll必須與源程序同一路徑。
2.命令行中執行:
python3 appMain.py
3.支持的型號:
EST-100、EST-100GS、EST-100G、EST-100U、EST-200G、EST-J13X等系列身份證社??ㄗx卡器
4、開發包下載地址:
http://www.eastcoms.com/service/downdrive/561.html
Python部分代碼:
#-*- coding : utf-8-*-
import sys
from ctypes import *
id_dev_name = b"USB1"
dll_path = './est64.dll'
id_image_path = './zp.bmp'
pBmpFile = c_char_p(b'/0'*100)
#pFingerData = c_char_p(b'/0'*1025)
#pBmpData = c_char_p(b'/0'*77725)
#pBase64Data = c_char_p(b'/0'*6025)
pName = c_char_p(b'/0'*100)
pSex = c_char_p(b'/0'*100)
pNation = c_char_p(b'/0'*100)
pBirth = c_char_p(b'/0'*100)
pAddress = c_char_p(b'/0'*100)
pCertNo = c_char_p(b'/0'*100)
pDepartment = c_char_p(b'/0'*100)
pEffectData = c_char_p(b'/0'*100)
pExpire = c_char_p(b'/0'*100)
pData = c_char_p(b'/0'*100)
pErrMsg = c_char_p(b'/0'*100)
pTXZHM = c_char_p(b'/0'*100)
pTXZQFCS = c_char_p(b'/0'*100)
pEnName = c_char_p(b'/0'*200)
pEnNation = c_char_p(b'/0'*100)
pAuthorCode = c_char_p(b'/0'*100)
pCardVersion = c_char_p(b'/0'*100)
pErrMsg = c_char_p(b'/0'*100)
class idreader(object):
def __init__(self, parent=None):
self.dev_name = c_char_p(id_dev_name)
self.id_dev = CDLL(dll_path)
self.id_handle = self.id_dev.EU_Reader_Open(self.dev_name)
def get_msg(self):
global pBmpFile,pName,pSex,\
pNation,pBirth,pAddress,pCertNo,pDepartment,pEffectData,\
pExpire,pData,pErrMsg,pTXZHM,pTXZQFCS,pEnName,pEnNation,\
pAuthorCode,pCardVersion
#pFingerData,pBmpData,pBase64Data,
pBmpFile.value = bytes(id_image_path,encoding="utf8")
id_msg_str = ""
self.id_handle = self.id_dev.EU_Reader_Open(self.dev_name)
if self.id_handle <= 0:
print('reader port open failure.')
return (self.id_handle,)
sUID = c_char_p(b'/0'*30)
self.id_dev.PEU_Reader_ID_ReadUID(self.id_handle, sUID)
ret = self.id_dev.PEU_Reader_ReadIDCard(self.id_handle, pErrMsg)
if ret == 0:
idcardType = int(-1)
idcardType = self.id_dev.GetCardType()
if idcardType == 0:
id_msg_str = "證件類型:居民身份證" + "\r\n"
self.id_dev.GetName(pName)
id_msg_str += "姓名:" + str(pName.value,encoding='gbk') + "\r\n"
self.id_dev.GetSex(pSex)
id_msg_str += "性別:" + str(pSex.value,encoding='gbk') + "\r\n"
self.id_dev.GetNation(pNation)
id_msg_str += "民族:" + str(pNation.value,encoding='gbk') + "\r\n"
self.id_dev.GetBirth(pBirth)
id_msg_str += "出生日期:" + str(pBirth.value,encoding='gbk') + "\r\n"
self.id_dev.GetAddress(pAddress)
id_msg_str += "住址:" + str(pAddress.value,encoding='gbk').strip() + "\r\n"
self.id_dev.GetCertNo(pCertNo)
id_msg_str += "身份證號碼:" + str(pCertNo.value,encoding='gbk') + "\r\n"
self.id_dev.GetDepartemt(pDepartment)
id_msg_str += "簽發機關:" + str(pDepartment.value,encoding='gbk') + "\r\n"
self.id_dev.GetEffectDate(pEffectData)
id_msg_str += "有效起始日期:" + str(pEffectData.value,encoding='gbk') + "\r\n"
self.id_dev.GetExpireDate(pExpire)
id_msg_str += "有效截止日期:" + str(pExpire.value,encoding='gbk') + "\r\n"
elif idcardType == 1:
id_msg_str = "證件類型:外國人永久居留證" + "\r\n"
self.id_dev.GetName(pName)
id_msg_str += "中文姓名:" + str(pName.value,encoding='gbk') + "\r\n"
self.id_dev.GetEnName(pEnName)
id_msg_str += "英文姓名:" + str(pEnName.value,encoding='gbk')
self.id_dev.GetSex(pSex)
id_msg_str += "性別:" + str(pSex.value,encoding='gbk')
self.id_dev.GetNationalityCode(pEnNation)
id_msg_str += "國籍代碼:" + str(pEnNation.value,encoding='gbk') + "\r\n"
self.id_dev.GetBirth(pBirth)
id_msg_str += "出生日期:" + str(pBirth.value,encoding='gbk') + "\r\n"
self.id_dev.GetCertNo(pCertNo)
id_msg_str += "永久證號碼:" + str(pCertNo.value,encoding='gbk') + "\r\n"
self.id_dev.GetEffectDate(pEffectData)
id_msg_str += "有效起始日期:" + str(pEffectData.value,encoding='gbk') + "\r\n"
self.id_dev.GetExpireDate(pExpire)
id_msg_str += "有效截止日期:" + str(pExpire.value,encoding='gbk') + "\r\n"
elif idcardType == 2:
id_msg_str = "證件類型:港澳臺居民居住證" + "\r\n"
self.id_dev.GetName(pName)
id_msg_str += "姓名:" + str(pName.value,encoding='gbk') + "\r\n"
self.id_dev.GetSex(pSex)
id_msg_str += "性別:" + str(pSex.value,encoding='gbk') + "\r\n"
self.id_dev.GetBirth(pBirth)
id_msg_str += "出生日期:" + str(pBirth.value,encoding='gbk') + "\r\n"
self.id_dev.GetCertNo(pCertNo)
id_msg_str += "身份證號碼:" + str(pCertNo.value,encoding='gbk') + "\r\n"
self.id_dev.GetAddress(pAddress)
id_msg_str += "住址:" + str(pAddress.value,encoding='gbk').strip() + "\r\n"
self.id_dev.GetDepartemt(pDepartment)
id_msg_str += "簽發機關:" + str(pDepartment.value,encoding='gbk') + "\r\n"
self.id_dev.GetEffectDate(pEffectData)
id_msg_str += "有效起始日期:" + str(pEffectData.value,encoding='gbk') + "\r\n"
self.id_dev.GetExpireDate(pExpire)
id_msg_str += "有效截止日期:" + str(pExpire.value,encoding='gbk') + "\r\n"
self.id_dev.GetTXZHM(pTXZHM)
id_msg_str += "通行證號碼:" + str(pTXZHM.value,encoding='gbk') + "\r\n"
self.id_dev.GetTXZQFCS(pTXZQFCS)
id_msg_str += "通行證簽發次數:" + str(pTXZQFCS.value,encoding='gbk') + "\r\n"
else:
print("id card read failure.")
return (idcardType,)
img = self.id_dev.GetBmpFile(pBmpFile);
self.id_dev.EU_PosBeep(self.id_handle, 0x30);
return (ret,id_msg_str,img,id_image_path)
else:
print('PEU_Reader_ReadIDCard error.')
return (ret,)
def get_uid(self):
uid_pstr = c_char_p(b'/0'*20)
self.id_handle = self.id_dev.EU_Reader_Open(self.dev_name)
ret = self.id_dev.PEU_Reader_ID_ReadUID(self.id_handle,uid_pstr)
if ret == 0:
self.id_dev.EU_PosBeep(self.id_handle, 0x30);
uid_str = str(uid_pstr.value,encoding='utf-8')
return (ret,uid_str)
if __name__ == "__main__":
idcard = idreader()
uid=idcard.get_uid()
print('id card uid=')
print(uid)
id_msg = idcard.get_msg()
print('id card message:')
print(id_msg)
特別注意:
本Python方案用于規范支持的型號有:EST-100、EST-100GS、EST-100G、EST-100U、EST-200G、EST-J13X等系列身份證閱讀器機型。
以下型號第二代身份證閱讀器(讀卡器)未經深度測試,不一定支持使用。
如:千景J15S、千景HD-900、華旭HX-FDX3S、神思SS628(100)、新中新DKQ-A16D、中控ID100、華視CVR-100UC、華視CVR-100UA、精倫IDR210、國騰GTICR100、普天CP IDMR02/TG/ZW、神盾ICR-100U、ICR-100M、昌茂CM008等等等……