你提到的MSC也是“USB”大容量存储设备?
如果是,那么您可以使用 SCSI_PATH_THROUGH 与此 USB MSC 进行通信!
前任。向 USB MSC 发出写入命令可以通过以下代码片段实现:
BOOL LogicalWriteCmd(HANDLE fileHandle,ULONG LBA,ULONG SectorCnt,PVOID DataBuffer)
{
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb;
ULONG returned,length;
BOOL status;
ZeroMemory(&sptdwb, sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
length = SectorCnt<<SECTOR_SIZE_SHIFT_BIT;
sptdwb.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
sptdwb.sptd.PathId = 0;
sptdwb.sptd.TargetId = 0;
sptdwb.sptd.Lun = 0;
sptdwb.sptd.CdbLength = CDB10GENERIC_LENGTH;
sptdwb.sptd.DataIn = SCSI_IOCTL_DATA_OUT;
sptdwb.sptd.SenseInfoLength = SPT_SENSE_LENGTH;
sptdwb.sptd.DataTransferLength = length;
sptdwb.sptd.TimeOutValue = g_ulTimeOut;
sptdwb.sptd.DataBuffer = DataBuffer;
sptdwb.sptd.SenseInfoOffset =
offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER,ucSenseBuf);
sptdwb.sptd.Cdb[0] = SCSIOP_WRITE;
sptdwb.sptd.Cdb[2] = (UCHAR)(LBA>>24);
sptdwb.sptd.Cdb[3] = (UCHAR)(LBA>>16);
sptdwb.sptd.Cdb[4] = (UCHAR)(LBA>>8);
sptdwb.sptd.Cdb[5] = (UCHAR)(LBA);
sptdwb.sptd.Cdb[7] = SectorCnt>>8;
sptdwb.sptd.Cdb[8] = (UCHAR)SectorCnt;
length = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);
status = DeviceIoControl(fileHandle,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&sptdwb,
length,
&sptdwb,
length,
&returned,
FALSE);
if ((sptdwb.sptd.ScsiStatus == 0) && (status != 0)) {
return TRUE;
}
return FALSE;
}
您可以创建自己的供应商/自定义命令,然后通过上述方式将其发送到 USB MSC。但是您的设备应该正确识别它们!