[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get Handle for SerialPort

Posted on 2011-03-22
4
Medium Priority
?
1,306 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 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