Solved

Get Handle for SerialPort

Posted on 2011-03-22
4
1,201 Views
Last Modified: 2012-05-11
Does anyone know how to get a handle for a SerialPort.

I am trying to generate a IOCTL_SERIAL_GET_COMMSTATUS message.

I have seen that people say you can open(create new ?) the port as a file and so get a handle that way but I cannot see how to do this.
0
Comment
Question by:jetbet
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:morgulo
ID: 35194317
Maybe use: SerialPort port = new SerialPort("COM1");
0
 

Author Comment

by:jetbet
ID: 35194328
What is the handle?
0
 
LVL 5

Accepted Solution

by:
morgulo earned 500 total points
ID: 35196921
If you need handle you must use CreateFile from kernel32.dll
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(string lpFileName, System.UInt32 dwDesiredAccess, System.UInt32 dwShareMode, IntPtr pSecurityAttributes, System.UInt32 dwCreationDisposition, System.UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);

Open in new window


read this:
"Open and Close Port"
http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx
0
 

Author Closing Comment

by:jetbet
ID: 35201379
Just what I was looking for.

Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now