Log in

View Full Version : USB and ReadFile


Nazgul
06-24-2007, 02:12 PM
Hello,
I have recently acquired a Loox N560 with Windows Mobile 5, integral USB host and installed Ratoc USB host driver and Mass storage driver,
in order to develop a program that connects' to an embedded device through USB. The device registers itself as mass storage and handles command communication through a pipe file (text file).
This settings worked well for a similar program written for PC - thepipe file was opened using CreateFile with FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH attributes, and sector aligned blocks werewritten and read using WriteFile and ReadFile, respectively.
I'm developing the program using C++/MFC.
Trying to implement to same thing in Windows Mobile 5, lead to some unfortunate results.
The CreateFile and WriteFile seems to work well; ReadFile does not fail, but returns invalid data (all zeros).
The USB driver implemented in the device maintains that while WriteFile and CreateFile does cause the OS
to send a WRITE request through the USB host and after that the data is pushed to the OUT FIFO in the device,
the ReadFile operation does not seem to cause the OS to send a READ request and thus does not receive any
viable data through the pipe from the device.
As the pipe is used to handle commands between the PDA and the device, operation as reading a parameter goes
like this - Allocation of a aligned data packet specifying the desired parameter, 'WriteFile'ing the packet through
the pipe, and 'ReadFile'ing the result. As I metioned, the WriteFile part seems always to work while the ReadFile does not.
It seems as if the OS buffers/caches the file contents the first time it is used and so does not seem to inquire the
device through the USB afterwards, despite the fact that the handle was created with the seemingly appropriate flags.
Been trying to use IOControl instead of ReadFile/WriteFile, but could not find anywhere 'diskio.h' needed for the
IOCTL_DISK_WRITE and IOCTL_DISK_READ definitions.
Does anybody has any idea what can be the problem or has encountered a similar one?
Thanks.

Nazgul
06-25-2007, 09:08 AM
As I found out that Windows CE does not support the FILE_FLAG_NO_BUFFERING flag for CreateFile, my question becomes a little different - what can I do in Windows CE in order to open a file/hard disk without caching, if possible at all?

Thanks.