Solved

Get Handle for SerialPort

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scanning dentists xray (the small ones) 3 53
Error in JQuery 5 52
SqlDataBase 7 48
Service Controller 1 23
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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