[python-win32] USB access using win32file.deviceIOcontrol
Tim Roberts
timr at probo.com
Tue Dec 11 22:24:27 CET 2007
Sebastian Friebe wrote:
> I'm trying to get access to a USB mass storage device in order to send
> low-level SCSI commands, like TEST_UNIT_READY and REQUEST_SENSE.
> I'm looking for a pure Python solution using the deviceIOcontrol
> function out of the win32file package.
>
> Does anyone has experience with it?
>
> I heared about libusb_win32 and pyUSB, but I couldn't figure out if
> these are really required. I guess these packages are needed just in
> case you want to do higher level operations in an application, right?
This can't be done as you have described it.
The problem is that the SCSI-like command set is only used between the
USB mass storage driver (usbstor.sys) and the USB host controller
driver. Above usbstor.sys, the device looks like a standard mass
storage device. There are no hooks in usbstor.sys to allow you to send
commands like this, nor does usbstor.sys allow you to send USB packets
directly. Neither libusb-win32 nor pyUSB will help, because there is
already a driver handling the device. libusb installs its own generic
driver, but it can't install a driver if another one has already claimed
the device.
Theoretically, you could write an INF file to force your device to be
claimed by libusb's driver, and then use libusb commands to talk to the
device. You would then be in COMPLETE control of the device. However,
that also means it won't be recognized as a mass storage device. It
will just be a generic USB device.
It may be that the easiest course of action for you is to write a lower
filter driver to sit between usbstor.sys and USBD, and have it expose a
"control" device object. Such a thing CAN be opened and manipulated
using the win32file APIs.
Do you have any driver experience at your shop?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list