Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2006

Tip: Looking for answers? Try searching our database.

Problem calling DeviceIoControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eduwushu - 27 Jul 2006 19:58 GMT
Hi Im trying tu use deviceiocontrol to retrieve serial port informationin a
C#project.
The problem is that i cant make it work. it gives me always the same error.
The function returns a win32 error telling me that the parameter is not valid
The problem is that i dont know which parameter is the function referring to.
I have tried everything to make it work but i cant
I create the handle to the serial port correctly in the overlapped mode. I
call some functions to change different parameters of the serial port and
everything goes fine, none of the imported functions gives me any error.
But when i finally call DeviceiOcONTROL:

IntPtr control = Marshal.AllocHGlobal(3);
           IntPtr stats = Marshal.AllocHGlobal(24);
           IntPtr BaudRate = Marshal.AllocHGlobal(4);
           if (hFile != IntPtr.Zero)
           {
               if (false != DeviceIoControl(hFile,
IOCTL_SERIAL_GET_LINE_CONTROL, IntPtr.Zero, 0, control, 3, out returned,
IntPtr.Zero))
               {
                   SERIAL_LINE_CONTROL c =
(SERIAL_LINE_CONTROL)Marshal.PtrToStructure(control,
typeof(SERIAL_LINE_CONTROL));
                   arg.DataBits = c.WordLenght;
                   arg.bitsStop = c.StopBits;
                   arg.paridad = c.Parity;
               }
               else
               {
                   MessageBox.Show(new
System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()).Message);
                   arg.DataBits = -1;
                   arg.bitsStop = -1;
                   arg.paridad = -1;
               }

i always enter the else clause and it gives me the "inbcorrect parameter"
error.
¿Somebody knows which parameter could be referring to?
Many thanks
bullshark@gmail.com - 27 Jul 2006 21:15 GMT
> Hi Im trying tu use deviceiocontrol to retrieve serial port informationin a

> IntPtr control = Marshal.AllocHGlobal(3);

I don't have  reference handy. Are you sure about the size of the
SERIAL_LINE_CONTROL structure? It seems kind of odd to use just three
bytes.

Could you post your declarations for SERIAL_LINE_CONTROL and
DeviceIoControl?

bullshark
eduwushu - 28 Jul 2006 12:01 GMT
Hi I solved the problem. The problem was the declaration i made of
IOCTL_SERIAL_GET_LINE_CONTROL. the C# function i wrote to emulate the
CTL_CODE macro to construct the IOCTL's codes was wrong. So i was passing to
DeviceIoControl a 'guess-what' control code so it was probably expecting as
input or output buffer something different from i was actually passing.
And yes the size of the structures are all right. I put that in that way
because i was desperate and i was triyng all kind of thing but at first i had
something like this:

IntPtr
control=Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SERIAL_LINE_CONTROL)); or
something like that

Many Thanks anyway for the reply , see you!

> > Hi Im trying tu use deviceiocontrol to retrieve serial port informationin a
>
[quoted text clipped - 8 lines]
>
> bullshark
bullshark@gmail.com - 28 Jul 2006 13:37 GMT
> Hi I solved the problem. The problem was the declaration i made of

Glad to hear it. It's always something simple isn't it?

I would still like to see your declarations for SERIAL_LINE_CONTROL
structure. It might help me with a problem I have.

thanks

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.