Serial Ports

M

M. Raab

i have written an application that utilizes serail ports. In order not to
have to reinvent code, I decided to use John Hind's sample code that he
presented in MSDN magazine last year (Serial Comm: Use P/Invoke to Develop a
..NET Base Class Library for Serial Device Communications John Hind - MSDN
Magazine - October 2002)

it works fine except for one problem. i cannot address any port higher than
COM9. I am using an equinox multi-serial card that addes 16 serial ports, so
there are a total of 18 valid com ports. However when i try to open anything
over COM9: i get an error that says that it is an invalid name.

i llooked thruogh his code but was unable to find any reason why this would
fail.
does anyone have any explanations as to why it would fail or suggestions as
to how to fix this?

i appreciate your help
m
 
J

Jeffrey Tan[MSFT]

Hi m,

Thanks for posting in this group.
Based on my understanding, when you use the code of (Serial Comm: Use
P/Invoke to Develop a .NET Base Class Library for Serial Device
Communications John Hind - MSDN Magazine - October 2002), you can not
address any port higher than COM9.
I think first, you should confirm the problem is generated in win32 layer
or in the P/invoke layer between .Net and win32 API, so you can use the
link below to have a test:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/htm
l/msdn_serial.asp

Once you have find the cause layer, please feel free to feedback to me, I
will work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

Tom Hall

I ran into this when I wrote my own serial driver for .NET

For COM ports greater than 9 you have to use a special syntax when calling
CreateFile (which also works for 1 through 9).

the name should be \\.\COM10 - if using C# you need to escape those slashes
or use the literal prefix (the @)

Note the lack of a trailing colon as well. In my driver I had the user pass
in the COM #, which I converted to the appropriate string syntax.

e.g.

either
string port="\\\\.\\COM10";
or
string port= @"\\.\COM10";

See this link for the article (Q115831)

http://support.microsoft.com/default.aspx?scid=kb;[LN];115831

I have successfully opened ports to COM16 using this.

That should do it
Tom
 
M

M. Raab

Yes. this is the answer i also came up with while researching the problem. I
tried it and it works
Thanks for your help
m

Tom Hall said:
I ran into this when I wrote my own serial driver for .NET

For COM ports greater than 9 you have to use a special syntax when calling
CreateFile (which also works for 1 through 9).

the name should be \\.\COM10 - if using C# you need to escape those slashes
or use the literal prefix (the @)

Note the lack of a trailing colon as well. In my driver I had the user pass
in the COM #, which I converted to the appropriate string syntax.

e.g.

either
string port="\\\\.\\COM10";
or
string port= @"\\.\COM10";

See this link for the article (Q115831)

http://support.microsoft.com/default.aspx?scid=kb;[LN];115831

I have successfully opened ports to COM16 using this.

That should do it
Tom


"Jeffrey Tan[MSFT]" said:
Hi m,

Thanks for posting in this group.
Based on my understanding, when you use the code of (Serial Comm: Use
P/Invoke to Develop a .NET Base Class Library for Serial Device
Communications John Hind - MSDN Magazine - October 2002), you can not
address any port higher than COM9.
I think first, you should confirm the problem is generated in win32 layer
or in the P/invoke layer between .Net and win32 API, so you can use the
link below to have a test:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/htm
l/msdn_serial.asp

Once you have find the cause layer, please feel free to feedback to me, I
will work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

Thomas Lutz

In the Windows API you use the CreateFile function to open COM ports
using the names "COMn" for the COM port that you want to open.
If the port number n is greater than 9, you have to use the format
"\\.\COMn"

You will need to find the code in the class that opens the port using
the CreateFile function and change it so that it adds the "\\.\" to
the beginning of the COM port names in order to open COM9 and above.

For more serial I/O tools, visit:
www.taltech.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top