all groups > dotnet interop > march 2005 >
You're in the

dotnet interop

group:

problem with scsi_pass_through and Device_io_control urgent


RE: problem with scsi_pass_through and Device_io_control urgent Daniel Petersson, Cefalo
3/29/2005 2:37:05 AM
dotnet interop:
Hi,

You need to explain your problem a litte more! We cant
spend hours reading every line of your code.

// Daniel


[quoted text, click to view]
problem with scsi_pass_through and Device_io_control urgent sai sai via DotNetMonster.com
3/29/2005 3:53:37 AM
I used scsi_pass_through with Device_io_control.But i am not getting any
output.what is my mistake in my code.Any body Please help me Urgent??


[StructLayout(LayoutKind.Sequential)]
class SCSI_PASS_THROUGH
{
public UInt16 Length;// = (UInt16) Marshal.SizeOf(typeof
(SCSI_PASS_THROUGH));
public byte ScsiStatus;
public byte PathId;
public byte TargetId;
public byte Lun;
public byte CdbLength;
public byte SenseInfoLength;
public byte DataIn;// = SCSI_IOCTL_DATA_IN;
public UInt32 DataTransferLength;
public UInt32 TimeOutValue;
public char[] DataBufferOffset;// = (UInt32)
public UInt32 SenseInfoOffset;// = (UInt32)
public byte[] Cdb = new byte[16];
//public char[] Cdb = new char[16];
public SCSI_PASS_THROUGH(byte target, byte cdbLen, UInt32
dataTransferLength)
{
TargetId = target;
CdbLength = cdbLen;
DataTransferLength = dataTransferLength;
}
}

[StructLayout(LayoutKind.Sequential)]
struct SCSI_PASS_THROUGH_WITH_BUFFERS
{
public UInt32 Filler;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public byte[] ucSenseBuf;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=512)]
public byte[] ucDataBuf;

}

[DllImport("kernel32.dll", SetLastError = true)]
static extern int WriteFile(
IntPtr hFile,
char[] lpBuffer,
int nNumberOfBytesToWrite,
ref int lpNumberOfBytesWritten,
IntPtr lpOverlapped);

[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true,
CharSet = CharSet.Auto)]
static extern int DeviceIoControl(
IntPtr hDevice, uint dwIoControlCode,
SCSI_PASS_THROUGH lpInBuffer, int nInBufferSize,
ref IntPtr lpOutBuffer, int nOutBufferSize,
ref int lpBytesReturned, IntPtr lpOverlapped);


[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);

unsafe public static void MoveFile()
{
IntPtr hFile = CreateFile(@"C:\\
test.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,IntPtr.Zero,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,IntPtr.Zero);
char[] buf=new char[4096];
for (int i = 1; i< 1023; i++)
{
buf[i] =(char)i;
}

IntPtr hDevice=IntPtr.Zero;
//hDevice = CreateFile(@"\\.\
G:",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,IntPtr.Zero,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,IntPtr.Zero);
//hDevice = CreateFile(@"\\.\G:\\
kk.x",GENERIC_READ,FILE_SHARE_READ,IntPtr.Zero,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,IntPtr.Zero);
//SCSI_PASS_THROUGH_WITH_BUFFERS sptwb = new
SCSI_PASS_THROUGH_WITH_BUFFERS(hFile,hDevice, 1024, 1024);
//int junk=0;
//int res =WriteFile(hDevice, buf, buf.Length ,ref junk,
IntPtr.Zero);

hDevice = CreateFile(@"\\.\
F:",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,IntPtr.Zero,OPEN_EXISTING,0,IntPtr.Zero);
SCSI_PASS_THROUGH spt = new SCSI_PASS_THROUGH(0,10,4096);

spt.Length = (UInt16) Marshal.SizeOf(typeof(SCSI_PASS_THROUGH));
spt.ScsiStatus = 0;
spt.PathId =0;
//spt.TargetId =01;
spt.Lun = 0;
//spt.CdbLength = 10;
spt.SenseInfoLength = 0;
spt.DataIn = SCSI_IOCTL_DATA_IN;
//spt.DataTransferLength=4096;
spt.TimeOutValue = 10;
spt.DataBufferOffset = buf;

spt.SenseInfoOffset = 0;

spt.Cdb[0] = 0xaa;
spt.Cdb[1] = 0;
spt.Cdb[2] = 0;
spt.Cdb[3] = 0;
spt.Cdb[4] = 0;
spt.Cdb[5] = 0;
spt.Cdb[6] = 0;
spt.Cdb[7] = 0;
spt.Cdb[8] = 8;
spt.Cdb[9] = 0;


int inputSize = Marshal.SizeOf(typeof(SCSI_PASS_THROUGH_WITH_BUFFERS));
IntPtr input = Marshal.AllocHGlobal(inputSize);
int outputSize = Marshal.SizeOf(typeof(byte)) * 4096;
IntPtr output = Marshal.AllocHGlobal(outputSize);
int size = 0;
IntPtr p=IntPtr.Zero;
int fResult = DeviceIoControl(
hDevice,
IOCTL_SCSI_PASS_THROUGH,//sptwb,//SCSI_PASS_THROUGH,//IOCTL_READ_DEVICE_INFO,//FSCTL_GET_VOLUME_BITMAP,
spt,//input,
Marshal.SizeOf(spt),
ref output,
outputSize,
ref size,
IntPtr.Zero);

--
RE: problem with scsi_pass_through and Device_io_control urgent sai sai via DotNetMonster.com
3/30/2005 4:50:17 AM
ok sir, Actually i want to write data into Flash(ROM) through scsi
Devices.I am doing it in C#.so i tried it by Device_io_control by using
SCSI_pass_through command.If i execute the above code, the scsi Device is
not giving any response,but the code is not giving any runtime error,In
Device_io_control we are sending data through "spt" variables, so the
device must fill the "output"
variable,but it is not filling any data or sending any data to device also

--
Re: problem with scsi_pass_through and Device_io_control urgent Mattias Sjögren
4/1/2005 11:53:47 PM
[quoted text, click to view]

According to the docs this should be an offset from the beginning of
thr struct, not an array member.

[quoted text, click to view]

You have to mark this member with [MarshalAs(UnmanagedType.ByValArray,
SizeConst=16)]


[quoted text, click to view]

I don't think you want lpOutBuffer to be a ref parameter here. Try
passing it by value.




Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button