J
Jen C.
Hi all,
I have developed a custom USB driver based on the USB printer
driver. It works great with Win32 read and write functions. The
driver communicates only through the stream interface, but Seek is not
supported, it just returns a -1.
I have not been able to get reads to work with a .NET program,
however. I am opening a FileStream, and trying to read 64 bytes into
an array of bytes.
It looks to me like .NET is asking my driver for 128 bytes, not 64,
and then tries to do a SEEK which fails, because my driver doesn't
implement Seek.
So my questions are:
1.) Why is it trying to read 128 bytes instead of 64?
2.) Can I make a change to my driver, or two my C# code to tell it to
not try to seek?
3.) Is there a better way to do this? I suppose I could p/invoke to
the Win32 functions but I'd rather not do that.
Here is the Debug log output.
4294889170 PID:3de437e TID:43ab870e 0x83ab897c: >PSO_Open(0x4e670,
0xc0000000, 0x0)
4294889170 PID:3de437e TID:43ab870e 0x83ab897c: <PSO_Open:1
4294889176 PID:3de437e TID:43ab870e 0x83ab897c: >PSO_Read(0xe14166c,
128)
4294889177 PID:3de437e TID:43ab870e 0x83ab897c: PSO_Read timeout due
in 1380 msec
4294889178 PID:3de437e TID:43ab870e 0x83ab897c: <PSO_Read:128
4294889181 PID:3de437e TID:43ab870e 0x83ab897c: PSO_Seek
Here is my code. It just tries to read 64 bytes when I click the
button.
public Form1()
{
InitializeComponent();
m_bufferIncoming = new byte[64];
}
public const string USBDRIVERNAME = "PSO1:";
public byte[] m_bufferIncoming;
FileStream m_driverFileStream;
private void button1_Click(object sender, EventArgs e)
{
try
{
m_driverFileStream = new FileStream(USBDRIVERNAME,
FileMode.Open, FileAccess.ReadWrite,
FileShare.None);
}
catch (Exception eFileException)
{
throw new USBDriverException("Could not open PSO1:
driver" +
eFileException.ToString());
}
try
{
m_driverFileStream.Read(m_bufferIncoming, 0, 64);
}
catch (Exception eRead)
{
throw new USBDriverException("Could not read PSO1: " +
eRead.ToString());
}
}
private void Form1_Closing(object sender, CancelEventArgs e)
{
m_driverFileStream.Close();
}
}
I have developed a custom USB driver based on the USB printer
driver. It works great with Win32 read and write functions. The
driver communicates only through the stream interface, but Seek is not
supported, it just returns a -1.
I have not been able to get reads to work with a .NET program,
however. I am opening a FileStream, and trying to read 64 bytes into
an array of bytes.
It looks to me like .NET is asking my driver for 128 bytes, not 64,
and then tries to do a SEEK which fails, because my driver doesn't
implement Seek.
So my questions are:
1.) Why is it trying to read 128 bytes instead of 64?
2.) Can I make a change to my driver, or two my C# code to tell it to
not try to seek?
3.) Is there a better way to do this? I suppose I could p/invoke to
the Win32 functions but I'd rather not do that.
Here is the Debug log output.
4294889170 PID:3de437e TID:43ab870e 0x83ab897c: >PSO_Open(0x4e670,
0xc0000000, 0x0)
4294889170 PID:3de437e TID:43ab870e 0x83ab897c: <PSO_Open:1
4294889176 PID:3de437e TID:43ab870e 0x83ab897c: >PSO_Read(0xe14166c,
128)
4294889177 PID:3de437e TID:43ab870e 0x83ab897c: PSO_Read timeout due
in 1380 msec
4294889178 PID:3de437e TID:43ab870e 0x83ab897c: <PSO_Read:128
4294889181 PID:3de437e TID:43ab870e 0x83ab897c: PSO_Seek
Here is my code. It just tries to read 64 bytes when I click the
button.
public Form1()
{
InitializeComponent();
m_bufferIncoming = new byte[64];
}
public const string USBDRIVERNAME = "PSO1:";
public byte[] m_bufferIncoming;
FileStream m_driverFileStream;
private void button1_Click(object sender, EventArgs e)
{
try
{
m_driverFileStream = new FileStream(USBDRIVERNAME,
FileMode.Open, FileAccess.ReadWrite,
FileShare.None);
}
catch (Exception eFileException)
{
throw new USBDriverException("Could not open PSO1:
driver" +
eFileException.ToString());
}
try
{
m_driverFileStream.Read(m_bufferIncoming, 0, 64);
}
catch (Exception eRead)
{
throw new USBDriverException("Could not read PSO1: " +
eRead.ToString());
}
}
private void Form1_Closing(object sender, CancelEventArgs e)
{
m_driverFileStream.Close();
}
}