|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Device Driver in VB 2005I'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. >but I couldn't get values from device driver 'cause I get an exception What does System.Runtime.InteropServices.Marshal.GetLastWin32Error()>("Unable to >read from driver"). 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. Mattias Sjögren ha scritto:
> >but I couldn't get values from device driver 'cause I get an exception It returns 6. What does it mean?> >("Unable to > >read from driver"). > > What does System.Runtime.InteropServices.Marshal.GetLastWin32Error() > return after the ReadFile call? 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. >It returns 6. What does it mean? It means "The handle is invalid". Have you verified that CreateFilereally 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. Mattias Sjögren ha scritto:
> >It returns 6. What does it mean? No, it returned an invalid handle and I've already fixed the code for> > 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. 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. 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. Dick Grier ha scritto:
Show quoteHide quote > Is this a serial port device? If so, why not use System.IO.Ports? I'm trying to read values from an ISA card.> > 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. Thanks for your attention
ADO.net + MS Access = performance issues
VB.NET Structures and Union Help. how to group similar events? 2nd Post: Problem adding events to controls created at run-time KeyUp + KeyDown Event Handler Problems with ByRef parameters Copying files across network String vs. Stringbuilder speed parsing questio System.IO.FileSystemWatcher is missing alot of files. continue debugging without interrupting |
|||||||||||||||||||||||