📄 mainfrm.cpp
字号:
myRequest.direction = 1;
myRequest.index = 0;
myRequest.value = 0;
myRequest.request = VR_USB_VERION;
// vendor specific request type (2)
myRequest.requestType=2;
// recepient is device (0)
myRequest.recepient=0;
/*传回一个数据长度*/
venderlong = 1;
Sx2SendVendorReq(&myRequest,
&buffer1[0],
venderlong,
&recnBytes);
if(buffer1[0] ==0x55)
{
theApp.Out("CY7C68001 is working under USB 2.0!\n");
}
else
{
if(buffer1[0] ==0x54)
{
theApp.Out("CY7C68001 is working under USB 1.1!\n");
}
else
{
theApp.Out("CY7C68001 is working error!\n");
}
}
}
void CMainFrame::OnBulkRead()
{
// TODO: Add your command handler code here
// BULK数据的读操作
int i = 0;
char *buffer;
char recievedat[1024] = {0};
ULONG length;
BULK_TRANSFER_CONTROL bulkControl;
int recnBytes = 0;
/*命令请求定义*/
char buffer1[64];
VENDOR_OR_CLASS_REQUEST_CONTROL myRequest;
ULONG venderlong;
/*发送命令,使DSP先定入固定的数据*/
myRequest.direction = 0;
myRequest.index = 0;
myRequest.value = 2;
myRequest.request =0xb6;
// vendor specific request type (2)
myRequest.requestType=2;
// recepient is device (0)
myRequest.recepient=0;
venderlong = 0;
Sx2SendVendorReq(&myRequest,
&buffer1[0],
venderlong,
&recnBytes);
/*延时250ms*/
// SleepEx(250,0);
/*按默认的配置,读回Endpoint6的数据并显示*/
bulkControl.pipeNum = 2;
buffer = &recievedat[0];
length = theApp.m_USBbufferlong;
Sx2BulkdataTrans( &bulkControl,
buffer,
length,
&recnBytes);
/*显示读回数据*/
theApp.Out("The data read from the endpiont 6:\n");
theApp.Out("The data is oven data.\n");
for(i = 0; i<64 ;)
{
int j = 0;
bool drawover = FALSE;
for(j = 0 ;j<9;j++)
{
if(i+j ==63)
{
theApp.Out("00%04d\n",(buffer[i+j]&0xff));
drawover = TRUE;
break;
}
else
{
theApp.Out("00%04d ",(buffer[i+j]&0xff));
}
}
if(drawover)
{
break;
}
i = i +9;
theApp.Out("00%04d\n",(buffer[i]&0xff));
i= i +1;
}
myRequest.direction = 0;
myRequest.index = 0;
myRequest.value = 3;
myRequest.request =0xb6;
// vendor specific request type (2)
myRequest.requestType=2;
// recepient is device (0)
myRequest.recepient=0;
venderlong = 0;
Sx2SendVendorReq(&myRequest,
&buffer1[0],
venderlong,
&recnBytes);
/*按默认的配置,读回Endpoint6的数据并显示*/
bulkControl.pipeNum = 3;
buffer = &recievedat[0];
length = theApp.m_USBbufferlong;
Sx2BulkdataTrans( &bulkControl,
buffer,
length,
&recnBytes);
/*显示读回数据*/
theApp.Out("The data read from the endpiont 8:\n");
theApp.Out("The data is odd data.\n");
for(i = 0; i<64 ;)
{
int j = 0;
bool drawover = FALSE;
for(j = 0 ;j<9;j++)
{
if(i+j == 63)
{
theApp.Out("00%04d\n",(buffer[i+j]&0xff));
drawover = TRUE;
break;
}
else
{
theApp.Out("00%04d ",(buffer[i+j]&0xff));
}
}
if(drawover)
{
break;
}
i = i +9;
theApp.Out("00%04d\n",(buffer[i]&0xff));
i= i +1;
}
}
void CMainFrame::OnBulkWrite()
{
// TODO: Add your command handler code here
//BULK数据的写操作
int i = 0;
char *buffer;
char senddat[512] = {0};
ULONG length;
BULK_TRANSFER_CONTROL bulkControl;
int recnBytes = 0;
/*写Endpoint2*/
bulkControl.pipeNum = 0;
for(i = 0;i<512;i++)
{
senddat[i] = i;
}
buffer = &senddat[0];
length =theApp.m_USBbufferlong;
Sx2BulkdataTrans( &bulkControl,
buffer,
length,
&recnBytes);
/*读回Endpoint6,并显示*/
bulkControl.pipeNum = 2;
for(i = 0;i<512;i++)
{
senddat[i] = 0;
}
buffer = &senddat[0];
length = theApp.m_USBbufferlong;
Sx2BulkdataTrans( &bulkControl,
buffer,
length,
&recnBytes);
/*显示读回数据*/
theApp.Out("The data send to the endpiont2 is:\n0,1,2,3.......to 0x3f.\n");
theApp.Out("The data read from the endpiont 6:\n");
for(i = 0; i<64 ;)
{
int j = 0;
bool drawover = FALSE;
for(j = 0 ;j<9;j++)
{
if(i+j == 63)
{
theApp.Out("0x%04x\n",(buffer[i+j]&0xff));
drawover = TRUE;
break;
}
else
{
theApp.Out("0x%04x ",(buffer[i+j]&0xff));
}
}
if(drawover)
{
break;
}
i = i +9;
theApp.Out("0x%04x\n",(buffer[i]&0xff));
i= i +1;
}
/*写Endpoint4*/
bulkControl.pipeNum = 1;
for(i = 0;i<theApp.m_USBbufferlong;i++)
{
senddat[i] = 0x3F-i;
}
buffer = &senddat[0];
length =theApp.m_USBbufferlong;
Sx2BulkdataTrans( &bulkControl,
buffer,
length,
&recnBytes);
/*读回Endpoint6,并显示*/
bulkControl.pipeNum = 3;
for(i = 0;i<512;i++)
{
senddat[i] = 0;
}
buffer = &senddat[0];
length = theApp.m_USBbufferlong;
Sx2BulkdataTrans( &bulkControl,
buffer,
length,
&recnBytes);
/*显示读回数据*/
theApp.Out("The data send to the endpiont4 is:\n0x3f,0x3e,0x3d.......to 0.\n");
theApp.Out("The data read from the endpiont 8:\n");
for(i = 0; i<64 ;)
{
int j = 0;
bool drawover = FALSE;
for(j = 0 ;j<9;j++)
{
if(i+j == 63)
{
theApp.Out("0x%04x\n",(buffer[i+j]&0xff));
drawover = TRUE;
break;
}
else
{
theApp.Out("0x%04x ",(buffer[i+j]&0xff));
}
}
if(drawover)
{
break;
}
i = i +9;
theApp.Out("0x%04x\n",(buffer[i]&0xff));
i= i +1;
}
}
void CMainFrame::OnTestVendor()
{
// TODO: Add your command handler code here
// 测试命令输入
int i = 0;
int recnBytes;
char buffer[64];
VENDOR_OR_CLASS_REQUEST_CONTROL myRequest;
CUsbvreqDialog vendordlg;
if(vendordlg.DoModal()== IDCANCEL)
{
return;
}
theApp.Out("USB vendor requset!");
myRequest.direction = vendordlg.m_VendorDir;
myRequest.index = vendordlg.m_VendorIndex;
myRequest.value = vendordlg.m_VendorValue;
myRequest.request = vendordlg.m_VendorReq;
// vendor specific request type (2)
myRequest.requestType=2;
// recepient is device (0)
myRequest.recepient=0;
for(i = 0 ;i <vendordlg.m_VendorLength; i++)
{
buffer[i] = vendordlg.m_Endpoint0data[i];
}
Sx2SendVendorReq(&myRequest,
&buffer[0],
vendordlg.m_VendorLength,
&recnBytes);
if(recnBytes !=0)
{
for(i = 0;i<recnBytes;i++)
{
theApp.Out("The data we recieved from the Endpoint0 is 0x%4x\n",buffer[i]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -