Solved

Get Handle for SerialPort

Posted on 2011-03-22
4
1,229 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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