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

📄 usbhostdlg.cpp

📁 本代码是用vc开发的波形发生器的应用程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	}

	input.Index=2;
	input.LanguageId=0;
	bResult = DeviceIoControl (hDevice,
                               IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
                               &input,
                               sizeof(GET_STRING_DESCRIPTOR_IN),
                               &output,
                               4, 
                               &nBytes,
                               NULL);
	if (bResult!=TRUE) 
	{
		MessageBox("读取字符串描述符失败!", "错误", MB_ICONERROR | MB_OK);
        CloseHandle (hDevice);
		return;
	}
    else
	{
		bResult = DeviceIoControl (hDevice,
                                   IOCTL_Ezusb_GET_STRING_DESCRIPTOR,
                                   &input,
                                   sizeof(GET_STRING_DESCRIPTOR_IN),
                                   &output0,
                                   output.bLength, 
                                   &nBytes,
                                   NULL);
		if (bResult!=TRUE) 
		{
			MessageBox("读取字符串描述符失败!", "错误", MB_ICONERROR | MB_OK);
            CloseHandle (hDevice);
		    return;
		}
		else 
		{
			m_UsbList.AddString("USB String Descriptor");			
			m_UsbList.AddString("String Descriptor 2");
			str.Format(_T("bLength:0x%x"),output0[0]);  
            m_UsbList.AddString(str);
		    str.Format(_T("bDescriptorType:0x%x"),output0[1]); 
		    m_UsbList.AddString(str);		    
	        sprintf(tempbuff[0],"bString:");
		    for (int i=0;i<output.bLength-2;i++) 
			{
				sprintf(tempbuff[1],"%c",output0[i+2]);
				strcat(tempbuff[0],tempbuff[1]);
			}
			m_UsbList.AddString((CString)tempbuff[0]);
		}
	}
    
    CloseHandle (hDevice);
}

void CUsbhostDlg::OnFrameButton() 
{
	// TODO: Add your control notification handler code here
	unsigned long  output;
    HANDLE  hDevice = NULL;
	BOOLEAN bResult = FALSE;
    ULONG   nBytes;	
	CString str;
	
    if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) 
	{
		MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
		hDevice = NULL;
		return;
	}

	bResult = DeviceIoControl (hDevice,
                               IOCTL_EZUSB_GET_CURRENT_FRAME_NUMBER,
                               NULL,
                               0,
                               &output,
                               sizeof(unsigned long),
                               &nBytes,
                               NULL);
	if (bResult!=TRUE)
		MessageBox("读取当前帧号失败!", "错误", MB_ICONERROR | MB_OK);
    else 
	{
		str.Format(_T("当前帧号:%d"),output); 
        m_UsbList.AddString(str);
    }

	CloseHandle(hDevice);
}

///////////////////////////////////////////////////////////////////
//
// 以下是DA0832相关函数。
//
///////////////////////////////////////////////////////////////////

void CUsbhostDlg::OnPhackleButton() 
{
	// TODO: Add your control notification handler code here
	if (BigSmall)
	{
		for(int i=0;i<256;i++)
		{
			m_PointList[i].y = (float)i;
            m_PointList[i+256].y = (float)i;
            m_PointList[i+512].y = (float)i;
            m_PointList[i+768].y = (float)i;
		}
		BigSmall=false;
	}
	else
	{
		for(int i=0;i<128;i++)
		{
			m_PointList[i].y = (float)i;
            m_PointList[i+128].y = (float)i;
            m_PointList[i+256].y = (float)i;
            m_PointList[i+384].y = (float)i;
		    m_PointList[i+512].y = (float)i;
            m_PointList[i+640].y = (float)i;
            m_PointList[i+768].y = (float)i;
			m_PointList[i+896].y = (float)i;
		}
		BigSmall=true;
	}
	index=1;	
	CRect r;
	r.SetRect(m_InnerLWScreen , m_InnerUHScreen, m_InnerRWScreen , m_InnerDHScreen);
	InvalidateRect(r,TRUE); 
}

