// Page1.cpp : 实现文件
//

#include "stdafx.h"
#include "UHFReader288VC.h"
#include "Page1.h"
int FrmHandle;
int fcmdRet;
byte fComAddr;
BOOL InventoryFlag;
HINSTANCE g_hRRLibrary; 
int ReadTime =0;
unsigned char Target =0;
unsigned char ReadSession =0;
unsigned char Qvalue;
unsigned char Session;
unsigned char scanTime;
unsigned char cursession;
int NoCardCount =0;
int AATimes =0;
bool chkTarget =false;
unsigned char profile=0xC5;
	
unsigned char VersionInfo[2];			//软件版本
unsigned char ReaderType;				//读写器型号
unsigned char TrType;		//支持的协议
unsigned char dmaxfre;          //当前读写器使用的最高频率
unsigned char dminfre;          //当前读写器使用的最低频率
unsigned char powerdBm;             //读写器的输出功率
unsigned char ScanTime;
unsigned char Ant;
unsigned char BeepEn;
unsigned char OutputRep;
unsigned char CheckAnt;

unsigned char AntennaNum=0;
DWORD StartTime;
DWORD StopTime;

// Page1 对话框

IMPLEMENT_DYNAMIC(Page1, CDialog)

Page1::Page1(CWnd* pParent /*=NULL*/)
	: CDialog(Page1::IDD, pParent)
{

}

Page1::~Page1()
{
}

void Page1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	DDX_Control(pDX, IDC_LIST1, m_list1);
}


BEGIN_MESSAGE_MAP(Page1, CDialog)
	ON_BN_CLICKED(IDC_RS232, &Page1::OnBnClickedRs232)
	ON_BN_CLICKED(IDC_TCP, &Page1::OnBnClickedTcp)
	ON_BN_CLICKED(IDC_BUTTON1, &Page1::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &Page1::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &Page1::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &Page1::OnBnClickedButton4)//
	ON_BN_CLICKED(IDC_BUTTON6, &Page1::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON5, &Page1::OnBnClickedButton5)
	ON_WM_TIMER()
	ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()


// Page1 消息处理程序

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

	// TODO:  在此添加额外的初始化
	//Session
	int i=0;
    CString str;
	for(i=0;i<16;i++)
	{
		str.Format(_T("%d"),i);
		((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString(str);	
	}
	((CComboBox*)GetDlgItem(IDC_COMBO4))->SetCurSel(4);
	//Q
	for(i=0;i<4;i++)
	{
		str.Format(_T("%d"),i);
		((CComboBox*)GetDlgItem(IDC_COMBO3))->AddString(str);	
	}
	((CComboBox*)GetDlgItem(IDC_COMBO3))->AddString(_T("AUTO-1"));	
	((CComboBox*)GetDlgItem(IDC_COMBO3))->AddString(_T("AUTO-2"));	
	((CComboBox*)GetDlgItem(IDC_COMBO3))->AddString(_T("AUTO-3"));	
	((CComboBox*)GetDlgItem(IDC_COMBO3))->SetCurSel(5);
    
	//COM
	for(i=1;i<10;i++)
	{
		str.Format(_T("%d"),i);
		((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(_T("COM")+str);	
	}
	((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
    //波特率
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString(_T("9600bps"));	
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString(_T("19200bps"));	
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString(_T("38400bps"));	
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString(_T("57600bps"));	
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString(_T("115200bps"));	
    ((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(3);
	
	//端口初始化
	((CEdit*)GetDlgItem(IDC_EDIT2))->SetWindowText(_T("27011"));
	//IP初始化
	((CEdit*)GetDlgItem(IDC_IPADDRESS1))->SetWindowText(_T("192.168.0.250"));

    //初始化列表
	m_list1.InsertColumn(0,_T("序号"),LVCFMT_LEFT,80);
	m_list1.InsertColumn(1,_T("EPC号"),LVCFMT_LEFT,250);
	m_list1.InsertColumn(2,_T("长度"),LVCFMT_LEFT,80);
	m_list1.InsertColumn(3,_T("RSSI"),LVCFMT_LEFT,80);
	m_list1.InsertColumn(4,_T("次数"),LVCFMT_LEFT,80);
	m_list1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES |LVS_EX_HEADERDRAGDROP);

	//TARGET
	((CComboBox*)GetDlgItem(IDC_COMBO5))->AddString(_T("A"));	
	((CComboBox*)GetDlgItem(IDC_COMBO5))->AddString(_T("B"));	
	((CComboBox*)GetDlgItem(IDC_COMBO5))->SetCurSel(0);


	//MaxScanTime
	for(i=3;i<256;i++)
	{
		str.Format(_T("%d*100ms"),i);
		((CComboBox*)GetDlgItem(IDC_COMBO6))->AddString(str);	
	}
	((CComboBox*)GetDlgItem(IDC_COMBO6))->SetCurSel(47);

	((CEdit*)GetDlgItem(IDC_EDIT4))->SetWindowText(_T("5"));

	((CEdit*)GetDlgItem(IDC_EDIT3))->SetWindowText(_T("10000"));

	((CButton *)GetDlgItem(IDC_RS232))->SetCheck(1);

	((CButton *)GetDlgItem(IDC_CHECK21))->SetCheck(1);

	((CButton *)GetDlgItem(IDC_ANT1))->SetCheck(1);

	g_hRRLibrary = LoadLibrary(_T("UHFReader288.dll"));

	if (g_hRRLibrary ==NULL)
		return FALSE;
	if(!(RR_OpenComPort = (POpenComPort)GetProcAddress(g_hRRLibrary,"OpenComPort")))
		return FALSE;
	if(!(RR_CloseComPort = (PCloseComPort)GetProcAddress(g_hRRLibrary,"CloseComPort")))
		return FALSE;
	if(!(RR_CloseSpecComPort = (PCloseSpecComPort)GetProcAddress(g_hRRLibrary,"CloseSpecComPort")))
		return FALSE;

	if(!(RR_GetReaderInformation = (PGetReaderInformation)GetProcAddress(g_hRRLibrary,"GetReaderInformation")))
		return FALSE;

	if(!(RR_OpenNetPort = (POpenNetPort)GetProcAddress(g_hRRLibrary,"OpenNetPort")))
		return FALSE;
	if(!(RR_CloseNetPort = (PCloseNetPort)GetProcAddress(g_hRRLibrary,"CloseNetPort")))
		return FALSE;

	if(!(RR_Inventory_G2 = (PInventory_G2)GetProcAddress(g_hRRLibrary,"Inventory_G2")))
		return FALSE;
	if(!(RR_SelectCMDByAntenna = (PSelectCMDByAntenna)GetProcAddress(g_hRRLibrary,"SelectCMDByAntenna")))
		return FALSE;
	if(!(RR_SetProfile = (PSetProfile)GetProcAddress(g_hRRLibrary,"SetProfile")))
		return FALSE;
	if(!(RR_StopImmediately = (PStopImmediately)GetProcAddress(g_hRRLibrary,"StopImmediately")))
		return FALSE;

	((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);
	DisableButton();
	return TRUE;  // return TRUE unless you set the focus to a control

}

void Page1::EnableButton()
{
	/*((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(TRUE);*/
	((CButton *)GetDlgItem(IDC_BUTTON5))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON6))->EnableWindow(TRUE);
}
void Page1::DisableButton()
{
	/*((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);*/
	((CButton *)GetDlgItem(IDC_BUTTON5))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON6))->EnableWindow(FALSE);
}

void Page1::InventoryEPC()
{
	BOOL ANTFLAG=FALSE;
	for(int m_index=0;m_index<16;m_index++)//遍历4天线
	{
		if(AntArr[m_index]==1)
		{
			int ant=0;
			switch(m_index)
			{
			case 0:
				ant=0x80;
				break;
			case 1:
				ant=0x81;
				break;
			case 2:
				ant=0x82;
				break;
			case 3:
				ant=0x83;
				break;
			case 4:
				ant=0x84;
				break;
			case 5:
				ant=0x85;
				break;
			case 6:
				ant=0x86;
				break;
			case 7:
				ant=0x87;
				break;

			case 8:
				ant=0x88;
				break;
			case 9:
				ant=0x89;
				break;
			case 10:
				ant=0x8A;
				break;
			case 11:
				ant=0x8B;
				break;
			case 12:
				ant=0x8C;
				break;
			case 13:
				ant=0x8D;
				break;
			case 14:
				ant=0x8E;
				break;
			case 15:
				ant=0x8F;
				break;
			default:
				ant=0x80;
				break;
			}
			Query(ant);
			ANTFLAG=TRUE;
		}
	}
	if(!ANTFLAG)
	{
		Query(0);
	}
}
void Page1::Query(int Ant)
{  
	byte OutAnt = 0;
	int CardNum = 0;
	int Totallen = 0;
	int EPClen=0;
	int m=0;
	byte EPC[20000];
	int CardIndex;
	CString temps, temp,sEPC;
	byte MaskMem = 0;
	byte MaskAdr[2];
	byte MaskLen = 0;
	byte MaskData[100];
	byte MaskFlag = 0;
	byte AdrTID = 0;
	byte LenTID = 0;
	BYTE TIDFlag=0;//询查EPC

	byte FastFlag=0;
	MaskFlag = 0;
	CardNum = 0;
	byte InAnt=Ant;
	
	if(Session==4)
		Session=255;
	if(Ant==0)
	{
		FastFlag=0;
	}
	else
	{
		FastFlag=1;
	}
	if(((CButton *)GetDlgItem(IDC_CHECK5))->GetCheck()==1)
	{
		AdrTID=0;
		LenTID=6;
		TIDFlag=1;
	}
	fcmdRet = RR_Inventory_G2(&fComAddr, Qvalue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, InAnt, scanTime, FastFlag, EPC, &OutAnt, &Totallen, &CardNum, FrmHandle);
	if((CardNum<150) && (profile==1)&&(ReadSession==253))
	{
		profile = 0xC5;
		RR_SetProfile(&fComAddr,&profile,FrmHandle);
	}
	if(CardNum>0)
	{
		AATimes=0;
		m = 1;
		if (CardNum == 0)
		{
			return;
		}
		for (CardIndex = 0 ;CardIndex<CardNum;CardIndex++)
		{
			temp=_T("");
			temps=_T("");
			BOOL EPCflag = FALSE;
			EPClen = EPC[m - 1];
			byte EPC1[250];
			memcpy(EPC1,&EPC[m], EPClen);
			byte RSSI=EPC[m+EPClen];
			m = m + EPClen + 2;
			//得到标签的EPC号
			for(int n=0;n<EPClen;n++)
			{
				temp.Format(_T("%02X"),EPC1[n]);
				temps=temps+temp;
			}
			BOOL inList=FALSE;
			
			
			for(int p=0;p<m_list1.GetItemCount();p++)
			{
				if(m_list1.GetItemText(p,1)==temps)//如果存在，次数加一
				{
					inList=TRUE;
					int m=(int)_tcstol(m_list1.GetItemText(p,4),NULL,10);
					m++;
					CString str_count;

					str_count.Format(_T("%d"),RSSI);
					m_list1.SetItemText(p,3,str_count);//RSSI

					str_count.Format(_T("%d"),m);
					m_list1.SetItemText(p,4,str_count);//次数
				}
			}
			if(!inList)//不存在插入列表
			{
				CString str_ID;
				int index=m_list1.GetItemCount();
				//序号
				str_ID.Format(_T("%d"),index+1);
				m_list1.InsertItem(index,str_ID);
				//EPC
				m_list1.SetItemText(index,1,temps);
                //长度
                str_ID.Format(_T("%d"),EPClen);
				m_list1.SetItemText(index,2,str_ID);
                //RSSI
				str_ID.Format(_T("%d"),RSSI);
				m_list1.SetItemText(index,3,str_ID);
				//次数
				m_list1.SetItemText(index,4,_T("1"));
				m_list1.EnsureVisible(index, FALSE);
			}
		}
	}
	else
	{
		if(profile==5)
		{
			profile = 0xCD;
			RR_SetProfile(&fComAddr,&profile,FrmHandle);
		}
		AATimes++;
		if(AATimes>=NoCardCount)
		{
			AATimes=0;
			if(chkTarget)
			{
				Target =1 -Target;
				if(ReadSession==254)
					profile = 0xC5;
				else if(ReadSession ==253)
					profile = 0xC1;
				RR_SetProfile(&fComAddr,&profile,FrmHandle);
			}
		}
	}

}  
void Page1::OnBnClickedRs232()
{
	// TODO: 在此添加控件通知处理程序代码
	OnBnClickedButton4();
	((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);
}

void Page1::OnBnClickedTcp()
{
	OnBnClickedButton2();
	((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
	((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(TRUE);
	((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);
}

//打开串口连接
void Page1::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strip;
	CString str;
	fComAddr=255;
	FrmHandle=0;
	AntennaNum=8;
	strip="";
	int port=((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel()+1;
	byte baud=((CComboBox*)GetDlgItem(IDC_COMBO2))->GetCurSel();
	if(baud>2)baud=baud+2;
	fcmdRet=RR_OpenComPort(port,&fComAddr,baud,&FrmHandle);
	if(fcmdRet==0)
	{
		fcmdRet = RR_GetReaderInformation(&fComAddr,VersionInfo,&ReaderType, &TrType,&dmaxfre,&dminfre, &powerdBm,&ScanTime,&Ant,&BeepEn,&OutputRep,&CheckAnt, FrmHandle);
		if(fcmdRet==0)
		{
			if((ReaderType==0x27)||(ReaderType==0x65)||(ReaderType==0x77)||(ReaderType==0x57)||(ReaderType==0x39))
			{
				AntennaNum=16;
			}
		}

		EnableButton();
		((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(TRUE);
		((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);
		MessageBox(_T("连接成功"),_T("提示"),0);
	}
	else
	{
		MessageBox(_T("连接失败"),_T("提示"),0);
	}
}

//关闭串口连接
void Page1::OnBnClickedButton2()
{
	//if((FrmHandle>0)&&(FrmHandle<256))
	{
		if(FrmHandle>0)
			fcmdRet=RR_CloseSpecComPort(FrmHandle);
		((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(TRUE);
		((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);
		FrmHandle=-1;
		DisableButton();
	}
	// TODO: 在此添加控件通知处理程序代码
}

//打开网口连接
void Page1::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	CString strip;
	CString str;
	fComAddr=255;
	FrmHandle=0;
	AntennaNum=0;
	strip="";
	GetDlgItemText(IDC_EDIT2,str);
	int port=_tcstol(str,NULL,10);
	GetDlgItemText(IDC_IPADDRESS1,strip);
	DWORD dwFileNameCharNum = WideCharToMultiByte(CP_OEMCP,NULL,strip.GetBuffer(strip.GetLength()),-1,NULL,0,NULL,FALSE);
	char *ip = new char[dwFileNameCharNum+1];
	WideCharToMultiByte (CP_OEMCP,NULL,strip.GetBuffer(strip.GetLength()),-1,ip,dwFileNameCharNum,NULL,FALSE);
	ip[dwFileNameCharNum]='\0';

	fcmdRet=RR_OpenNetPort(port,ip, &fComAddr,&FrmHandle);
	if(fcmdRet==0)
	{
		fcmdRet = RR_GetReaderInformation(&fComAddr,VersionInfo,&ReaderType, &TrType,&dmaxfre,&dminfre, &powerdBm,&ScanTime,&Ant,&BeepEn,&OutputRep,&CheckAnt, FrmHandle);
		if(fcmdRet==0)
		{
			if((ReaderType==0x27)||(ReaderType==0x65)||(ReaderType==0x77)||(ReaderType==0x57)||(ReaderType==0x39))
			{
				AntennaNum=16;
			}
		}
		EnableButton();
		((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(TRUE);
		MessageBox(_T("连接成功"),_T("提示"),0);
	}
	else
	{
		MessageBox(_T("连接失败"),_T("提示"),0);
	}
}

//关闭网口连接
void Page1::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	if((FrmHandle>0)&&(FrmHandle<256))
	{
		fcmdRet=RR_CloseNetPort(FrmHandle);
		((CButton *)GetDlgItem(IDC_BUTTON1))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON2))->EnableWindow(FALSE);
		((CButton *)GetDlgItem(IDC_BUTTON3))->EnableWindow(TRUE);
		((CButton *)GetDlgItem(IDC_BUTTON4))->EnableWindow(FALSE);
		FrmHandle=-1;
		DisableButton();
	}
}

//启动/停止读卡
void Page1::OnBnClickedButton6()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;
	((CButton *)GetDlgItem(IDC_BUTTON6))->GetWindowText(str);
	byte Cursession =0;
	int SelectAntenna =0;
	//byte portNum,
	byte Selaction =0;
	byte MaskMem=1;
	byte MaskAdr[2];
	byte MaskLen=0;
	byte MaskData[100];
	byte Truncate=0;
	
	if(str=="开始")
	{
		GetDlgItemText(IDC_EDIT3,str);
		ReadTime =_tcstol(str,NULL,10);


		GetDlgItemText(IDC_EDIT4,str);
		NoCardCount =_tcstol(str,NULL,10);
		AATimes=0;

		Qvalue= ((CComboBox*)GetDlgItem(IDC_COMBO4))->GetCurSel();
		int index = ((CComboBox*)GetDlgItem(IDC_COMBO3))->GetCurSel();
		scanTime = ((CComboBox*)GetDlgItem(IDC_COMBO6))->GetCurSel()+3;
		Target = ((CComboBox*)GetDlgItem(IDC_COMBO5))->GetCurSel();

		if(index==4)
		{
			ReadSession = 255;
		}
		else if(index==5)
		{
			ReadSession = 254;
		}
		else if(index==6)
		{
			ReadSession = 253;
		}
		else
		{
			ReadSession = index;
		}

		if(ReadSession==254 || ReadSession==253)
		{
			if(Session==254)
			{
				Session = 253;
				cursession=2;
			}
			else
			{
				Session = 254;
				cursession=3;
			}

		}
		else
		{
			Session = ReadSession;
		}
		if(((CButton *)GetDlgItem(IDC_CHECK21))->GetCheck())
			chkTarget = true;
		else
			chkTarget = false;
		
		
		((CButton *)GetDlgItem(IDC_BUTTON6))->SetWindowText(_T("停止"));
		m_list1.DeleteAllItems();
		nFlag=FALSE;
		memset(AntArr,0,16);
		if(((CButton *)GetDlgItem(IDC_ANT1))->GetCheck())
		{
			AntArr[0]=1;
			SelectAntenna |=0x0001;
		}
		if(((CButton *)GetDlgItem(IDC_ANT2))->GetCheck())
		{
			AntArr[1]=1;
			SelectAntenna |=0x0002;
		}
		if(((CButton *)GetDlgItem(IDC_ANT3))->GetCheck())
		{
			AntArr[2]=1;
			SelectAntenna |=0x0004;
		}
		if(((CButton *)GetDlgItem(IDC_ANT4))->GetCheck())
		{
			AntArr[3]=1;
			SelectAntenna |=0x0008;
		}
		if(((CButton *)GetDlgItem(IDC_ANT5))->GetCheck())
		{
			AntArr[4]=1;
			SelectAntenna |=0x0010;
		}
		if(((CButton *)GetDlgItem(IDC_ANT6))->GetCheck())
		{
			AntArr[5]=1;
			SelectAntenna |=0x0020;
		}
		if(((CButton *)GetDlgItem(IDC_ANT7))->GetCheck())
		{
			AntArr[6]=1;
			SelectAntenna |=0x0040;
		}
		if(((CButton *)GetDlgItem(IDC_ANT8))->GetCheck())
		{
			AntArr[7]=1;
			SelectAntenna |=0x0080;
		}

		if(((CButton *)GetDlgItem(IDC_ANT9))->GetCheck())
		{
			AntArr[8]=1;
			SelectAntenna |=0x0100;
		}
		if(((CButton *)GetDlgItem(IDC_ANT10))->GetCheck())
		{
			AntArr[9]=1;
			SelectAntenna |=0x0200;
		}
		if(((CButton *)GetDlgItem(IDC_ANT11))->GetCheck())
		{
			AntArr[10]=1;
			SelectAntenna |=0x0400;
		}
		if(((CButton *)GetDlgItem(IDC_ANT12))->GetCheck())
		{
			AntArr[11]=1;
			SelectAntenna |=0x0800;
		}
		if(((CButton *)GetDlgItem(IDC_ANT13))->GetCheck())
		{
			AntArr[12]=1;
			SelectAntenna |=0x1000;
		}
		if(((CButton *)GetDlgItem(IDC_ANT14))->GetCheck())
		{
			AntArr[13]=1;
			SelectAntenna |=0x2000;
		}
		if(((CButton *)GetDlgItem(IDC_ANT15))->GetCheck())
		{
			AntArr[14]=1;
			SelectAntenna |=0x4000;
		}
		if(((CButton *)GetDlgItem(IDC_ANT16))->GetCheck())
		{
			AntArr[15]=1;
			SelectAntenna |=0x8000;
		}

		if(ReadSession==254 || ReadSession==253)
		{
			RR_SelectCMDByAntenna(&fComAddr,SelectAntenna,AntennaNum, cursession, 0, MaskMem, MaskAdr, MaskLen, MaskData, 0,FrmHandle);
			Sleep(5);
			RR_SelectCMDByAntenna(&fComAddr,SelectAntenna,AntennaNum, cursession, 0, MaskMem, MaskAdr, MaskLen, MaskData, 0,FrmHandle);
			Sleep(5);
			RR_SelectCMDByAntenna(&fComAddr,SelectAntenna,AntennaNum, cursession, 0, MaskMem, MaskAdr, MaskLen, MaskData, 0,FrmHandle);
			Sleep(5);
			RR_SelectCMDByAntenna(&fComAddr,SelectAntenna,AntennaNum, cursession, 0, MaskMem, MaskAdr, MaskLen, MaskData, 0,FrmHandle);
			Sleep(5);
			if(ReadSession==254)
				profile = 0xC5;
			else if(ReadSession==253)
				profile = 0xC1;
			RR_SetProfile(&fComAddr,&profile,FrmHandle);
		}
		str.Empty();
		SetTimer(2,5,NULL);
		StartTime = GetTickCount();
	}
	else
	{
		((CButton *)GetDlgItem(IDC_BUTTON6))->SetWindowText(_T("开始"));
		KillTimer(2);
	}
}

//清屏
void Page1::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list1.DeleteAllItems();
	nFlag=FALSE;
}

//定时器
void Page1::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
    if(nIDEvent==2)
	{
		if((int)(GetTickCount()-StartTime) > ReadTime)
		{
			RR_StopImmediately(&fComAddr,FrmHandle);
			KillTimer(2);
			((CButton *)GetDlgItem(IDC_BUTTON6))->SetWindowText(_T("开始"));
		}
		if(nFlag)return;
		nFlag=TRUE;
		InventoryEPC();
		nFlag=FALSE;
	}
	CDialog::OnTimer(nIDEvent);
}

void Page1::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);

	KillTimer(2);
	((CButton *)GetDlgItem(IDC_BUTTON6))->SetWindowText(_T("开始"));
	// TODO: 在此处添加消息处理程序代码
}
