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

📄 s180006capiexamplecomendlg.cpp

📁 这是高频RFID读写示例程序,能控制RFID读写器进行读写
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	GetDlgItem(IDC_BTN_END_WRITE)->EnableWindow(FALSE);
	
}

bool CS180006CAPIExampleComEnDlg::GetReaderVersion()
{
	unsigned char MainVersion;
	unsigned char MinorVersion;
	CString str;
	bool bResult;
	status = SeRFIDpub_SysGetFirmwareRevision(g_hCom, g_RAddr,&MainVersion,&MinorVersion);	
	if (status ==ERR_NONE)
	{
		str.Format("%s:V%02X.%02X",GetUID(C_SCANNER_VERSION),MainVersion,MinorVersion);
		bResult = true;
	}else
	{		
		bResult = false;
	}
	ShowInfo(str.GetBuffer(0));
	return bResult;
}

void CS180006CAPIExampleComEnDlg::OnButtonRead() 
{

	SetTimer(1,5000, 0); 
	bReadTimer=true;
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(TRUE);
}


bool CS180006CAPIExampleComEnDlg::ReadTagID()
{
	unsigned char TagCount=0x00, MaskLength=0x00, DataLen=0x00;
	unsigned char QValue=3;
	unsigned char TagID[12];
	unsigned char Mask[12];
	CString str;

	unsigned char Bank = ((CComboBox*)GetDlgItem(IDC_CMB_READTYPE))->GetCurSel()*2+1;
	unsigned char Point = GetDlgItemInt(IDC_COMBO_READOFFSET,NULL,false);
	unsigned char ReadLen = GetDlgItemInt(IDC_COMBO_READ_LEN,NULL,false);
	status = SeRFIDGen2_SingleRead(g_hCom,g_RAddr,QValue,Bank,Point,ReadLen,MaskLength,Mask,&TagCount,&DataLen,TagID);
//		status = SeRFIDGen2_SingleReadID(g_hCom,g_RAddr,QValue,MaskLength,Mask,&TagCount,&DataLen,TagID);
	//RfidError = SeRFIDGen2_SingleRead(hCom, 255, 3, 1, 0, 12, 0, Mask(), TagCount, DataLength, Data())
	if (status==ERR_NONE)
	{
		if (TagCount!=0)
			;	
		else 
		{
			return true;
		}

		
		sprintf(temp,FormatData(&TagID[0],DataLen));
		int iAntID = TagID[DataLen]+1;
		SenseList_InsertItem(m_ListCtrl,temp,iAntID);
		ChangeBKColor();
		return true;
	}
	return false;
}

CString CS180006CAPIExampleComEnDlg::FormatData(unsigned char *TagID,unsigned char bitCount)
{
	
	CString s,s1;
	for(int k = 0;k<bitCount;k++)
	{
		s1.Format("%02X",TagID[k]);
		s=s+s1;
		if (((k+1)%4==0)&&(k>0)&&(k<bitCount-1))
			s=s + " ";		
	}
	return s;
}
void CS180006CAPIExampleComEnDlg::ChangeBKColor()
{

		SenseList_SetBKColor(m_ListCtrl, bDefaultColor);
		InvalidateRect(m_ListRect,true);

}

void CS180006CAPIExampleComEnDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (bReadTimer)
	{
		bReadTimer=false;
		ReadTagID();
		bReadTimer=true;
	}
	CDialog::OnTimer(nIDEvent);
}

void CS180006CAPIExampleComEnDlg::OnSelchangeCmbReadtype() 
{

	int iSel = ((CComboBox*)GetDlgItem(IDC_CMB_READTYPE))->GetCurSel();
	CComboBox* cbOffset = (CComboBox*)GetDlgItem(IDC_COMBO_READOFFSET);
	CComboBox* cbWriteLen = (CComboBox*)GetDlgItem(IDC_COMBO_READ_LEN);
	
	cbWriteLen->EnableWindow(true);
	switch(iSel)
	{
		case	0:								
				cbWriteLen->SetCurSel(6);
				cbOffset->SetCurSel(0);
				cbOffset->EnableWindow(false);
				break;
		case	1:	//tagID 8-12 byte
				cbOffset->EnableWindow(true);
				cbWriteLen->SetCurSel(4);
				cbOffset->SetCurSel(0);
				break;
		default :
				cbWriteLen->SetCurSel(6);
				cbOffset->SetCurSel(0);
				cbOffset->EnableWindow(false);
				break;
	}		
}

void CS180006CAPIExampleComEnDlg::OnSelchangeCmbWritetype() 
{
	CString str;
	int i;
	int iSel = ((CComboBox*)GetDlgItem(IDC_CMB_WRITETYPE))->GetCurSel();
	CComboBox* cbOffset = (CComboBox*)GetDlgItem(IDC_COMBO_WRITEOFFSET);
	CComboBox* cbWriteLen = (CComboBox*)GetDlgItem(IDC_COMBO_WRITE_LEN);
	cbWriteLen->ResetContent();
	for(i=1;i<=8;i++)
	{
		str.Format("%d",i*2);
		cbWriteLen->AddString(str);
	}

	cbWriteLen->EnableWindow(true);
	cbOffset->ResetContent();
	switch(iSel)
	{
		case	0:				
				cbOffset->AddString("Access Password");	//4 Byte
				cbOffset->AddString("Kill Password"); //4 Byte
				cbOffset->SetCurSel(0);
				cbWriteLen->SetCurSel(1);
				cbWriteLen->EnableWindow(false);
				break;
		case	1:	//tagID 8-12 byte
				cbOffset->AddString("EPC ID");
				cbWriteLen->SetCurSel(5);
				cbOffset->SetCurSel(0);
				break;
		case	2:	//TID :8byte
				cbOffset->AddString("TID");
				cbOffset->SetCurSel(0);
				cbWriteLen->SetCurSel(2);
				cbWriteLen->EnableWindow(false);
				break;
		case	3:
				for(i = 0; i <= 0xff; i++)
				{
					str.Format("%02d",i);
					cbOffset->AddString(str);
				}
				cbWriteLen->SetCurSel(3);
				cbOffset->SetCurSel(0);
				break;
	}
	OnSelchangeComboWriteLen();
}

void CS180006CAPIExampleComEnDlg::OnSelchangeComboWriteLen() 
{
	int nBytes = 0;
	nBytes = ((CComboBox*)GetDlgItem(IDC_COMBO_WRITE_LEN))->GetCurSel();
	nBytes = (nBytes+1)*2*2;
	((CEdit*)GetDlgItem(IDC_EDIT_WRITEDATA))->SetLimitText(nBytes);
	
}

void CS180006CAPIExampleComEnDlg::OnButtonWritedata() 
{
	CString sData;
	unsigned char tagData[16];
	
	unsigned char Bank = ((CComboBox*)GetDlgItem(IDC_CMB_WRITETYPE))->GetCurSel();
	unsigned char Point = GetDlgItemInt(IDC_COMBO_WRITEOFFSET,NULL,false);
	unsigned char uclen = GetDlgItemInt(IDC_COMBO_WRITE_LEN,NULL,false);	
	unsigned char IDBitCount = 0;
	unsigned char tagID[12];
	unsigned char QValue = 2;

	
	GetDlgItem(IDC_BUTTON_WRITEDATA)->EnableWindow(false);

	((CEdit*)GetDlgItem(IDC_EDIT_WRITEDATA))->GetWindowText(sData);
	StrHexToArray(sData,uclen,tagData);
	CycleEnabledBtn(IDC_BUTTON_WRITEDATA,IDC_BTN_END_WRITE,true);
	int i = 10;
	pstr = "";
	while(i>0)
	{		
		i--;
		CString stemp;
		stemp = "";			pstr = "";
		GetDlgItem(IDC_CMB_WRITETYPE)->GetWindowText(stemp);
		pstr = GetUID(C_WRITE) + " "+ GetUID(C_BLOCK) + ":"+stemp;
		GetDlgItem(IDC_COMBO_WRITEOFFSET)->GetWindowText(stemp);
		pstr = pstr + "," + GetUID(C_ADDRESS) + ": "+stemp;
		GetDlgItem(IDC_COMBO_WRITE_LEN)->GetWindowText(stemp);
		pstr = pstr + ","+ GetUID(C_LENGTH)+": "+stemp;
		GetDlgItem(IDC_EDIT_WRITEDATA)->GetWindowText(stemp);
		pstr = pstr + GetUID(C_DATA)+": "+stemp+"(hex) ";
	
		status = SeRFIDGen2_Write(g_hCom, g_RAddr, QValue, Bank, Point, uclen, tagData);

		if (status == ERR_NONE)
		{
				
			break;
		}

		StopOperation(IDC_BUTTON_WRITEDATA,IDC_BTN_END_WRITE,i);
	}
	if (status !=ERR_NONE)
	{
		CString str;
		str = pstr + GetUID(C_FAIL)+"!(%02X)"; 
		pstr.Format(str,status);	
	}else
		pstr = pstr + GetUID(C_SUCCESS)+"!";

	CycleEnabledBtn(IDC_BUTTON_WRITEDATA,IDC_BTN_END_WRITE,false);	
	ShowInfo(pstr.GetBuffer(0));

	return ;
	
}



void CS180006CAPIExampleComEnDlg::StrHexToArray(CString sdata, int ArrayCount, unsigned char data[])
{
	CString sFormat,stemp;
	sFormat.Format("%%0%ds",ArrayCount*2);
	stemp.Format(sFormat,sdata);
	
	for(int i=0;i<ArrayCount;i++)
	{
		data[i] = strtoul(stemp.Mid(i*2,2),NULL,16);
	}
}

void CS180006CAPIExampleComEnDlg::StopOperation(int btID,int endBtID,int& pos)
{
	MSG msg;

	if (PeekMessage(&msg,m_hWnd,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE))
	{
		if ((msg.message == WM_LBUTTONDOWN)&&(msg.hwnd==GetDlgItem(endBtID)->m_hWnd))
		{
			GetDlgItem(btID)->EnableWindow(true); 
			GetDlgItem(endBtID)->EnableWindow(false); 
			pos = 0;
			return;
		}
	}
}

void CS180006CAPIExampleComEnDlg::OnButtonStop() 
{
	bReadTimer=false;	
	KillTimer(1);
	if (bStartedRunning)
	{
		SeRFIDGen2_End(g_hCom,g_RAddr);
		bStartedRunning = false;
	}	
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(true);
	GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(false);
	
}


void CS180006CAPIExampleComEnDlg::CycleEnabledBtn(int btID, int endBtID, bool btype)	//true :Cycle start ;false :cycle end
{
	GetDlgItem(btID)->EnableWindow(!btype); 
	GetDlgItem(endBtID)->EnableWindow(btype); 
}

void CS180006CAPIExampleComEnDlg::OnBtnRfset() 
{
	// TODO: Add your control notification handler code here
	unsigned char RFSel = ((CComboBox*)GetDlgItem(IDC_COMBO_RF))->GetCurSel();
	unsigned char RF = RFSel*5 + 100;
	status = SeRFIDpub_SysRFSet(g_hCom, g_RAddr, RF);
	CString str,stemp;
	if (status ==ERR_NONE)
	{
		((CComboBox*)GetDlgItem(IDC_COMBO_RF))->GetLBText(RFSel,stemp);
		str.Format(C_SET_RF_SUCC_VALUE,stemp);
	}else
	{
		str.Format(C_SET_RF_FAIL_ERRORID,status);	
	}
	ShowInfo(str.GetBuffer(0)); 
	
}

void CS180006CAPIExampleComEnDlg::OnBtnRfquery() 
{
	// TODO: Add your control notification handler code here
	unsigned char RF;
	status = SeRFIDpub_SysRFQuery(g_hCom, g_RAddr, &RF);
	CString str, stemp;
	if (status ==ERR_NONE)
	{
		((CComboBox*)GetDlgItem(IDC_COMBO_RF))->GetLBText((RF-100)/5, stemp);
		((CComboBox*)GetDlgItem(IDC_COMBO_RF))->SetCurSel((RF-100)/5);
		str.Format(C_QUERY_RF_SUCC_VALUE, stemp);
	}else
	{
		str.Format(C_QUERY_RF_FAIL_ERRORID,status);	
	}
	ShowInfo(str.GetBuffer(0));
	
}



BOOL CS180006CAPIExampleComEnDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if   (pMsg->message == WM_KEYDOWN && 
		(pMsg->wParam == VK_RETURN||pMsg->wParam == VK_ESCAPE))       
		return   TRUE; 
	
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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