void CUsbhostDlg::OnNhackleButton() 
{
	// TODO: Add your control notification handler code here
	if (BigSmall)
	{
		for(int i=0;i<256;i++)
		{		
			m_PointList[i].y = (float)(255-i);
            m_PointList[i+256].y = (float)(255-i);
            m_PointList[i+512].y = (float)(255-i);
            m_PointList[i+768].y = (float)(255-i);
		}
		BigSmall=false;	
	}
	else
	{
		for(int i=0;i<128;i++)
		{
			m_PointList[i].y = (float)(128-i);
            m_PointList[i+128].y = (float)(128-i);
            m_PointList[i+256].y = (float)(128-i);
            m_PointList[i+384].y = (float)(128-i);
		    m_PointList[i+512].y = (float)(128-i);
            m_PointList[i+640].y = (float)(128-i);
            m_PointList[i+768].y = (float)(128-i);
			m_PointList[i+896].y = (float)(128-i);
		}
		BigSmall=true;
	}
	index=2;	
	CRect r;
	r.SetRect(m_InnerLWScreen , m_InnerUHScreen, m_InnerRWScreen , m_InnerDHScreen);
	InvalidateRect(r,TRUE); 
}

void CUsbhostDlg::OnTriangleButton() 
{
	// TODO: Add your control notification handler code here
	if (BigSmall)
	{
		for(int i=0;i<256;i++)
		{
			m_PointList[i].y = (float)i;
            m_PointList[i+256].y = (float)(255-i);
            m_PointList[i+512].y = (float)i;
            m_PointList[i+768].y = (float)(255-i);
		}
		BigSmall=false;
	}
	else
	{
		for(int i=0;i<128;i++)
		{
			m_PointList[i].y = (float)i;
            m_PointList[i+128].y = (float)(128-i);
            m_PointList[i+256].y = (float)i;
            m_PointList[i+384].y = (float)(128-i);
			m_PointList[i+512].y = (float)i;
            m_PointList[i+640].y = (float)(128-i);
            m_PointList[i+768].y = (float)i;
			m_PointList[i+896].y = (float)(128-i);
		}
		BigSmall=true;
	}
	index=3;
	CRect r;
	r.SetRect(m_InnerLWScreen , m_InnerUHScreen, m_InnerRWScreen , m_InnerDHScreen);
	InvalidateRect(r,TRUE);  
}

void CUsbhostDlg::OnSquareButton() 
{
	// TODO: Add your control notification handler code here
	if (BigSmall)
	{
		for(int i=0;i<256;i++)
		{		
			m_PointList[i].y = 255;
            m_PointList[i+256].y = 0;
            m_PointList[i+512].y = 255;
            m_PointList[i+768].y = 0;
		}
		BigSmall=false;
	}
	else
	{
		for(int i=0;i<128;i++)
		{		
			m_PointList[i].y = 255;
            m_PointList[i+128].y = 0;
            m_PointList[i+256].y = 255;
            m_PointList[i+384].y = 0;
			m_PointList[i+512].y = 255;
            m_PointList[i+640].y = 0;
            m_PointList[i+768].y = 255;
            m_PointList[i+896].y = 0;
		}
		BigSmall=true;
	}
	
	index=4;	
	CRect r;
	r.SetRect(m_InnerLWScreen , m_InnerUHScreen, m_InnerRWScreen , m_InnerDHScreen);
	InvalidateRect(r,TRUE);  
}

void CUsbhostDlg::OnSinButton() 
{
	// TODO: Add your control notification handler code here
	if (BigSmall)
	{
		for(int i=0;i<1024;i++)
		{
			m_PointList[i].y = 127+128*(float)sin(2*PI*i/1024);
		}
		BigSmall=false;
	}
	else
	{
		for(int i=0;i<1024;i++)
		{
			m_PointList[i].y = 127+128*(float)sin(2*PI*i/512);			
		}
		BigSmall=true;
	}

	index=5;
	CRect r;
	r.SetRect(m_InnerLWScreen , m_InnerUHScreen, m_InnerRWScreen , m_InnerDHScreen);
	InvalidateRect(r,TRUE);  
}

void CUsbhostDlg::OnRandomButton() 
{
	// TODO: Add your control notification handler code here
    int i=0;
	float temp;
	srand((unsigned)time(NULL));
	if (BigSmall)
	{
		while (i<1024)
		{	
			temp=(float)(rand()/100.0);
		    if(temp<=255)
			{
				m_PointList[i].y = temp;
			    i++;
			}
            BigSmall=false;
		}
	}
	else
	{
		while (i<1024)
		{	
			temp=(float)(rand()/100.0);
		    if(temp<=128)
			{
				m_PointList[i].y = temp;
			    i++;
			}
            BigSmall=true;
		}
	}
	index=6;
	CRect r;
	r.SetRect(m_InnerLWScreen , m_InnerUHScreen, m_InnerRWScreen , m_InnerDHScreen);
	InvalidateRect(r,TRUE); 
}

///////////////////////////////////////////////////////////////////
//
// 以下是USB相关函数。
//
///////////////////////////////////////////////////////////////////

void CUsbhostDlg::OnSendButton() 
{
	// TODO: Add your control notification handler code here
	HANDLE  hDevice = NULL;
	BOOLEAN bResult = FALSE;
	ULONG   nBytes;
	unsigned char outValue;   
	BULK_TRANSFER_CONTROL bulkControl;    

    if(g_KeepGoing)
	{
		MessageBox("请首先结束当前线程!", "错误", MB_ICONERROR | MB_OK);
		return;
	}

	for(int i=0;i<1024;i++)
	{
		PacketoutBuffer[i]=255-(unsigned char)m_PointList[i].y;
	}

	if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) 
	{    	 
		MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
		return;
	}

	outValue=0x55;
	bulkControl.pipeNum = 2; 
	bResult = DeviceIoControl (hDevice,
                              IOCTL_EZUSB_BULK_WRITE,
                              &bulkControl,
                              sizeof(BULK_TRANSFER_CONTROL),
                              &outValue,
                              1,
                              &nBytes,
                              NULL);
        if (bResult != TRUE) 
		{
             AfxMessageBox("USB块OUT传输失败!");
          	 CloseHandle(hDevice);
             return;
		}  

    g_KeepGoing = true;
    if(_beginthread(SendThreadFunction, 0, hDevice) < 0)
    {
		AfxMessageBox("启动发送数据线程失败!");
    }
}

void __cdecl SendThreadFunction(HANDLE hDevice)
{
	BOOLEAN bResult = FALSE;
	ULONG   nBytes;
	BULK_TRANSFER_CONTROL bulkControl;    

	while (g_KeepGoing) 
	{
		  bulkControl.pipeNum = 4; 
          bResult = DeviceIoControl (hDevice,
                              IOCTL_EZUSB_BULK_WRITE,
                              &bulkControl,
                              sizeof(BULK_TRANSFER_CONTROL),
                              PacketoutBuffer,
                              1024,
                              &nBytes,
                              NULL);  
          if (bResult != TRUE) 
		  {
             AfxMessageBox("USB块OUT传输失败!");
             goto exit1;
		  }
	}
exit1:
	CloseHandle(hDevice);
	g_KeepGoing=false;
    _endthread();
}

void CUsbhostDlg::OnEndButton() 
{
	// TODO: Add your control notification handler code here
	HANDLE  hDevice = NULL;
	BOOLEAN bResult = FALSE;
	ULONG   nBytes;
	unsigned char outValue;   
	BULK_TRANSFER_CONTROL bulkControl;    

    g_KeepGoing = false;

	if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) 
	{    	 
		MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
		return;
	}

	outValue=0xAA;
	bulkControl.pipeNum = 3;  
	bResult = DeviceIoControl (hDevice,
                              IOCTL_EZUSB_BULK_WRITE,
                              &bulkControl,
                              sizeof(BULK_TRANSFER_CONTROL),
                              &outValue,
                              1,
                              &nBytes,
                              NULL);
        if (bResult != TRUE) 
		{
             AfxMessageBox("USB块OUT传输失败!");
             CloseHandle(hDevice);
			 return;
		}  
  	CloseHandle(hDevice);    
}

void CUsbhostDlg::OnClearButton() 
{
	// TODO: Add your control notification handler code here
	int count=m_UsbList.GetCount();
	
	for (int i=0;i < count;i++)
	{
		m_UsbList.DeleteString( 0 );
	}
}

void CUsbhostDlg::OnExitButton() 
{
	// TODO: Add your control notification handler code here
    if(g_KeepGoing)
	{
		MessageBox("请首先结束当前线程!", "错误", MB_ICONERROR | MB_OK);
		return;
	}	
	OnOK();
}

⌨️ 快捷键说明

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