📄 usbhostlogicdlg.cpp
字号:
int i;
for(i=0;i<m_xn+1;i++)
{
pDC->MoveTo ((int)m_xLineStart[i],m_InnerUHScreen);
pDC->LineTo ((int)m_xLineStart[i],m_InnerDHScreen);
}
for(i=0;i<m_yn+1;i++)
{
pDC->MoveTo (m_InnerLWScreen,(int)m_yLineStart[i]);
pDC->LineTo (m_InnerRWScreen,(int)m_yLineStart[i]);
}
pDC->SelectObject (pOldPen);
}
void CUSBHOSTLOGICDlg::DrawLab(CDC *pDC)
{
pDC->SetBkMode (OPAQUE);
CFont* pOldFont=(CFont*)pDC->SelectObject(&LabelFont);
pDC->TextOut(m_InnerLWScreen-30,m_InnerUHScreen-20,"通道号");
pDC->TextOut(m_InnerLWScreen/2-15 + m_InnerRWScreen/2,m_InnerDHScreen+ 20, "点数值");
char str[10];
for(int i=0;i<m_yn;i++)
{
sprintf(str,"CH%d",7-i);
pDC->TextOut(m_InnerLWScreen-25,(int)m_yLineStart[i]-30,str);
}
for(i=0;i<m_xn+1;i++)
{
sprintf(str,"%d",i*128);
pDC->TextOut((int)m_xLineStart[i]-5,m_InnerDHScreen+5,str);
}
pDC->SelectObject(TitleFont);
pDC->TextOut(m_InnerLWScreen+240,m_InnerUHScreen-27,"波形显示");
pDC->SelectObject(pOldFont);
}
void CUSBHOSTLOGICDlg::DrawCurve (CDC *pDC)
{
int x1,y1;
CPen* npOldPen=pDC->SelectObject (&CurvePen);
pDC->SetROP2(R2_COPYPEN);
int StepY=(m_InnerDHScreen-m_InnerUHScreen)/8;
for(int j=0;j<8;j++)
{
x1=(int)(((m_PointList[j][0].x-m_xStart)/m_XOriginScale+(float)0.5)+m_InnerLWScreen);
y1=(int)(m_InnerDHScreen-StepY/2-StepY*(7-j)-((m_PointList[j][0].y-m_yStart)/m_YOriginScale+(float)0.5));
pDC->MoveTo (x1,y1);
for(int i=1;i<1024;i++)
{
x1=(int)(((m_PointList[j][i].x-m_xStart)/m_XOriginScale+(float)0.5)+m_InnerLWScreen);
y1=(int)(m_InnerDHScreen-StepY/2-StepY*(7-j)-((m_PointList[j][i].y-m_yStart)/m_YOriginScale+(float)0.5));
pDC->LineTo (x1,y1);
}
}
pDC->SelectObject (npOldPen);
}
void CUSBHOSTLOGICDlg::OnExitButton()
{
// TODO: Add your control notification handler code here
OnOK();
}
///////////////////////////////////////////////////////////////////
//
// 以下是CY7C68013相关函数。
//
///////////////////////////////////////////////////////////////////
BOOLEAN CUSBHOSTLOGICDlg::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 CUSBHOSTLOGICDlg::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);
}
void CUSBHOSTLOGICDlg::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 CUSBHOSTLOGICDlg::OnClearlistButton()
{
// 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 CUSBHOSTLOGICDlg::OnStartButton()
{
// TODO: Add your control notification handler code here
HANDLE hDevice = NULL;
VENDOR_REQUEST_IN myRequest;
BULK_TRANSFER_CONTROL bulkControl;
BOOLEAN bResult = FALSE;
unsigned char InBuffer[4096];
ULONG nBytes;
char buffer[10];
if (g_KeepGoing)
{
MessageBox("请首先结束当前线程!", "错误", MB_ICONERROR | MB_OK);
return;
}
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
return;
}
myRequest.bRequest = 0xB5;
myRequest.wValue = 0x0000;
myRequest.wIndex = 0x0000;
myRequest.wLength = 0x0001;
myRequest.bData = 0x00;
myRequest.direction = 0x01;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_VENDOR_REQUEST,
&myRequest,
sizeof(VENDOR_REQUEST_IN),
buffer,
1,
&nBytes,
NULL);
if (bResult != TRUE)
{
AfxMessageBox("启动系统硬件失败!");
CloseHandle(hDevice);
g_KeepGoing=false;
return;
}
nBytes = 0;
bulkControl.pipeNum = 0 ;
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_READ,
&bulkControl,
sizeof(BULK_TRANSFER_CONTROL),
InBuffer,
4096,
&nBytes,
NULL);
if (bResult != TRUE)
{
AfxMessageBox("接收数据失败!");
goto exit;
}
if (nBytes==4096)
{
for(int j=0;j<8;j++)
{
for(int i=0;i<4096;i++)
ADDataBuffer[j][i]=((InBuffer[i]&((int)pow(2,j)))>>j);
}
PostMessage(WM_DRAWPICTURE,0,0);
}
exit:
myRequest.bRequest = 0xB6;
myRequest.wValue = 0x0000;
myRequest.wIndex = 0x0000;
myRequest.wLength = 0x0001;
myRequest.bData = 0x00;
myRequest.direction = 0x01;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_VENDOR_REQUEST,
&myRequest,
sizeof(VENDOR_REQUEST_IN),
buffer,
1,
&nBytes,
NULL);
if (bResult != TRUE)
{
AfxMessageBox("结束逻辑分析失败,请重新启动设备!");
}
CloseHandle(hDevice);
g_KeepGoing=false;
}
void CUSBHOSTLOGICDlg::OnCustomdrawSliderfreq(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nPos;
float Freq;
CString str;
nPos=m_SliderFreq.GetPos();
if(nPos<7)
{
Freq=SamFreq[nPos];
str.Format("%5.2f",Freq);
}
else
{
str="Exterior";
}
m_Edit_Freq.SetWindowText(str);
*pResult = 0;
}
void CUSBHOSTLOGICDlg::OnCustomdrawSlideramp(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nPos;
nPos=m_SliderAmp.GetPos();
CString str;
str.Format("%d",nPos*20);
m_Edit_Amp.SetWindowText(str);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -