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

📄 s180006capiexamplecomendlg.cpp

📁 这是高频RFID读写示例程序,能控制RFID读写器进行读写
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// S180006CAPIExampleComEnDlg.cpp : implementation file
//

#include "stdafx.h"
#include "S180006CAPIExampleComEn.h"
#include "S180006CAPIExampleComEnDlg.h"

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


char temp[128];

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CS180006CAPIExampleComEnDlg dialog

CS180006CAPIExampleComEnDlg::CS180006CAPIExampleComEnDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CS180006CAPIExampleComEnDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CS180006CAPIExampleComEnDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CS180006CAPIExampleComEnDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CS180006CAPIExampleComEnDlg)
	DDX_Control(pDX, IDC_LIST3, m_ListCtrl);
	DDX_Control(pDX, IDC_LIST1, m_infoList);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CS180006CAPIExampleComEnDlg, CDialog)
	//{{AFX_MSG_MAP(CS180006CAPIExampleComEnDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
	ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
	ON_WM_TIMER()
	ON_CBN_SELCHANGE(IDC_CMB_READTYPE, OnSelchangeCmbReadtype)
	ON_CBN_SELCHANGE(IDC_CMB_WRITETYPE, OnSelchangeCmbWritetype)
	ON_CBN_SELCHANGE(IDC_COMBO_WRITE_LEN, OnSelchangeComboWriteLen)
	ON_BN_CLICKED(IDC_BUTTON_WRITEDATA, OnButtonWritedata)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_BN_CLICKED(IDC_BTN_RFSET, OnBtnRfset)
	ON_BN_CLICKED(IDC_BTN_RFQUERY, OnBtnRfquery)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CS180006CAPIExampleComEnDlg message handlers

BOOL CS180006CAPIExampleComEnDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	CString str;
	SenseinfoList_CreateColumn(&m_infoList);

	int i;

	CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_COM);
	for(i = 1; i < 9; i++)
	{		
		str.Format("COM%d",i);
		pCombo->AddString(str);
	}	
	pCombo->SetCurSel(0);	
	CComboBox* pBaudRate = (CComboBox*)GetDlgItem(IDC_COMBO_BAUDRATE);
	pBaudRate->AddString("300");
	pBaudRate->AddString("600");
	pBaudRate->AddString("2400");
	pBaudRate->AddString("4800");
	pBaudRate->AddString("9600");
	pBaudRate->AddString("19200");
	pBaudRate->AddString("38400");
	pBaudRate->AddString("57600");
	pBaudRate->AddString("115200");
	pBaudRate->SetCurSel(4);
	str.Format("%d",0xFF);
	((CComboBox*)GetDlgItem(IDC_COMBO_REARERADDR))->AddString(str);
	for (i=0;i<=0xF0;i++)
	{
		str.Format("%d",i);		
		((CComboBox*)GetDlgItem(IDC_COMBO_REARERADDR))->AddString(str);	
	}
	((CComboBox*)GetDlgItem(IDC_COMBO_REARERADDR))->SetCurSel(0);

	((CComboBox*)GetDlgItem(IDC_CMB_READTYPE))->SetCurSel(0);
	CComboBox* cbOffset = (CComboBox*)GetDlgItem(IDC_COMBO_READOFFSET);
	for(i = 0; i <= 0xff; i++)
	{
		str.Format("%02d",i);
		cbOffset->AddString(str);
	}

	CComboBox* cbWriteLen = (CComboBox*)GetDlgItem(IDC_COMBO_READ_LEN);
	for(i=0;i<=16;i+=2)
	{
		str.Format("%d",i);
		cbWriteLen->AddString(str);
	}

	m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS|LVS_EX_GRIDLINES);
	m_ListCtrl.GetWindowRect(&m_ListRect);
	m_ListRect.left = 150;
	m_ListRect.top = 7;
	SenseList_CreateColumn(m_ListCtrl);
	OnSelchangeCmbReadtype();	

	((CEdit*)GetDlgItem(IDC_EDIT_WRITEDATA))->SetLimitText(32);
	((CComboBox*)GetDlgItem(IDC_CMB_WRITETYPE))->SetCurSel(3);


	OnSelchangeCmbWritetype();

	OnSelchangeComboWriteLen(); 

	CComboBox* pCBRF = (CComboBox*)GetDlgItem(IDC_COMBO_RF);
	for(i=100;i<=150;i=i+5)
	{
		str.Format("%2d",i);		
		pCBRF->AddString(str);				
	}
	pCBRF->SetCurSel(0);

	GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_RFSET)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_RFQUERY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_WRITEDATA)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_END_WRITE)->EnableWindow(FALSE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CS180006CAPIExampleComEnDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CS180006CAPIExampleComEnDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CS180006CAPIExampleComEnDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CS180006CAPIExampleComEnDlg::OnButtonOpen() 
{
	CString str;	// comm name 
	CComboBox* pCombo1 = (CComboBox*)GetDlgItem(IDC_COMBO_COM);
	pCombo1->GetLBText(pCombo1->GetCurSel(),str);
	str.MakeUpper();
	if (g_hCom != NULL)
	{
		MessageBox(GetUID(C_COM_AREADY_OPEN), GetUID(C_HINT),MB_OK);
		if (!::IsWindowEnabled(GetDlgItem(IDC_BUTTON_CLOSE)->GetSafeHwnd()))
			GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(TRUE);
		return;
	}

	status = SeRFIDpub_Open(g_hCom,str.GetBuffer(0));
	if (status != ERR_NONE)
	{

		pstr = GetUID(C_OPEN_COM_FAIL);
		ShowInfo(pstr.GetBuffer(0));
		OnButtonClose();
		GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);			
	}
	else
	{
		g_RAddr = ((CComboBox*)GetDlgItem(IDC_COMBO_REARERADDR))->GetCurSel();	
		if (g_RAddr == 0)
			g_RAddr = 0xFF;  //广播地址
		else
			g_RAddr = g_RAddr-1;
		
		unsigned char BaudRate = ((CComboBox*)GetDlgItem(IDC_COMBO_BAUDRATE))->GetCurSel();
		status = SeRFIDpub_SysSetBaudRate(g_hCom, g_RAddr, BaudRate);
		if(status == ERR_NONE)
		{
			GetReaderVersion();
			str.Format(GetUID(C_CONNECT_SUCC));
			ShowInfo(str.GetBuffer(0));				
			GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(FALSE);
			GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(TRUE);
			GetDlgItem(IDC_BUTTON_READ)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_RFSET)->EnableWindow(true);
			GetDlgItem(IDC_BTN_RFQUERY)->EnableWindow(true);
			GetDlgItem(IDC_BUTTON_WRITEDATA)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_END_WRITE)->EnableWindow(TRUE);
			
		}else
		{
			str.Format(GetUID(C_CONNECT_FAILED),status);
			ShowInfo(str.GetBuffer(0));
			GetDlgItem(IDC_BUTTON_READ)->EnableWindow(FALSE);
			GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(TRUE);
			GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_RFSET)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_RFQUERY)->EnableWindow(FALSE);
			GetDlgItem(IDC_BUTTON_WRITEDATA)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_END_WRITE)->EnableWindow(FALSE);
			OnButtonClose();
		}
	}
	
}

void CS180006CAPIExampleComEnDlg::OnButtonClose() 
{
		if (g_hCom != NULL)
	{
		SeRFIDpub_Close(g_hCom,g_RAddr);

		CString str;
		str.Format("%s",GetUID(C_SCANNER_VERSION));

		g_hCom=NULL;
		pstr = GetUID(C_READER_IS_CLOSED);

	}
	GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_READ)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_RFSET)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_RFQUERY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_WRITEDATA)->EnableWindow(FALSE);

⌨️ 快捷键说明

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