⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgrfidt2.bak2007.11.8.cpp

📁 rfid在wince的平台的驱动
💻 CPP
字号:
// DlgRFIDT2.cpp : implementation file
//

#include "stdafx.h"
#include "capture.h"
#include "DlgRFIDT2.h"
#include "prompt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgRFIDT2 dialog


CDlgRFIDT2::CDlgRFIDT2(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgRFIDT2::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgRFIDT2)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgRFIDT2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgRFIDT2)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgRFIDT2, CDialog)
	//{{AFX_MSG_MAP(CDlgRFIDT2)
	ON_EN_CHANGE(IDC_EDITRFID, OnChangeEditrfid)
	ON_BN_CLICKED(IDC_BTNWRITE, OnBtnwrite)
	ON_BN_CLICKED(IDC_BTNREAD, OnBtnread)
//	ON_EN_CHANGE(IDC_EDIT_WRITEDATAINFO, OnChangeEditWritedatainfo)
	ON_EN_CHANGE(IDC_EDIT_RWDATALENINFO, OnChangeEditRwdataleninfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgRFIDT2 message handlers

void CDlgRFIDT2::OnChangeEditrfid() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	//SetDlgItemText(IDC_EDITRFID, _T(""));
}

void CDlgRFIDT2::OnBtnwrite() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_EDIT_USINGTIMEINFO, (CString)"");
	LARGE_INTEGER g_frequency;
	LARGE_INTEGER Start;
	LARGE_INTEGER End;
	double Time;
	QueryPerformanceFrequency(&g_frequency);//查询系统频率
	QueryPerformanceCounter(&Start);//查询系统运行滴答数,
	//每次执行QueryPerformanceCounter 得到的是你从开机到执行这个函数时的系统滴答数


	TCHAR m_wbuf[BUF_MAX_LEN];
	char m_szbuf[BUF_MAX_LEN];
	ZeroMemory(m_wbuf, BUF_MAX_LEN);
	ZeroMemory(m_szbuf, BUF_MAX_LEN);
	GetDlgItemText(IDC_EDITRFID, m_wbuf, MAX_PATH-1);
	WideCharToMultiByte(CP_ACP, 0, m_wbuf, -1, m_szbuf, MAX_PATH, NULL, NULL);

	int m_szbufLen = 0;
	m_szbufLen = m_iWriteDataLen = strlen(m_szbuf);
	char m_tempBuf[50] = {0};
	if (m_iWriteDataLen > 256)
	{
		SetDlgItemText(IDC_EDIT_RWDATALENINFO, (CString)"The data must be less than 256 bytes!");
		return;
	}
	else
	{
		sprintf(m_tempBuf, "Write %d bytes to the T2 card!", m_iWriteDataLen);
		SetDlgItemText(IDC_EDIT_RWDATALENINFO, (CString)m_tempBuf);
	}

	/*MessageBox(m_wbuf);
	char temp[20]={0};
	sprintf(temp, "len=[%d]", szTempBufLen);
	MessageBox((CString)temp);*/
	if (!m_ComMgr.IsOpen())
	{
		m_ComMgr.Open(3,38400,3000);
		Sleep(100);
	}
	if (m_ComMgr.IsOpen())
	{
		int m_iReadDataRe = 0;
		memset(szSendBuf, 0x00, BUF_MAX_LEN);
		
		if(m_szbufLen < 256)
			m_szbufLen += 1;
		
		m_szbufLen++;
		szSendBuf[0]=0x02;
		szSendBuf[1]=m_szbufLen/256;
		szSendBuf[2]=(char)m_szbufLen;
		szSendBuf[3]=0x34;
		szSendBuf[4]=0x00;
		strcpy(szSendBuf+5, m_szbuf);
		m_iReadDataRe = m_ComMgr.Write(szSendBuf, m_szbufLen+4);
		memset(szSendBuf, 0x00, BUF_MAX_LEN);
		m_iReadDataRe = m_ComMgr.ReadSync(szSendBuf, 4, 3000);
		if (szSendBuf[3]==0x34)
		{
			beep();
			SetDlgItemText(IDC_EDITRFID, (CString)"Write data ok!");
		}
		else
			SetDlgItemText(IDC_EDITRFID, (CString)"Write data error!");
		/*if(m_szbufLen < 256)
		{
			szSendBuf[1]=(m_szbufLen+1)/256;
			szSendBuf[2]=(char)m_szbufLen+1;
			szSendBuf[3]=0x34;
			strcpy(szSendBuf+4, m_szbuf);
			m_iReadDataRe = m_ComMgr.Write(szSendBuf, m_szbufLen+1+5);
			memset(szSendBuf, 0x00, BUF_MAX_LEN);
			m_iReadDataRe = m_ComMgr.ReadSync(szSendBuf, m_szbufLen+1+10, 16*1000);
			if (szSendBuf[8+m_szbufLen+1]==0x34)
			{
				beep();
				SetDlgItemText(IDC_EDITRFID, (CString)"Write data ok!");
			}
			else
				SetDlgItemText(IDC_EDITRFID, (CString)"Write data error!");
		}
		else
		{
			szSendBuf[1]=m_szbufLen/256;
			szSendBuf[2]=(char)m_szbufLen;
			szSendBuf[3]=0x34;
			strcpy(szSendBuf+4, m_szbuf);
			m_iReadDataRe = m_ComMgr.Write(szSendBuf, m_szbufLen+5);
			memset(szSendBuf, 0x00, BUF_MAX_LEN);
			m_iReadDataRe = m_ComMgr.ReadSync(szSendBuf, m_szbufLen+10, 16*1000);
			if (szSendBuf[8+m_szbufLen]==0x34)
			{
				beep();
				SetDlgItemText(IDC_EDITRFID, (CString)"Write data ok!");
			}
			else
				SetDlgItemText(IDC_EDITRFID, (CString)"Write data error!");
		}*/

		QueryPerformanceCounter(&End);
		//前后两次滴答数的差除以系统频率就是时间差,单位是豪秒
		//Time = (double)(End.QuadPart-Start.QuadPart)/(double)(g_frequency.QuadPart)*1000.0;
		//前后两次滴答数的差除以系统频率就是时间差,单位是秒
		Time = (double)(End.QuadPart-Start.QuadPart)/(double)(g_frequency.QuadPart);
		
		memset(m_tempBuf, 0x00, 50);
		sprintf(m_tempBuf, "Write data using %f s", Time);
		SetDlgItemText(IDC_EDIT_USINGTIMEINFO, (CString)m_tempBuf);

	//	Sleep(1000);
		m_ComMgr.Close();
		m_ComMgr.Open(4,38400,3000);
		m_ComMgr.Close();
	}
}

void CDlgRFIDT2::OnBtnread() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_EDIT_USINGTIMEINFO, (CString)"");
	LARGE_INTEGER g_frequency;
	LARGE_INTEGER Start;
	LARGE_INTEGER End;
	double Time;
	int nLength;
	QueryPerformanceFrequency(&g_frequency);
	QueryPerformanceCounter(&Start);

	if (!m_ComMgr.IsOpen())
	{
		m_ComMgr.Open(3,38400,3000);
		Sleep(100);
	}
	if (m_ComMgr.IsOpen())
	{
		memset(szSendBuf, 0x00, BUF_MAX_LEN);
		szSendBuf[0]=0x02;// start
		szSendBuf[1]=0x00;// length
		szSendBuf[2]=0x03;// length
		szSendBuf[3]=0x32;// cmd
		szSendBuf[4]=0x00;// block_NO
		szSendBuf[5]=0x01;// data length
		szSendBuf[6]=0x00;// data length
		nLength = 7;

		int m_iReadDataRe = 0;	
		m_iReadDataRe =m_ComMgr.Write(szSendBuf, nLength);

		nLength = szSendBuf[5] * 256 + szSendBuf[6];
		memset(szSendBuf, 0x00, BUF_MAX_LEN);
		//m_iReadDataRe = m_ComMgr.Read(szSendBuf, 261+5, 3000);
		m_iReadDataRe = m_ComMgr.ReadSync(szSendBuf, nLength+4, 2000);
		char m_tempBuf[50]={0};
// 		sprintf(m_tempBuf, "0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x0x%x", szSendBuf[0],
// 			szSendBuf[1],szSendBuf[2],szSendBuf[3],szSendBuf[4],
// 			szSendBuf[5],szSendBuf[6],szSendBuf[7],szSendBuf[8],
// 			szSendBuf[9],szSendBuf[10],szSendBuf[11],szSendBuf[12],
// 			szSendBuf[13],szSendBuf[14],szSendBuf[15]);
		
		
	/*	beep();
		m_iReadDataRe=szSendBuf[0];
 		memset(szSendBuf, 0x00, sizeof(szSendBuf));
 		sprintf(szSendBuf, "szSendBuf[0]=[%d]", m_iReadDataRe);
 		SetDlgItemText(IDC_EDITRFID, (CString)(szSendBuf));*/

		if (szSendBuf[3]==0x32)
		{
			beep();
			char m_readDataBuf[BUF_MAX_LEN] = {0};
			strcpy(m_readDataBuf, szSendBuf+4);
			m_iReadDataLen = strlen(m_readDataBuf);
			if (m_iReadDataLen >= 256)
				m_iReadDataLen = 256;
			
			//sprintf(m_tempBuf, "Read %d bytes %d from the T2 card!", m_iReadDataLen, m_iReadDataRe);
			sprintf(m_tempBuf, "Read %d bytes from the T2 card!", m_iReadDataLen);
			SetDlgItemText(IDC_EDIT_RWDATALENINFO, (CString)m_tempBuf);
			SetDlgItemText(IDC_EDITRFID, (CString)(szSendBuf+4));
		}
		else
		{
			m_iReadDataLen = 0;
			sprintf(m_tempBuf, "Read %d bytes from the T2 card!", m_iReadDataLen);
			SetDlgItemText(IDC_EDIT_RWDATALENINFO, (CString)m_tempBuf);
			SetDlgItemText(IDC_EDITRFID, (CString)"Read data error!");
		}

		QueryPerformanceCounter(&End);
		//Time = (double)(End.QuadPart-Start.QuadPart)/(double)(g_frequency.QuadPart)*1000.0;
		Time = (double)(End.QuadPart-Start.QuadPart)/(double)(g_frequency.QuadPart);
		memset(m_tempBuf, 0x00, 50);
		sprintf(m_tempBuf, "Read data using %f s", Time);
		SetDlgItemText(IDC_EDIT_USINGTIMEINFO, (CString)m_tempBuf);

		m_ComMgr.Close();
		m_ComMgr.Open(4,38400,3000);
		m_ComMgr.Close();
	}

}

void CDlgRFIDT2::OnChangeEditWritedatainfo() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CDlgRFIDT2::OnChangeEditRwdataleninfo() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -