📄 rfid.cpp
字号:
#include "StdAfx.h"
#include "RFID.h"
#include "XCRF500API.h"
CRFID::CRFID(void)
{
m_hCom = INVALID_HANDLE_VALUE;
}
CRFID::~CRFID(void)
{
}
bool CRFID::Open(void)
{
if(m_hCom != INVALID_HANDLE_VALUE)
{
return false;
}
CString strCfgFileName;
strCfgFileName = "C:\\SYSIT.CFG";
int iResult = XCOpen(m_hCom, strCfgFileName, "XCRF-500W SCANER");
if(iResult != 1)
{
MessageBox(NULL, "与读写器建立通讯通路失败!", "错误", MB_OK);
return false;
}
iResult = XCPowerOn(m_hCom);
if(iResult != 1)
{
Close();
return false;
}
// iResult = XCReset(m_hCom);
// if(iResult == 0)
// {
// return false;
// }
return true;
}
bool CRFID::Close(void)
{
if(m_hCom == INVALID_HANDLE_VALUE)
{
return false;
}
int iResult = XCPowerOff(m_hCom);
if(iResult != 1)
{
return false;
}
iResult = XCClose(m_hCom);
if(iResult == 1)
{
m_hCom = INVALID_HANDLE_VALUE;
return true;
}
else
{
return false;
}
}
bool CRFID::ReadID(CString& strCardID)
{
unsigned char uTagType = 1;//卡的类型
unsigned char ucAntenna = 0;//天线号
unsigned char ucScanTimes = 0;//
int iResult;
unsigned char newData[11];
iResult = XCIdentify(m_hCom,
uTagType,
ucAntenna,
ucScanTimes);
if(iResult == 0)
{
return false;
}
iResult = XCReport(m_hCom, newData);
if(iResult == 0 || iResult == -1 || newData[2] != 0x01) //读取失败
{
//返回1代表失败
return false;
}
strCardID = "";
CString temp;
for(int i=3;i<11;i++)
{
temp.Format("%2x",newData[i]);
strCardID += temp;
}
//返回0代表获取ID成功
return true;
}
void CRFID::Clear()
{
unsigned char uTagType = 1;//卡的类型
unsigned char ucAntenna = 0;//天线号
unsigned char ucScanTimes = 0;//
int iResult;
unsigned char newData[11];
while(1)
{
iResult = XCIdentify(m_hCom,
uTagType,
ucAntenna,
ucScanTimes);
if(iResult == 0)
{
return;
}
iResult = XCReport(m_hCom, newData);
if(iResult == 0 || iResult == -1 || newData[2] != 0x01)
{
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -