📄 writepage.cpp
字号:
// WritePage.cpp : implementation file
//
#include "stdafx.h"
#include "RFID.h"
#include "WritePage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWritePage property page
IMPLEMENT_DYNCREATE(CWritePage, CPropertyPage)
CWritePage::CWritePage() : CPropertyPage(CWritePage::IDD)
{
//{{AFX_DATA_INIT(CWritePage)
m_WriteData = _T("");
//}}AFX_DATA_INIT
}
CWritePage::~CWritePage()
{
}
void CWritePage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWritePage)
DDX_Control(pDX, IDC_WriteBlkList10, m_WriteBlkList10);
DDX_Control(pDX, IDC_WriteBlkList, m_WriteBlkList);
DDX_Text(pDX, IDC_EDIT1, m_WriteData);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWritePage, CPropertyPage)
//{{AFX_MSG_MAP(CWritePage)
ON_BN_CLICKED(IDC_WriteAFI, OnWriteAFI)
ON_BN_CLICKED(IDC_WriteDSFID, OnWriteDSFID)
ON_BN_CLICKED(IDC_LockAFI, OnLockAFI)
ON_BN_CLICKED(IDC_LockDSFID, OnLockDSFID)
ON_BN_CLICKED(IDC_WriteBlock, OnWriteBlock)
ON_BN_CLICKED(IDC_LockBlock, OnLockBlock)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWritePage message handlers
BOOL CWritePage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CheckRadioButton(IDC_TI,IDC_Philips,IDC_Philips);
TCHAR* strNum[] ={L"0",L"1",L"2",L"3",L"4",L"5",L"6",L"7",L"8",
L"9"};
TCHAR* strNum10[] ={L"0",L"1",L"2"};
for(int i = 0 ; i<10;i++)
{
m_WriteBlkList.AddString(*(strNum+i));
if(i<3)
{
m_WriteBlkList10.AddString(*(strNum10+i));
}
}
m_WriteBlkList.SetCurSel(0);
m_WriteBlkList10.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CWritePage::OnWriteAFI()
{
if(fOpenDev==0&&fContinueMode ==false)
{
UpdateData(true);//update for input
if(m_WriteData.GetLength()>0)
{
CString uid;
int fWriteAFI=0;
CString ResFlag;
//get card uid for function
//send request
Amic_GetCardUIDRequest();
Sleep(100);
uid = Amic_GetUID();
//clear all data
if(uid.GetLength()>0)
{
Amic_ClearAll15693Data();
int ntype =CheckTagType();//get Tag type
// ResFlag = Amic_GetResponseFlag();
// AfxMessageBox(ResFlag);
fWriteAFI = Amic_WriteAFIRequest(ntype,ChangeStrToInt(m_WriteData) ,false,uid);
if(fWriteAFI==0)
AfxMessageBox(L"Write OK");
else
AfxMessageBox(L"Write Error");
//clear all 15693 data
Amic_ClearAll15693Data();
uid ="";
}
else
AfxMessageBox(L"Can't Find the Tag");
}
}
}
int CWritePage::CheckTagType()
{
switch(GetCheckedRadioButton(IDC_TI,IDC_Philips))
{
case IDC_TI:
return TAG_TYPE_TI;
break;
case IDC_AMIC:
return TAG_TYPE_AMIC;
break;
case IDC_Philips:
return TAG_TYPE_PHILIPS;
break;
default:
return TAG_TYPE_PHILIPS;
}
return 0;
}
int CWritePage::ChangeStrToInt(CString data)
{
UpdateData(true);
CHAR buff[MAX_PATH];
for(int i = 0; i<data.GetLength(); i++)
{
buff[i] = (CHAR)data[i];
}
return atoi(buff);
}
void CWritePage::OnWriteDSFID()
{
if(fOpenDev==0&&fContinueMode ==false)
{
UpdateData(true);//update for input
if(m_WriteData.GetLength()>0)
{
CString uid;
//get card uid for function
//init
//send request
Amic_GetCardUIDRequest();
Sleep(100);
uid = Amic_GetUID();
//clear all data
if(uid.GetLength()>0)
{
Amic_ClearAll15693Data();
int ntype =CheckTagType();//get Tag type
int fWriteDSFID = Amic_WriteDSFIDRequest(ntype,ChangeStrToInt(m_WriteData),false,uid);
if(fWriteDSFID==0)
AfxMessageBox(L"Write OK");
else
AfxMessageBox(L"Write Error");
//clear all 15693 data
Amic_ClearAll15693Data();
uid ="";
}else{AfxMessageBox(L"Can't Find the Tag");}
}
}
}
void CWritePage::OnLockAFI()
{
if(fOpenDev==0&&fContinueMode ==false)
{
int HndLock=MessageBox(L"LOCK THE AFI? You can't unlock if locked",L"RFIDDemo",MB_YESNOCANCEL|MB_ICONASTERISK);
if(HndLock==IDYES)
{
CString uid;
//get card uid for function
//send request
Amic_GetCardUIDRequest();
uid = Amic_GetUID();
//clear all data
Amic_ClearAll15693Data();
int ntype =CheckTagType();//get Tag type
int fLockAFI= Amic_LockAFIRequest(ntype,false,uid);
if(fLockAFI==0)
AfxMessageBox(L"Lock OK");
else
AfxMessageBox(L"Lock Error");
//clear all 15693 data
Amic_ClearAll15693Data();
}
}
}
void CWritePage::OnLockDSFID()
{
if(fOpenDev==0&&fContinueMode ==false)
{
int HndLock=MessageBox(L"LOCK THE DSFID?You can't unlock if locked",L"RFIDDemo",MB_YESNOCANCEL|MB_ICONASTERISK);
if(HndLock==IDYES)
{
CString uid;
//get card uid for function
//send request
Amic_GetCardUIDRequest();
uid = Amic_GetUID();
//clear all data
Amic_ClearAll15693Data();
int ntype =CheckTagType();//get Tag type
int fLockDSFID= Amic_LockDSFIDRequest(ntype,false,uid);
if(fLockDSFID==0)
AfxMessageBox(L"Lock OK");
else
AfxMessageBox(L"Lock Error");
//clear all 15693 data
Amic_ClearAll15693Data();
}
}
}
void CWritePage::OnWriteBlock()
{
if(fOpenDev==0&&fContinueMode ==false)
{
UpdateData(true);
if(m_WriteData.GetLength()>0)
{
CString uid;
CString strWrite;
CString response_flag;
//get which block to be read
int nBlockList = m_WriteBlkList.GetCurSel();
int nBlockList10 =m_WriteBlkList10.GetCurSel();
int nReadRlockNum = nBlockList10*10 + nBlockList-1;
//get card uid for function
//send request
Amic_GetCardUIDRequest();
Sleep(100);
uid = Amic_GetUID();
//clear all data
if(uid.GetLength()>0)
{
Amic_ClearAll15693Data();
if(nReadRlockNum>=0&&nReadRlockNum<28)
{
int ntype =CheckTagType();//get Tag type
CHAR charbuf[MAX_PATH];
sprintf(charbuf,"%S",m_WriteData);
int fWrite = Amic_WriteBlockRequest(ntype,nReadRlockNum,false,uid,charbuf);
if(fWrite==0)// write ok
AfxMessageBox(L"Write Ok");
else if(fWrite==1)
AfxMessageBox(L"Write Error");
//clear all data
Amic_ClearAll15693Data();
}
else{ AfxMessageBox(L"Please Slect correct block num");}
}else{AfxMessageBox(L"Can't Find the Tag");}
}
}
}
void CWritePage::OnLockBlock()
{
if(fOpenDev==0&&fContinueMode ==false)
{
int HndLock=MessageBox(L"LOCK THE BLOCK?You can't unlock if locked",L"RFIDDemo",MB_YESNOCANCEL|MB_ICONASTERISK);
if(HndLock==IDYES)
{
CString uid;
//get which block to be Lock
int nBlockList = m_WriteBlkList.GetCurSel();
int nBlockList10 =m_WriteBlkList10.GetCurSel();
int nReadRlockNum = nBlockList10*10 + nBlockList-1;
//get card uid for function
//send request
Amic_GetCardUIDRequest();
Sleep(100);
uid = Amic_GetUID();
//clear all data
Amic_ClearAll15693Data();
int ntype =CheckTagType();//get Tag type
int fBlock = Amic_LockBlockRequest(ntype,nReadRlockNum,false,uid);
if(fBlock==0)// write ok
AfxMessageBox(L"Write Ok");
else if(fBlock==1)
AfxMessageBox(L"Write Error");
//clear all data
Amic_ClearAll15693Data();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -