📄 usbhostdlg.cpp
字号:
XVPtoXLP(m_PointList[0].x,&x1);
YVPtoYLP(m_PointList[0].y,&y1);
pDC->MoveTo (x1,y1);
for(int i=1;i<1024;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->SetBkMode (OPAQUE);
CFont fontText;
fontText.CreateFont(14,0,0,0,50,FALSE,0,0,0,0,0,0,0,"Arial");
CFont* pOldFont=(CFont*)pDC->SelectObject(&fontText);
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;i<m_YLineStart.GetSize();i++)
{
sprintf(str,"%d",(-64)+i*64);
pDC->TextOut(m_InnerLWScreen-25,m_YLineStart[i]-10,str);
}
for(i=0;i<m_XLineStart.GetSize();i++)
{
sprintf(str,"%d",i*128);
pDC->TextOut(m_XLineStart[i]-5,m_InnerDHScreen+5,str);
}
fontText.CreateFont(20,0,0,0,50,FALSE,0,0,0,0,0,0,0,"Arial");
pOldFont=(CFont*)pDC->SelectObject(&fontText);
pDC->TextOut(m_InnerLWScreen+150,m_InnerUHScreen-27,"波形显示");
pDC->SelectObject(pOldFont);
}
///////////////////////////////////////////////////////////////////
//
// 以下是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::OnInterfaceButton()
{
// TODO: Add your control notification handler code here
USB_CONFIGURATION_DESCRIPTOR output;
unsigned char output2[200];
USB_INTERFACE_DESCRIPTOR *output0;
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)
{
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output2,
output.wTotalLength,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox("读取接口描述符失败!", "错误", MB_ICONERROR | MB_OK);
else
{
m_UsbList.AddString("USB Interface Descriptor");
output0=(USB_INTERFACE_DESCRIPTOR *)&output2[9];
str.Format(_T("bLength:0x%x"),output0->bLength);
m_UsbList.AddString(str);
str.Format(_T("bDescriptorType:0x%x"),output0->bDescriptorType);
m_UsbList.AddString(str);
str.Format(_T("bInterfaceNumber:0x%x"),output0->bInterfaceNumber);
m_UsbList.AddString(str);
str.Format(_T("bAlternateSetting:0x%x"),output0->bAlternateSetting);
m_UsbList.AddString(str);
str.Format(_T("bNumEndpoints:0x%x"),output0->bNumEndpoints);
m_UsbList.AddString(str);
str.Format(_T("bInterfaceClass:0x%x"),output0->bInterfaceClass);
m_UsbList.AddString(str);
str.Format(_T("bInterfaceSubClass:0x%x"),output0->bInterfaceSubClass);
m_UsbList.AddString(str);
str.Format(_T("bInterfaceProtocol:0x%x"),output0->bInterfaceProtocol);
m_UsbList.AddString(str);
str.Format(_T("iInterface:0x%x"),output0->iInterface);
m_UsbList.AddString(str);
}
}
else
MessageBox("读取接口描述符失败!", "错误", MB_ICONERROR | MB_OK);
CloseHandle (hDevice);
}
void CUsbhostDlg::OnEndpointButton()
{
// TODO: Add your control notification handler code here
USB_CONFIGURATION_DESCRIPTOR output;
unsigned char output2[200];
USB_ENDPOINT_DESCRIPTOR *output0;
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)
{
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR,
NULL,
0,
&output2,
output.wTotalLength,
&nBytes,
NULL);
if (bResult!=TRUE)
MessageBox("读取端点描述符失败!", "错误", MB_ICONERROR | MB_OK);
else
{
m_UsbList.AddString("USB Endpoint Descriptor");
for (int i=0;i<6;i++)
{
output0=(USB_ENDPOINT_DESCRIPTOR *)&output2[18+i*7];
str.Format(_T("Endpoint:%d"),i+1);
m_UsbList.AddString(str);
str.Format(_T("bLength:0x%x"),output0->bLength);
m_UsbList.AddString(str);
str.Format(_T("bDescriptorType:0x%x"),output0->bDescriptorType);
m_UsbList.AddString(str);
str.Format(_T("bEndpointAddress:0x%x"),output0->bEndpointAddress);
m_UsbList.AddString(str);
str.Format(_T("bmAttributes:0x%x"),output0->bmAttributes);
m_UsbList.AddString(str);
str.Format(_T("wMaxPacketSize:0x%x"),output0->wMaxPacketSize);
m_UsbList.AddString(str);
str.Format(_T("bInterval:0x%x"),output0->bInterval);
m_UsbList.AddString(str);
m_UsbList.AddString("");
}
}
}
else
MessageBox("读取端点描述符失败!", "错误", MB_ICONERROR | MB_OK);
CloseHandle (hDevice);
}
void CUsbhostDlg::OnStringButton()
{
// TODO: Add your control notification handler code here
HANDLE hDevice=NULL;
BOOL bResult = FALSE;
ULONG nBytes;
char output0[50];
GET_STRING_DESCRIPTOR_IN input;
USB_STRING_DESCRIPTOR output;
char tempbuff[2][256];
CString str;
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
hDevice = NULL;
return;
}
input.Index=1;
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 1");
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]);
m_UsbList.AddString("");
}
}
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -