www.pudn.com > SenseISODemo.rar > ReadPage1.cpp
// ReadPage1.cpp : implementation file
//
#include "stdafx.h"
#include "SenseISODemo.h"
#include "ReadPage1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReadPage1 dialog
char temp[128];
CReadPage1::CReadPage1(CWnd* pParent /*=NULL*/)
: CDialog(CReadPage1::IDD, pParent)
{
//{{AFX_DATA_INIT(CReadPage1)
//}}AFX_DATA_INIT
}
void CReadPage1::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReadPage1)
DDX_Control(pDX, IDC_LIST3, m_ListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReadPage1, CDialog)
//{{AFX_MSG_MAP(CReadPage1)
ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
ON_BN_CLICKED(IDC_BUTTON_ROUNDREAD, OnButtonRoundread)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnButtonConfig)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
ON_BN_CLICKED(IDC_BUTTON_CONTINUEREAD, OnButtonContinueRead)
ON_WM_SHOWWINDOW()
ON_NOTIFY(NM_DBLCLK, IDC_LIST3, OnDblclkList3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReadPage1 message handlers
BOOL CReadPage1::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
bReadTimer=false;
CComboBox* pCom = ((CComboBox*)GetDlgItem(IDC_COMBO_CLYCEL));
pCom->AddString("100");
pCom->AddString("150");
pCom->AddString("200");
pCom->AddString("250");
pCom->AddString("300");
pCom->AddString("500");
pCom->AddString("1000");
m_Font.CreateFont(25,
12,
0,//10,
0,//45,
FW_DONTCARE,//FW_HEAVY,
false,
0,//TRUE,
0,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DRAFT_QUALITY,
FIXED_PITCH|FF_SWISS,
_T(GetUID(C_LISTVIEW_FONT))); //MS Gothic
CString str;
int i,j;
CComboBox* pcbSelAddr=(CComboBox*)GetDlgItem(IDC_COMBO_SELADDR);
CComboBox* pcbMTRAddr=(CComboBox*)GetDlgItem(IDC_COMBO_MTRADDR);
for(i=0x00;i<=0xFF;i++)
{
str.Format("%02d",i);
pcbSelAddr->AddString(str);
pcbMTRAddr->AddString(str);
}
pcbSelAddr->SetCurSel(0);
pcbMTRAddr->SetCurSel(0);
CComboBox* pComSelValue[8];
for (i=0; i<=7; i++)
{
pComSelValue[i] = (CComboBox*)GetDlgItem(IDC_CB0 + i);
}
for (i=0; i<=7; i++)
{
pComSelValue[i]->AddString(GetUID(C_IGNORE));
for (j=0; j<=255; j++)
{
str.Format("%02X",j);
pComSelValue[i]->AddString(str);
}
pComSelValue[i]->SetCurSel(0);
//pComSelValue[i]->EnableWindow(FALSE);
}
((CComboBox*)GetDlgItem(IDC_COMBO_SEL))->SetCurSel(0);
((CComboBox*)GetDlgItem(IDC_COMBO_CLYCEL))->SetCurSel(2);
((CButton*)GetDlgItem(IDC_RADIO_READID))->SetCheck(1);
((CButton*)GetDlgItem(IDC_CHECK_BKCHGCOLOR))->SetCheck(1);
// ((CButton*)GetDlgItem(IDC_BTNENDANTENNACYCLE))->EnableWindow(false);
// ((CButton*)GetDlgItem(IDC_CHECK_ANTA1))->SetCheck(true);
m_Brush = CreateSolidBrush(RGB(212,208,200)); //White
m_Brush1 = CreateSolidBrush(RGB(128,255,0)); //浅绿
m_Brush2 = CreateSolidBrush(RGB(0,255,255)); //浅蓝
m_Brush3 = CreateSolidBrush(RGB(0,128,255)); //深蓝
// CReadPage1::GetClientRect(m_ListRect);
m_ListCtrl.GetClientRect(m_ListRect);
m_ListRect.right += 10;
m_ListRect.bottom += 10;
/*
LV_COLUMN lvc;
CRect rclvc;
m_ListCtrl.GetClientRect(&rclvc);
lvc.mask = LVCF_TEXT|LVCF_WIDTH;
lvc.fmt = LVCFMT_CENTER;
lvc.pszText = _T("标签数据");
lvc.cx = rclvc.Width()*4/5;
m_ListCtrl.InsertColumn(0,&lvc);
lvc.pszText = _T("天线");
lvc.fmt = LVCFMT_RIGHT;
lvc.cx =rclvc.Width()/5;//+25;
m_ListCtrl.InsertColumn(1,&lvc);
*/ m_ListCtrl.SetFont(&m_Font);
SenseList_CreateColumn(m_ListCtrl);
return TRUE;
}
void CReadPage1::OnButtonRead() //
{
ClearCache();
if(((CButton*)GetDlgItem(IDC_RADIO_READID))->GetCheck()==1)
ReadTagID();
else if(((CButton*)GetDlgItem(IDC_RADIO_READADDRDATA))->GetCheck()==1)
MTRAddressData();
SetDlgItemInt(IDC_EDIT_COUNTER,m_ListCtrl.GetItemCount(),FALSE);
}
void CReadPage1::OnButtonRoundread()
{
// TODO: Add your control notification handler code here
int sel=((CComboBox*)GetDlgItem(IDC_COMBO_CLYCEL))->GetCurSel();
switch(sel)
{
case 0:
sel=100;
break;
case 1:
sel=150;
break;
case 2:
sel=200;
break;
case 3:
sel=250;
break;
case 4:
sel=300;
break;
case 5:
sel=500;
break;
case 6:
sel=1000;
break;
default:
sel=200;
}
SetTimer(1, sel, 0);
bReadTimer=true;
GetDlgItem(IDC_BUTTON_READ)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_ROUNDREAD)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(TRUE);
}
void CReadPage1::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (bReadTimer)
{
bReadTimer=false;
OnButtonRead();
bReadTimer=true;
}
CDialog::OnTimer(nIDEvent);
}
void CReadPage1::OnButtonStop()
{
bReadTimer=false;
KillTimer(1);
GetDlgItem(IDC_BUTTON_READ)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_ROUNDREAD)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(false);
}
void CReadPage1::PlayBeep()
{
if (((CButton *)GetDlgItem(IDC_CHECK_SPEAKER))->GetCheck()==1)
{
Beep(800,100);
}
}
void CReadPage1::ClearContent()
{
if (((CButton *)GetDlgItem(IDC_CHECK_AUTOCLEAR))->GetCheck()==1)
{
m_ListCtrl.DeleteAllItems();
// m_ListCtrl.UpdateWindow();
}
}
CString CReadPage1::FormatData(unsigned char *TagID,unsigned char bitCount)
{
CString s,s1;
for(int k = 0;kGetCurSel();
sel = ((CComboBox*)GetDlgItem(IDC_COMBO_SEL))->GetCurSel();
mask = 0X00;
for(int i=0;i<=7;i++)
{
iValue = ((CComboBox*)GetDlgItem(IDC_CB0 + i))->GetCurSel();
value[i] = iValue;
mask = mask<<1; //8位每一位表示是否参与比较;
if (iValue!=0)
{
mask = mask|0x01;
value[i] = iValue-1;
}
}
status = Sense18K_ISOSelect(g_hCom,g_RAddr,sel,addr,mask,value);
return unsigned char(status);
}
void CReadPage1::OnButtonConfig()
{
status = SelectTag();
CString str;
if (status==ERR_NONE)
{
str.Format(GetUID(C_SET_SELECT_TAG_SUCCESS));
}else
{
str.Format(GetUID(C_SET_SELECT_TAG_FAIL),status);
}
MessageBox(str,GetUID(C_HINT),MB_OK);
}
bool CReadPage1::ClearCache()
{
status = Sense18K_BufCLRAll(g_hCom,g_RAddr);
return status == ERR_NONE;
}
bool CReadPage1::ReadTagID()
{
unsigned char TagCount=0x00;
unsigned char TagID[255];
int i;
CString str;
status = Sense18K_ISOListUID(g_hCom,g_RAddr,&TagCount);
if (status==ERR_NONE)
{
if (TagCount!=0)
ClearContent();
else
{
ResetBkColor();
return true;
}
for(i=0;iGetCheck()!=1)
SenseList_InsertItem(m_ListCtrl,temp,TagID[TagID[0]]+1);
else
SenseList_InsertItemAdd(m_ListCtrl,temp,TagID[TagID[0]]+1);
//2006-06-16 ShowInfo(temp,TagID[TagID[0]]);
// ChangeBKColor(TagID[TagID[0]]);
// InvalidateRect(m_ListRect,true);
}
}
ChangeBKColor();
return true;
}
return false;
}
bool CReadPage1::MTRAddressData()
{
unsigned char dataAddr = 0x00;
unsigned char tagCount;
unsigned char TagData[9];
CString str;
dataAddr = ((CComboBox*)GetDlgItem(IDC_COMBO_MTRADDR))->GetCurSel();
status = Sense18K_ISOMTR(g_hCom,g_RAddr,dataAddr,&tagCount);
PlayBeep();
if (status == ERR_NONE)
{
if (tagCount!=0) ClearContent();
for(int i=0;iGetCheck()!=1)
SenseList_InsertItem(m_ListCtrl,temp,TagData[TagData[0]]+1);
else
SenseList_InsertItemAdd(m_ListCtrl,temp,TagData[TagData[0]]+1);
//2006-06-16 ShowInfo(temp,TagData[TagData[0]]);
// ChangeBKColor(TagData[TagData[0]]);
}
}
ChangeBKColor();
return true;
}
return false;
}
void CReadPage1::ShowImg(unsigned char AnteID)
{
CButton* cp1 = (CButton *)GetDlgItem(IDC_STATIC_ANT1);
CButton* cp2 = (CButton *)GetDlgItem(IDC_STATIC_ANT2);
CButton* cp3 = (CButton *)GetDlgItem(IDC_STATIC_ANT3);
CButton* cp4 = (CButton *)GetDlgItem(IDC_STATIC_ANT4);
if(AnteID==0x00)
{
cp1->ShowWindow(true);
cp2->ShowWindow(false);
cp3->ShowWindow(false);
cp4->ShowWindow(false);
}else if (AnteID==0x01)
{
cp1->ShowWindow(false);
cp2->ShowWindow(true);
cp3->ShowWindow(false);
cp4->ShowWindow(false);
}else if (AnteID==0x02)
{
cp1->ShowWindow(false);
cp2->ShowWindow(false);
cp3->ShowWindow(true);
cp4->ShowWindow(false);
}else if (AnteID==0x03)
{
cp1->ShowWindow(false);
cp2->ShowWindow(false);
cp3->ShowWindow(false);
cp4->ShowWindow(true);
}
UpdateWindow();
}
HBRUSH CReadPage1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
/* if (nCtlColor==CTLCOLOR_LISTBOX)
if (m_ucBKColor==1)
{
return m_Brush;
}else if (m_ucBKColor==2)
{
return m_Brush3;
}
// TODO: Return a different brush if the default is not desired
*/ return hbr;
}
void CReadPage1::ChangeBKColor()
{
if (((CButton*)GetDlgItem(IDC_CHECK_BKCHGCOLOR))->GetCheck()==1)
{
SenseList_SetBKColor(m_ListCtrl);
InvalidateRect(m_ListRect,true);
}
}
void CReadPage1::ShowInfo(LPTSTR lpInfo, unsigned char Ante)
{
int i=m_ListCtrl.GetItemCount();
if(i>200)
{
m_ListCtrl.DeleteItem(0);
i--;
}
LVITEM lvitem;
lvitem.mask=LVIF_TEXT;
lvitem.iItem=i;
lvitem.iSubItem=0;
// CTime tm(CTime::GetCurrentTime());
// _stprintf(temp, TEXT("%02d:%02d:%02d"),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
lvitem.pszText = lpInfo;
if (m_ucBKColor ==1)
{
m_ucBKColor =2;
m_ListCtrl.SetTextBkColor(RGB(255, 255, 255));
m_ListCtrl.SetBkColor(RGB(255, 255, 255));
}
else
if (m_ucBKColor ==2)
{
m_ucBKColor =1;
m_ListCtrl.SetTextBkColor(RGB(0, 255, 0));
m_ListCtrl.SetBkColor(RGB(0, 255, 0));
}
else
m_ucBKColor = 1;
m_ListCtrl.InsertItem(&lvitem);
lvitem.iSubItem=1;
_stprintf(temp, TEXT("%02d"),Ante+1);
lvitem.pszText=temp;
m_ListCtrl.SetItem(&lvitem);
m_ListCtrl.EnsureVisible(i,TRUE);
m_ListCtrl.UpdateWindow();
InvalidateRect(m_ListRect,true);
}
void CReadPage1::ResetBkColor()
{
}
void CReadPage1::OnButtonClear()
{
// TODO: Add your control notification handler code here
m_ListCtrl.DeleteAllItems();
SetDlgItemInt(IDC_EDIT_COUNTER,m_ListCtrl.GetItemCount(),FALSE);
}
void CReadPage1::OnButtonContinueRead()
{
GetDlgItem(IDC_STATIC)->SetWindowText("haha");
unsigned char dataAddr = 0x00;
unsigned char tagCount = 0;
unsigned char TagData[9];
CString str;
dataAddr = ((CComboBox*)GetDlgItem(IDC_COMBO_MTRADDR))->GetCurSel();
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_CONTINUEREAD)->EnableWindow(false);
status = Sense18K_ISOContinuousMTR(g_hCom, g_RAddr,dataAddr);
/// status = Sense18K_ISOMTR(g_hCom,g_RAddr,dataAddr,&tagCount);
PlayBeep();
if (status == ERR_NONE)
{
if (tagCount!=0) ClearContent();
else
{
ResetBkColor();
}
while(1)
{
// status = Sense18K_BufGetOneAndClear(g_hCom,g_RAddr,TagData);
status = Sense18K_BufGetOneNoClear(g_hCom,g_RAddr,TagData);
PlayBeep();
if (status==ERR_NONE)
{
str = FormatData(&TagData[1],TagData[0]-1);
ShowImg(TagData[TagData[0]]);
sprintf(temp,FormatData(&TagData[1],TagData[0]-1));
if (((CButton*)GetDlgItem(IDC_CHECK_LISTVIEW))->GetCheck()!=1)
SenseList_InsertItem(m_ListCtrl,temp,TagData[TagData[0]]+1);
else
SenseList_InsertItemAdd(m_ListCtrl,temp,TagData[TagData[0]]+1);
SenseList_SetBKColor(m_ListCtrl);
InvalidateRect(m_ListRect,true);
//2006-06-16 ShowInfo(temp,TagData[TagData[0]]);
// ChangeBKColor(TagData[TagData[0]]);
InvalidateRect(m_ListRect,true);
}
MSG msg;
if(::PeekMessage(&msg, m_hWnd, WM_MOUSEFIRST,WM_MOUSELAST, PM_REMOVE))
{
if ((msg.message== WM_LBUTTONDOWN) && (GetDlgItem(IDC_BUTTON_STOP)->m_hWnd == msg.hwnd))
{
status = Sense18K_ISOEndRead(g_hCom,g_RAddr);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_CONTINUEREAD)->EnableWindow(true);
return;
}
}
}
}
}
void CReadPage1::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
}
void CReadPage1::OnDblclkList3(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if (((CButton*)GetDlgItem(IDC_CHECK_BKCHGCOLOR))->GetCheck()!=1)
{
SenseList_SetBKColor(m_ListCtrl);
InvalidateRect(m_ListRect,true);
}
*pResult = 0;
}