阅读:1079回复:4
deviceiocontrol的问题!!
#include <windows.h>
//include <afxwin.h> //#include <afxdlgs.h> #include <stdio.h> #include <stdlib.h> //#include <process.h> //#include \"DEVIOCTL.H\" //#define USING_MFC #include \"ezusbsys.h\" #include \"winioctl.h\"\" #define IOCTL_EZUSB_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, \\ 0x800+19,\\ METHOD_IN_DIRECT, \\ FILE_ANY_ACCESS) int main() { char buffer[200000]; BOOL bResult; int length=2000000; int size=2000; int count=1000; ULONG numwritten; /* if (!buffer) { //AfxMessageBox(\"Unable to allocate transfer buffer\"); } // Get the text in the driver name edit box // GetDlgItemText (hDlg, IDC_DRIVER_NAME, pcDriverName, MAX_DRIVER_NAME); */ HANDLE hDevice; // handle to the drive to be examined //BOOL bResult; // results flag DWORD junk; // discard results int numread; hDevice = CreateFile(\"\\\\\\\\.\\\\Ezusb-0\", // drive to open GENERIC_READ | GENERIC_WRITE, // don\'t need any access to the drive FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode NULL, // default security attributes OPEN_EXISTING, // disposition 0, // file attributes NULL); // don\'t copy any file\'s attributes if (hDevice == INVALID_HANDLE_VALUE) // we can\'t open the drive { printf(\"open failed\"); return (FALSE); } FILE *fp=fopen (\"G:\\\\read.txt\", \"rb\"); if(fp!=NULL) { numread= fread(buffer, sizeof(int), 80, fp); } printf(\"hdevice=%d\", (char*)hDevice); printf(\"numread=%d\", numread); DWORD ioctl_val = IOCTL_EZUSB_BULK_WRITE; bResult = DeviceIoControl(hDevice, // device we are querying ioctl_val , // operation to perform NULL,//no need to build a construct, it is build in sys.c 0, buffer, length, // output buffer &junk, // discard count of bytes returned NULL); // synchronous I/O if (!bResult) // IOCTL failed { printf(\"chen open fail\"); return (FALSE); } WriteFile(hDevice, buffer, 2000, &numwritten, NULL); printf(\"ok\"); printf(\"chen=%d\",count); // ReadFile(); CloseHandle(hDevice); // we\'re done with the handle return (bResult); } 为什么我的deviceiocontrol不能成功的打开写呢? |
|
沙发#
发布于:2003-04-18 10:16
你首先要确保你的createfile成功
|
|
|
板凳#
发布于:2003-04-18 13:30
我刚拿到68013的开发板,现在对usb开发甚是不通,今天拿bulkloop的程序试了试,但是从winmain移植到vc却始终有问题,createfile没有问题,随后执行deviceiocontrol(IOCTL_Ezusb_GET_PIPE_INFO)可以得到pipeinfo,但是对bulkread和bulkwrite的时候一执行deviceiocontrol马上蓝屏死机,请教大侠问题可能出在什么地方?(原程序用winmain来写的,对bulkread和bulkwrite是在线程里做的,我觉得跟楼上这位的代码没有什么不同之处,但也是在deviceincontrol里出错)
|
|
地板#
发布于:2003-04-18 15:13
建议你检查一下你的驱动程序,看看是不是有什么冲突
|
|
地下室#
发布于:2003-04-18 17:04
看了楼上的程序,把createfile的参数由FILE_SHARE_WRITE改成FILE_SHARE_READ | FILE_SHARE_WRITE后不死机,但还是打不开设备,而cy自带的bulkloop程序里用winmain写的时候用FILE_SHARE_WRITE没有出现这个问题,而且还打得开设备,为什么?c文件和cpp文件都在vc下编译,二者在deviceiocontrol的使用上应该不会有什么区别的是吧?和驱动似乎无关吧?
|
|