www.pudn.com > data-bulktransfer.rar > usbhostDlg.cpp


// usbhostDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "usbhost.h" 
#include "usbhostDlg.h" 
 
#include "process.h" 
 
#include "usb100.h" 
#include "winioctl.h" 
#include "usbdriver.h" 
  
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
HWND hWindow;            
PointP* m_PointList;     
short MinValue,MaxValue; 
 
long m_InnerUHScreen;    
long m_InnerDHScreen;    
long m_InnerLWScreen;    
long m_InnerRWScreen;    
 
bool g_KeepGoing = false;    
bool g_Transfering = false;  
void __cdecl ReceiveThreadFunction(HANDLE hDevice);  
 
///////////////////////////////////////////////////////////////////////////// 
// 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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CUsbhostDlg dialog 
 
CUsbhostDlg::CUsbhostDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CUsbhostDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CUsbhostDlg) 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CUsbhostDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CUsbhostDlg) 
	DDX_Control(pDX, IDC_USB_LIST, m_UsbList); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CUsbhostDlg, CDialog) 
	//{{AFX_MSG_MAP(CUsbhostDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton) 
	ON_BN_CLICKED(IDC_DEVICE_BUTTON, OnDeviceButton) 
	ON_BN_CLICKED(IDC_CONFIG_BUTTON, OnConfigButton) 
	ON_BN_CLICKED(IDC_CLEARLIST_BUTTON, OnClearlistButton) 
	ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton) 
	ON_BN_CLICKED(IDC_ABOUT_BUTTON, OnAboutButton) 
	ON_BN_CLICKED(IDC_STOP_BUTTON, OnStopButton) 
	ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton) 
	ON_BN_CLICKED(IDC_REPLAY_BUTTON, OnReplayButton) 
	ON_BN_CLICKED(IDC_CLEARGRAPH_BUTTON, OnCleargraphButton) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CUsbhostDlg message handlers 
 
BOOL CUsbhostDlg::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 
    hWindow=*this;      
     
	m_LeftDis=250; 
	m_RightDis=15; 
	m_UpDis=15; 
	m_DownDis=60; 
 
    m_LeftRim=50; 
	m_RightRim=40; 
    m_UpRim=40; 
    m_DownRim=40; 
	 
	MinValue=0;   
	MaxValue=255; 
 
	m_xStart=0;   
	m_yStart=MinValue; 
 
    m_XLineStart.SetSize(20); 
    m_xn=0; 
 
    m_YLineStart.SetSize(20); 
    m_yn=0; 
 
	m_PointList=new PointP[256]; 
 
	for(int i=0;i<256;i++)  
	{		 
		m_PointList[i].x = i; 
		m_PointList[i].y = 0; 
	} 
 
	strcpy(DeviceName,"Ezusb-0"); 
 
	return TRUE;   
} 
 
void CUsbhostDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
    else if (nID == SC_CLOSE) 
	{ 
         if(g_KeepGoing) 
		 { 
			 MessageBox("请首先结束当前线程!", "错误", MB_ICONERROR | MB_OK); 
		     return; 
		 }	 
         OnOK(); 
	} 
	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 CUsbhostDlg::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(); 
 
		m_xStart=0;       
		m_yStart=MinValue; 
 
		GetUDLRrect(); 
         
		GetRectBlc(0,MinValue,256,MaxValue); 
         
		CDC* pDC;   
        pDC = GetDC(); 		 
		 
		CBrush brush(RGB(0,0,0)); 
	    pDC->FillRect(InnerRect,&brush); 
	     
		DrawBackLines(pDC); 
 
		DrawCurve(pDC); 
 
		DrawUDLRrect(pDC);  
		 
		DrawLab(pDC);   
		 
		ReleaseDC(pDC); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CUsbhostDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
/////////////////////////////////////////////////////////////////// 
// 
// 以下是画图的相关函数。 
// 
/////////////////////////////////////////////////////////////////// 
void CUsbhostDlg::GetUDLRrect() 
{ 
    CRect rect; 
    GetClientRect(&rect); 
 
    m_InnerUHScreen = m_UpRim+m_UpDis;               
    m_InnerDHScreen = rect.bottom - m_DownRim-m_DownDis;   
    m_InnerLWScreen = m_LeftRim + m_LeftDis;       
	m_InnerRWScreen = rect.right - m_RightRim-m_RightDis;   
 
	Urect.top=m_UpDis; 
	Urect.bottom=m_InnerUHScreen; 
	Urect.left=m_LeftDis; 
	Urect.right=rect.right-m_RightDis; 
 
	Drect.top=m_InnerDHScreen; 
	Drect.bottom=rect.bottom-m_DownDis; 
	Drect.left=m_LeftDis; 
	Drect.right=rect.right-m_RightDis; 
 
	Lrect.top=m_InnerUHScreen; 
	Lrect.bottom=m_InnerDHScreen; 
    Lrect.left=m_LeftDis; 
	Lrect.right=m_InnerLWScreen; 
 
	Rrect.top=m_InnerUHScreen; 
	Rrect.bottom=m_InnerDHScreen; 
    Rrect.left=m_InnerRWScreen; 
	Rrect.right=rect.right-m_RightDis; 
 
	InnerRect.top=m_InnerUHScreen; 
	InnerRect.bottom=m_InnerDHScreen; 
    InnerRect.left=m_InnerLWScreen; 
	InnerRect.right=m_InnerRWScreen;  
 
	TotalRect.top=m_UpDis; 
	TotalRect.bottom=rect.bottom-m_DownDis; 
    TotalRect.left=m_LeftDis; 
	TotalRect.right=rect.right-m_RightDis; 
} 
 
void CUsbhostDlg::GetRectBlc(float xRectStart,float yRectStart,float xRectEnd,float yRectEnd) 
{ 
	float m1,m2;   
	float x1,y1,x2,y2; 
	x1=min(xRectStart,xRectEnd); 
	x2=max(xRectStart,xRectEnd); 
	y1=min(yRectStart,yRectEnd); 
	y2=max(yRectStart,yRectEnd); 
	 
	float lx,ly; 
 
	lx=x2-x1;	 
    if(lx<0) return;    
 
    ly=y2-y1; 
	if(ly<0) return;    
 
    m1=lx/(m_InnerRWScreen-m_InnerLWScreen);    
	m2=ly/(m_InnerDHScreen-m_InnerUHScreen);	 
	m_XOriginScale =m1;       
	m_YOriginScale =m2;       
} 
 
void CUsbhostDlg::DrawBackLines (CDC *pDC) 
{ 
	float xx1; 
	float yy1; 
	float xx2; 
	float yy2; 
 
    XLPtoXVP(m_InnerLWScreen ,&xx1);  
	XLPtoXVP(m_InnerRWScreen ,&xx2); 
	YLPtoYVP(m_InnerDHScreen ,&yy1); 
	YLPtoYVP(m_InnerUHScreen ,&yy2); 
 
    GetBackLines(xx1,yy1,xx2,yy2); 
							 
    CPen penGray; 
    CPen* pOldPen; 
 
    penGray.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(128, 128, 128)); 
 
	pOldPen = pDC->SelectObject(&penGray);  
 
	int i;	 
	for(i=0;iMoveTo (m_XLineStart[i],m_InnerUHScreen); 
	    pDC->LineTo (m_XLineStart[i],m_InnerDHScreen); 
	} 
	 
    for(i=0;iMoveTo (m_InnerLWScreen,m_YLineStart[i]); 
	    pDC->LineTo (m_InnerRWScreen,m_YLineStart[i]); 
    } 
	 
    pDC->SelectObject (pOldPen); 
} 
 
void CUsbhostDlg::XLPtoXVP (int x,float *X) 
{ 
   *X=m_xStart+(x-m_InnerLWScreen)*m_XOriginScale;  
} 
 
void CUsbhostDlg::YLPtoYVP (int y,float *Y) 
{  	 
	*Y=m_yStart+(m_InnerDHScreen-y)*m_YOriginScale;	 
} 
 
void CUsbhostDlg::XVPtoXLP(float x,int *X) 
{ 
	float TempX; 
 
	TempX=((x-m_xStart)/m_XOriginScale+(float)0.5)+m_InnerLWScreen; 
	if(TempX > 3000) TempX = 3000; 
	*X=(int)TempX; 
} 
 
void CUsbhostDlg::YVPtoYLP(float y,int *Y) 
{ 
	float TempY;	 
 
	TempY=m_InnerDHScreen-((y-m_yStart)/m_YOriginScale+(float)0.5); 
	if(TempY > 3000) TempY = 3000; 
	*Y = (int)TempY; 
} 
 
void CUsbhostDlg::GetBackLines(float xRectStart,float yRectStart,float xRectEnd,float yRectEnd) 
{ 
		 
	if(m_XLineStart.GetSize()>0) 
	        m_XLineStart.RemoveAll(); 
	if(m_YLineStart.GetSize()>0) 
	        m_YLineStart.RemoveAll(); 
 
	    float xL; 
		float xd; 
		float xLine; 
 
        xL=xRectEnd-xRectStart;			 
		if(xL<0) xL=-xL; 
		if(xL==0) return; 
         
		xd=xL/8;   
         
        m_xLineStart[0]=xRectStart;      
		m_XLineStart.Add(m_InnerLWScreen);  
		m_xn=0;		 
 
		xLine=xd; 
 
		while(xLineSelectObject (&npen); 
 
    pDC->SetROP2(R2_COPYPEN);  
     
    XVPtoXLP(m_PointList[0].x,&x1); 
    YVPtoYLP(m_PointList[0].y,&y1); 
 
    pDC->MoveTo (x1,y1); 
    for(int i=1;i<256;i++) 
    { 
       XVPtoXLP(m_PointList[i].x,&x1); 
       YVPtoYLP(m_PointList[i].y,&y1); 
 	   pDC->LineTo (x1,y1); 
	} 
    pDC->SelectObject (npOldPen); 
} 
 
void CUsbhostDlg::DrawUDLRrect (CDC *pDC) 
{ 
	pDC->SetBkColor(12632256);   
 
	CBrush brush(pDC->GetBkColor ()); 
	pDC->FillRect(Urect,&brush); 
	pDC->FillRect(Drect,&brush); 
	pDC->FillRect(Lrect,&brush); 
	pDC->FillRect(Rrect,&brush); 
 
	pDC->DrawEdge(TotalRect,EDGE_SUNKEN,BF_RECT); 
} 
 
void CUsbhostDlg::DrawLab(CDC *pDC) 
{	 
    pDC->TextOut(m_InnerLWScreen-30,m_InnerUHScreen-27,"幅度值");  
	pDC->TextOut(m_InnerLWScreen/2-15 + m_InnerRWScreen/2,m_InnerDHScreen+ 20, "点数值"); 
 
	char str[10]; 
    	 
    for(int i=0;iTextOut(m_InnerLWScreen-45,m_YLineStart[i]-10,str);  
    } 
	 
	for(i=0;iTextOut(m_XLineStart[i]-5,m_InnerDHScreen+5,str);  
    } 
 
	pDC->TextOut(m_InnerLWScreen+150,m_InnerUHScreen-27,"波形显示");  
} 
 
/////////////////////////////////////////////////////////////////// 
// 
// 以下是AN2131相关函数。 
// 
/////////////////////////////////////////////////////////////////// 
BOOLEAN CUsbhostDlg::UsbOpenDriver (HANDLE *phDeviceHandle, PCHAR devname) 
{ 
   char completeDeviceName[64] = ""; 
   char pcMsg[64] = ""; 
    
   strcat (completeDeviceName,"\\\\.\\"); 
    
   strcat (completeDeviceName,devname); 
    
   *phDeviceHandle = CreateFile(completeDeviceName, 
                                GENERIC_WRITE, 
                                FILE_SHARE_WRITE, 
                                NULL, 
                                OPEN_EXISTING, 
                                0, 
                                NULL); 
    
   if (*phDeviceHandle == INVALID_HANDLE_VALUE)  
      return (FALSE); 
   else  
      return (TRUE);    
} 
 
void CUsbhostDlg::OnDeviceButton()  
{ 
	// TODO: Add your control notification handler code here 
    USB_DEVICE_DESCRIPTOR output; 
    HANDLE  hDevice = NULL; 
	BOOLEAN bResult = FALSE; 
    ULONG   nBytes;	 
	CString str; 
 
    if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)  
	{ 
		MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK); 
		hDevice = NULL; 
		return; 
	} 
 
	if (hDevice != NULL) 
    { 
        bResult = DeviceIoControl (hDevice, 
                                   IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, 
                                   NULL, 
                                   0, 
                                   &output, 
                                   sizeof(USB_DEVICE_DESCRIPTOR), 
                                   &nBytes, 
                                   NULL); 
    } 
 
	if (bResult==TRUE) 
    { 
		m_UsbList.AddString("USB Device Descriptor"); 
		str.Format(_T("bLength:0x%x"),output.bLength);   
        m_UsbList.AddString(str); 
		str.Format(_T("bDescriptorType:0x%x"),output.bDescriptorType);  
		m_UsbList.AddString(str); 
		str.Format(_T("bcdUSB:0x%x"),output.bcdUSB);  
		m_UsbList.AddString(str); 
        str.Format(_T("bDeviceClass:0x%x"),output.bDeviceClass);  
		m_UsbList.AddString(str); 
		str.Format(_T("bDeviceSubClass:0x%x"),output.bDeviceSubClass);   
		m_UsbList.AddString(str); 
        str.Format(_T("bDeviceProtocol:0x%x"),output.bDeviceProtocol);   
		m_UsbList.AddString(str); 
        str.Format(_T("bMaxPacketSize0:0x%x"),output.bMaxPacketSize0);   
        m_UsbList.AddString(str); 
        str.Format(_T("idVendor:0x%x"),output.idVendor);  
        m_UsbList.AddString(str); 
		str.Format(_T("idProduct:0x%x"),output.idProduct);  
		m_UsbList.AddString(str); 
		str.Format(_T("bcdDevice:0x%x"),output.bcdDevice);  
        m_UsbList.AddString(str); 
		str.Format(_T("iManufacturer:0x%x"),output.iManufacturer);  
        m_UsbList.AddString(str); 
		str.Format(_T("iProduct:0x%x"),output.iProduct); 
        m_UsbList.AddString(str); 
        str.Format(_T("iSerialNumber:0x%x"),output.iSerialNumber);  
        m_UsbList.AddString(str); 
		str.Format(_T("bNumConfigurations:0x%x"),output.bNumConfigurations);  
        m_UsbList.AddString(str);		 
    } 
    else 
		MessageBox("读取设备描述符失败!", "错误", MB_ICONERROR | MB_OK); 
           
    CloseHandle (hDevice); 
} 
 
void CUsbhostDlg::OnConfigButton()  
{ 
	// TODO: Add your control notification handler code here 
    USB_CONFIGURATION_DESCRIPTOR output; 
    HANDLE  hDevice = NULL; 
	BOOLEAN bResult = FALSE; 
    ULONG   nBytes; 
	CString str; 
 
    if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)  
	{ 
		MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK); 
		hDevice = NULL; 
		return; 
	} 
 
	if (hDevice != NULL) 
    { 
        bResult = DeviceIoControl (hDevice, 
                                   IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR, 
                                   NULL, 
                                   0, 
                                   &output, 
                                   sizeof(USB_CONFIGURATION_DESCRIPTOR), 
                                   &nBytes, 
                                   NULL); 
    } 
 
	if (bResult==TRUE) 
    { 
		m_UsbList.AddString("USB Configuration Descriptor"); 
		str.Format(_T("bLength:0x%x"),output.bLength);   
        m_UsbList.AddString(str); 
		str.Format(_T("bDescriptorType:0x%x"),output.bDescriptorType);  
		m_UsbList.AddString(str); 
		str.Format(_T("wTotalLength:0x%x"),output.wTotalLength);  
		m_UsbList.AddString(str); 
        str.Format(_T("bNumInterfaces:0x%x"),output.bNumInterfaces);  
		m_UsbList.AddString(str); 
		str.Format(_T("bConfigurationValue:0x%x"),output.bConfigurationValue);  
		m_UsbList.AddString(str); 
        str.Format(_T("iConfiguration:0x%x"),output.iConfiguration);  
		m_UsbList.AddString(str); 
        str.Format(_T("bmAttributes:0x%x"),output.bmAttributes);  
        m_UsbList.AddString(str); 
        str.Format(_T("MaxPower:0x%x"),output.MaxPower);  
        m_UsbList.AddString(str); 
    } 
    else 
		MessageBox("读取配置描述符失败!", "错误", MB_ICONERROR | MB_OK); 
           
    CloseHandle (hDevice); 
} 
 
void CUsbhostDlg::OnStartButton()  
{ 
	// TODO: Add your control notification handler code here 
	HANDLE  hDevice = NULL; 
	BOOLEAN bResult = FALSE; 
	ULONG   nBytes; 
	unsigned char outValue;    
	BULK_TRANSFER_CONTROL bulkControl; 
	unsigned long input=8; 
 
    if(g_KeepGoing) 
	{ 
		MessageBox("请首先结束当前线程!", "错误", MB_ICONERROR | MB_OK); 
		return; 
	} 
 
	if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)  
	{    	  
		MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK); 
		return; 
	} 
 
	outValue=0x1A; 
	bulkControl.pipeNum = 6;   
	bResult = DeviceIoControl (hDevice, 
                              IOCTL_EZUSB_BULK_WRITE, 
                              &bulkControl, 
                              sizeof(BULK_TRANSFER_CONTROL), 
                              &outValue, 
                              1, 
                              &nBytes, 
                              NULL); 
    if (bResult != TRUE)  
	{ 
        AfxMessageBox("启动AD1674失败!"); 
        CloseHandle(hDevice);	 
		return; 
	} 
     
	bResult = DeviceIoControl (hDevice, 
                           IOCTL_Ezusb_RESETPIPE, 
                           &input, 
                           sizeof(unsigned long), 
                           NULL, 
                           0, 
                           &nBytes, 
                           NULL); 
 
    if (bResult != TRUE)  
	{ 
    	AfxMessageBox("复位管道8失败!"); 
        CloseHandle(hDevice);	   
	    return; 
	} 
 
    g_KeepGoing = true; 
    if(_beginthread(ReceiveThreadFunction, 0, hDevice) < 0) 
    { 
		AfxMessageBox("启动接收数据线程失败!"); 
    } 
} 
 
void __cdecl ReceiveThreadFunction(HANDLE hDevice) 
{ 
	BOOLEAN bResult = FALSE; 
	ULONG   nBytes; 
	BULK_TRANSFER_CONTROL bulkControl; 
    unsigned char  InBuffer[512]; 
	unsigned short temp,TempMax,TempMin; 
	CString str; 
 
    while(g_KeepGoing) 
	{ 
        nBytes = 0; 
        bulkControl.pipeNum = 8; 
        g_Transfering= FALSE; 
		bResult = DeviceIoControl (hDevice, 
	            			   IOCTL_EZUSB_BULK_READ, 
							   &bulkControl, 
							   sizeof(BULK_TRANSFER_CONTROL), 
							   InBuffer, 
							   512, 
							   &nBytes, 
							   NULL); 
            
		if (bResult != TRUE) 
		{ 
			 AfxMessageBox("接收数据失败!"); 
			 goto exit; 
		} 
 
		if (nBytes==512)  
		{ 
		    for (int i=0;i<256;i++) 
			{ 
				 
                temp=InBuffer[2*i]*16+InBuffer[2*i+1]; 
				if(temp>4096) temp=2048;  
				m_PointList[i].y = temp; 
			} 
			 
			TempMax=TempMin=m_PointList[0].y; 
            for (i=1;i<256;i++) 
			{				 
                if(m_PointList[i].y>TempMax) 
					TempMax=m_PointList[i].y; 
                else if(m_PointList[i].yTempMax) 
					TempMax=m_PointList[i].y; 
                else if(m_PointList[i].y