rubylili
驱动牛犊
驱动牛犊
  • 注册日期2005-03-16
  • 最后登录2005-05-28
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:869回复:0

求教!

楼主#
更多 发布于:2005-05-22 18:48
我做的是USB接口数据采集器,是利用周立功的D12开发板来开发的,我分别做了发送数据的函数和接收数据的函数,下面是这两个函数的实现,而对应的消息函数OnReceive()和OnSend()和周立功的代码写的相似,但发送函数应该没有问题,接收就收不到,请高手们帮我看一下,先谢啦
UINT Receive(void*pParam)
{
    char temp[80];
    ULONG nBytes ;
BOOLEAN bResult=FALSE;
struct CThreadParam * threadParam;
CD12TestDlg* testDlg;
HANDLE hFile, hDevice;
// unsigned char *iobuf;
IO_BLOCK ioBlock;
IO_REQUEST ioRequest;

threadParam=(struct CThreadParam *)pParam;
threadParam->bInThread = FALSE;
testDlg = threadParam->testDlg;
threadParam->bUpdate = FALSE;

hFile = open_file(threadParam->pipe_name);
if(hFile == INVALID_HANDLE_VALUE)
{

strcpy(temp, \"驱动程序打开失败! 不能从 \");
strcat(temp, threadParam->pipe_name);
strcat(temp, \" 中读出数据。\");
testDlg->MessageBox((LPCSTR)temp, \"测试错误\");
return 0;

}
hDevice = open_dev();
threadParam->uiLength=testDlg->m_ed1.GetLength();
threadParam->pcIoBuffer = (unsigned char *)malloc (threadParam->uiLength + 16);

           ioRequest.uAddressL = 0;
ioRequest.bAddressH = 0;
ioRequest.uSize = threadParam->uiLength;
ioRequest.bCommand = 0x81; //start, read

ioBlock.uOffset = 0;
ioBlock.uLength = sizeof(IO_REQUEST);
ioBlock.pbyData = (PUCHAR)&ioRequest;
ioBlock.uIndex = SETUP_DMA_REQUEST;
           
bResult = DeviceIoControl(hDevice,IOCTL_READ_REGISTERS,(PVOID)&ioBlock,sizeof(IO_BLOCK),threadParam->pcIoBuffer,threadParam->uiLength,&nBytes,NULL);
//bResult = DeviceIoControl(hDevice,IOCTL_READ_REGISTERS,(PVOID)&ioBlock,sizeof(IO_BLOCK),NULL,0,&nBytes,NULL);
//bResult = ReadFile(hFile,threadParam->pcIoBuffer,threadParam->uiLength,&nBytes,NULL);

for(int i=0;i<testDlg->m_ed1.GetLength();i++)
{
testDlg->m_ed2+=threadParam->pcIoBuffer;
 //  threadParam->testDlg->m_ed1.Empty();


}

    return 0;
}






UINT Send(void*pParam)
{
// TODO: Add your control notification handler code here
  
    char temp[80];
    ULONG nBytes ;
BOOLEAN bResult=FALSE;
struct CThreadParam * threadParam;
CD12TestDlg* testDlg;
HANDLE hFile, hDevice;
// unsigned char *iobuf;
IO_BLOCK ioBlock;
IO_REQUEST ioRequest;

threadParam=(struct CThreadParam *)pParam;
threadParam->bInThread = FALSE;
testDlg = threadParam->testDlg;
threadParam->bUpdate = FALSE;

hFile = open_file(threadParam->pipe_name);
if(hFile == INVALID_HANDLE_VALUE)
{

strcpy(temp, \"驱动程序打开失败! 不能从 \");
strcat(temp, threadParam->pipe_name);
strcat(temp, \" 中读出数据。\");
testDlg->MessageBox((LPCSTR)temp, \"测试错误\");
return 0;

}


    hDevice = open_dev();
threadParam->pcIoBuffer = (unsigned char *)malloc (threadParam->uiLength + 16);
    threadParam->uiLength=testDlg->m_ed1.GetLength();
for(int i=0;i<threadParam->testDlg->m_ed1.GetLength();i++)
{
threadParam->pcIoBuffer=threadParam->testDlg->m_ed1.GetAt(i);

}

           ioRequest.uAddressL = 0;
ioRequest.bAddressH = 0;
ioRequest.uSize = threadParam->uiLength;
ioRequest.bCommand = 0x80; //start, write

ioBlock.uOffset = 0;
ioBlock.uLength = sizeof(IO_REQUEST);
ioBlock.pbyData = (PUCHAR)&ioRequest;
ioBlock.uIndex = SETUP_DMA_REQUEST;
bResult = DeviceIoControl(hDevice,IOCTL_WRITE_REGISTERS,(PVOID)&ioBlock,sizeof(IO_BLOCK),threadParam->pcIoBuffer,threadParam->testDlg->m_ed1.GetLength(),&nBytes, NULL);
//bResult = WriteFile(hFile,threadParam->pcIoBuffer,threadParam->uiLength,&nBytes,NULL);            


return 0;

}
游客

返回顶部