[python-win32] USB access using win32file.deviceIOcontrol

Sebastian Friebe basti at benkers-rock.de
Wed Dec 12 21:41:15 CET 2007


Tim Roberts wrote:
TR> That's fundamentally correct.  How are you creating the
TR> SCSI_PASS_THROUGH structure in "byte_list"?  Are you sure it is 42
TR> bytes?  Are you setting all the fields correctly?  How are you setting
TR> the DataBuffer pointer?  Have you set the Length field correctly?

That's exactly my problem.
I know there are some pointers in the C++ structure pointing to the
data inside the structure. But I don't have an idea at all, how to
port it to Python.

Could you give me an example of a very basic SCSI command, like the
TEST_UNIT_READY ?

Tim Roberts wrote:
TR> I would have guessed it would be easier to use the struct module to
TR> build the buffer, rather than array.

I didn't know if it would work, so I
started with a very strait forward approach.
I extracted the content of the SCSI_PASS_THROUGH in my C++ example
into a array of bytes.
I included the byte stream I found into my byte_list.
e.g.
    SCSI_TEST_UNIT_READY=[0x2C,0x00,0x00,0x00,0x01,0x00,0x06,0x18,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
                          0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
                          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
                          0x00,0x00,0x00,0x00]

    byte_list = SCSI_TEST_UNIT_READY

If the basic functionality is proven, I planned to go for a more
object oriented approach like:

 class SCSI_PASS_THROUGH_DIRECT(object):
    def __init__(self, cdbLength = 16, transfer_length, transfer_direction):
        self.Length             =   0                      #    USHORT Length;
        self.ScsiStatus         =   0                      #    UCHAR ScsiStatus;
        self.PathId             =   0                      #    UCHAR PathId;
        self.TargetId           =   1                      #    UCHAR TargetId;
        self.Lun                =   0                      #    UCHAR Lun;
        self.CdbLength          =   cdbLength              #    UCHAR CdbLength;
        self.SenseInfoLength    =   24                     #    UCHAR SenseInfoLength;
        self.DataIn             =   transfer_direction     #    UCHAR DataIn;
        self.DataTransferLength =   transfer_length        #    ULONG DataTransferLength;
        self.TimeOutValue       =   2                      #    ULONG TimeOutValue;
        self.DataBuffer         =   0                      #    PVOID DataBuffer;
        self.SenseInfoOffset    =   0                      #    ULONG SenseInfoOffset;
        self.Cdb                =   []                     #    UCHAR Cdb[16];

But again, I don't know how to handle the buffer pointers inside the
structure.



More information about the python-win32 mailing list