Home All Groups Group Topic Archive Search About

Device Driver in VB 2005

Author
7 Feb 2006 2:37 PM
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.aspx?scid=kb;en-us;823179&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.

Author
7 Feb 2006 3:31 PM
Mattias Sjögren
>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.GetLastWin32Error()
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.
Author
8 Feb 2006 8:13 AM
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.GetLastWin32Error()
> return after the ReadFile call?

It returns 6. What does it mean?

Thanks


Show quoteHide quote
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
Author
8 Feb 2006 2:59 PM
Mattias Sjögren
>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.
Author
8 Feb 2006 4:22 PM
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.
Author
8 Feb 2006 6:10 PM
Dick Grier
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.
Author
9 Feb 2006 7:56 AM
Fla
Dick Grier ha scritto:

Show quoteHide quote
> 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