?? usbhostdlg.cpp
字號:
}
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 + -