代码拉取完成,页面将自动刷新
// D8ReaderBeijing.cpp: implementation of the D8ReaderBeijing class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "D8ReaderBeijing.h"
#include "Function.h"
#include "D6脚本执行Dlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define HANG_TIME 7
extern CEditListCtrlEx *g_list;
D8ReaderBeijing::D8ReaderBeijing(int readerPort)
{
int dllNo = 1;
CString strLibName;
strLibName.Format(".\\dcrf32lib\\dcrf32_%d.dll", dllNo);
m_DllHandle = LoadLibrary(strLibName);
m_ReaderPort = readerPort;
m_hReader = NULL;
m_line = -1;
}
D8ReaderBeijing::~D8ReaderBeijing()
{
// G3_Close();
// FreeLibrary(m_DllHandle);
}
FARPROC D8ReaderBeijing::loadFun(CString FunName)
{
if(m_DllHandle == NULL) {
return 0;
}
FARPROC theFun;
theFun=GetProcAddress(m_DllHandle, FunName);
if(!theFun) {
return 0;
}
return theFun;
}
BOOL D8ReaderBeijing::loadFunAll(int readerPort) {
f_dc_init = (DC_init)loadFun("dc_init");
if(!f_dc_init) {
return FALSE;
}
f_dc_exit = (DC_exit)loadFun("dc_exit");
if(!f_dc_exit) {
return FALSE;
}
f_dc_reset = (DC_reset)loadFun("dc_reset");
if(!f_dc_reset) {
return FALSE;
}
f_dc_halt = (DC_halt)loadFun("dc_halt");
if(!f_dc_halt) {
return FALSE;
}
f_dc_card_hex = (DC_card_hex)loadFun("dc_card_hex");
if(!f_dc_card_hex) {
return FALSE;
}
f_dc_pro_reset_hex = (DC_pro_reset_hex)loadFun("dc_pro_reset_hex");
if(!f_dc_pro_reset_hex) {
return FALSE;
}
f_dc_pro_command_hex = (DC_pro_command_hex)loadFun("dc_pro_command_hex");
if(!f_dc_pro_command_hex) {
return FALSE;
}
f_a_hex = (A_hex)loadFun("a_hex");
if(!f_a_hex) {
return FALSE;
}
f_dc_beep = (DC_beep)loadFun("dc_beep");
if(!f_dc_beep) {
return FALSE;
}
f_dc_cpuapduEXT_hex = (DC_cpuapduEXT_hex)loadFun("dc_cpuapduEXT_hex");
if(!f_dc_cpuapduEXT_hex) {
return FALSE;
}
f_dc_pro_commandlinkEXT_hex = (DC_pro_commandlinkEXT)loadFun("dc_pro_commandlinkEXT_hex");
if (!f_dc_pro_commandlinkEXT_hex){
return FALSE;
}
return TRUE;
}
BOOL D8ReaderBeijing::G3_Open(int iPort)
{
if(!loadFunAll(100)) {
return -1;
}
m_hReader = f_dc_init(m_ReaderPort, 115200);
if (FAILED(m_hReader))
{
m_hReader = NULL;
MessageBox(NULL, "打开读卡器失败", "提示", MB_OK);
return -2;
}
return 0;
}
void D8ReaderBeijing::G3_Close()
{
if (m_hReader != NULL)
{
if(0 == f_dc_exit(m_hReader)) {
m_hReader = NULL;
return;
}
}
m_hReader = NULL;
return;
}
int D8ReaderBeijing::getReaderStatus()
{
int result = f_dc_reset(m_hReader, 1);
if(result != 0) {
return result;
}
result = f_dc_card_hex(m_hReader, 0, m_snr);
return result;
}
int D8ReaderBeijing::G3_Reset(DWORD &len,LPBYTE resp)
{
m_line++;
g_list->InsertItem(m_line,DecToCStr(m_line)); //
g_list->SetItemText(m_line,1,"reset");
int result = f_dc_reset(m_hReader, 1);
if(result != 0) {
strcpy((char*)m_SW, "0000");
m_pCardApduLog->setTransmitApdu("reset", "error!");
g_list->SetItemText(m_line,2,"f_dc_reset error!"); //
return result;
}
unsigned char rLen = 0;
memset(m_snr, 0, sizeof(m_snr));
result = f_dc_card_hex(m_hReader, 0, m_snr);
if(result != 0) {
strcpy((char*)m_SW, "0000");
m_pCardApduLog->setTransmitApdu("reset", "error!");
g_list->SetItemText(m_line,2,"寻卡失败!");
return result;
}
result = f_dc_pro_reset_hex(m_hReader, &rLen, (char *)m_RespBuf);
m_RespBuf[rLen*2] = '\0';
m_pCardApduLog->setTransmitApdu("reset", CString(m_snr) + "," + (const char*)m_RespBuf);
len = rLen;
hexStrToHexBuf((const char*)m_RespBuf,rLen*2,resp);
if(result == 0) {
g_list->SetItemText(m_line,2,"9000");
g_list->SetItemText(m_line,3,"snr:" + CString(m_snr) + " ats:" + CString(m_RespBuf));
strcpy((char*)m_SW, "9000");
} else {
strcpy((char*)m_SW, "0000");
}
return result;
}
int D8ReaderBeijing::G3_APDU(DWORD &len,LPBYTE comm)
{
m_line++;
unsigned int rLen = 0;
char apdu[800] = {0};
hexBufToHexStr(comm,len,apdu);
g_list->InsertItem(m_line,DecToCStr(m_line)); //
g_list->SetItemText(m_line,1,apdu);
unsigned char fg = 64;
if(0 != f_dc_pro_commandlinkEXT_hex(m_hReader, strlen(apdu)/2, (unsigned char *)apdu, &rLen,
(unsigned char *)m_RespBuf, HANG_TIME,fg)) {
strcpy((char*)m_SW, "FD00");
m_pCardApduLog->setTransmitApdu(apdu, (const char*)m_SW);
g_list->SetItemText(m_line,2,"FD00");
return 0xFD00;
}
m_RespBuf[rLen*2] = '\0';
m_pCardApduLog->setTransmitApdu(apdu, (const char*)m_RespBuf);
int swOff = rLen*2 - 4;
memcpy(m_SW, &m_RespBuf[swOff], 4);
m_SW[4] = '\0';
unsigned char sw1sw2Buf[5];
f_a_hex(&m_RespBuf[swOff], sw1sw2Buf, 4);
m_RespBuf[swOff] = '\0';
len = rLen-2;
hexStrToHexBuf((const char *)m_RespBuf,len*2,comm);
g_list->SetItemText(m_line,3,(char *)m_RespBuf);
g_list->SetItemText(m_line,2,(char *)m_SW);
g_list->EnsureVisible(m_line,TRUE);
DWORD sw = 0;
sw = MAKEWORD(sw1sw2Buf[1], sw1sw2Buf[0]);
if(sw == 0x9000) {
return 0;
} else {
return sw;
}
}
int D8ReaderBeijing::G3_Command(DWORD &nCosLen,BYTE *pCosCmd)
{
DWORD srclen=nCosLen;
nCosLen=0;
BYTE *src=pCosCmd;
while(1)
{
int ret=G3_APDU(srclen,pCosCmd);
if(ret==0)
{
pCosCmd+=srclen;
nCosLen+=srclen;
pCosCmd[0]=0x90;
pCosCmd[1]=0x00;
nCosLen+=2;
} else if((HIBYTE(ret)==0x61)&&(LOBYTE(ret)!=0x00)) {
pCosCmd+=srclen;
nCosLen+=srclen;
memcpy(pCosCmd,"\x00\xc0\x00\x00",4);
pCosCmd[4]=LOBYTE(ret);
srclen=5;
//continue;
} else {
pCosCmd+=srclen;
nCosLen+=srclen;
pCosCmd[0]=HIBYTE(ret);
pCosCmd[1]=LOBYTE(ret);
nCosLen+=2;
}
return ret;
}
}
void D8ReaderBeijing::G3_setReadHand(HANDLE hread)
{
m_hReader = hread;
}
/*
int __stdcall CardReset(int sChannelID,DWORD &nCosLen,BYTE *pCosCmd)
{
D8ReaderBeijing *pReader=(D8ReaderBeijing*)sChannelID;
return pReader->G3_Reset(nCosLen,pCosCmd);
}
int __stdcall CardCommand(int sChannelID,DWORD &nCosLen,BYTE *pCosCmd)
{
D8ReaderBeijing *pReader=(D8ReaderBeijing*)sChannelID;
return pReader->G3_Command(nCosLen,pCosCmd);
}
int __stdcall IcLock()
{
return 0;
}
int __stdcall IcUnLock()
{
return 0;
}*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。