By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

Device Driver in VB 2005

P: n/a
Fla
Hy!
I'm newbie to VB 2005 and I'm trying to read value from a device
driver, as I used in VB6 with CreateFile and DeveiceIoControl. I get a
correct driver handle with CreateFile but I can't read values with
ReadFile, as reported in this URL
http://support.microsoft.com/default...79&Product=vb6

I tried with ReadFile with the following code lines:

Try
Success = ReadFile(hSerialPort, Buffer, BytesWritten,
BytesRead, IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to read from driver")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
End Try

but I couldn't get values from device driver 'cause I get an exception
("Unable to
read from driver").

Is it better DeviceIoControl? What am I doing wrong?

Thanks for your replies.

Feb 7 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
>but I couldn't get values from device driver 'cause I get an exception
("Unable to
read from driver").


What does System.Runtime.InteropServices.Marshal.GetLastWin3 2Error()
return after the ReadFile call?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 7 '06 #2

P: n/a
Fla

Mattias Sjögren ha scritto:
but I couldn't get values from device driver 'cause I get an exception
("Unable to
read from driver").
What does System.Runtime.InteropServices.Marshal.GetLastWin3 2Error()
return after the ReadFile call?


It returns 6. What does it mean?

Thanks



Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Feb 8 '06 #3

P: n/a
>It returns 6. What does it mean?

It means "The handle is invalid". Have you verified that CreateFile
really returns a valid handle? What's the type of hSerialPort?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 8 '06 #4

P: n/a
Fla

Mattias Sjögren ha scritto:
It returns 6. What does it mean?


It means "The handle is invalid". Have you verified that CreateFile
really returns a valid handle? What's the type of hSerialPort?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


No, it returned an invalid handle and I've already fixed the code for
it, but I still haven't found a solution for ReadFile 'cause I get
"LastWin32Error 1: Incorrect function".

Try
Success = ReadFile(hCVxD, Buffer, BytesWritten, BytesRead,
IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to read from driver")
Else
TextBox3.Text = CStr(BytesRead)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

What am I doing wrong?
According .NET, which is better: DeviceIoControl, as in VB6, or
ReadFile?

Thanks for your replies.

Feb 8 '06 #5

P: n/a
Is this a serial port device? If so, why not use System.IO.Ports?

Personally, I want more information about what it is that you are REALLY
trying to do before suggesting what might be the problem/solution.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
Feb 8 '06 #6

P: n/a
Fla

Dick Grier ha scritto:
Is this a serial port device? If so, why not use System.IO.Ports?

Personally, I want more information about what it is that you are REALLY
trying to do before suggesting what might be the problem/solution.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.


I'm trying to read values from an ISA card.

Thanks for your attention

Feb 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.