News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How do I use com ports larger than 9?

Started by jimg, May 30, 2017, 04:20:09 AM

Previous topic - Next topic

jimg

I've been at this for hours with no progress.
I am trying to open com12 on my computer.
I know it a good port because I can open and communicate through it with two different terminal program.
When trying to write some masm to talk to the port, I can't open any port greater than 9.  Com1 works fine, just not com12.

This is what I tried-
opencom12 proc
.data
c12 db "COM12:",0
;c12 db "COM12",0
;c12 db "\\\\.\\COM12",0
;c12 db "\\\\.\\COM12:",0
;c12 db "\\.\COM12:",0
.code
    inv CreateFile,addr c12,GENERIC_READ or GENERIC_WRITE,
        0, ; comm devices must be opened w/exclusive-access
        0, ; no security attrs
        OPEN_EXISTING, ; comm devices must use OPEN_EXISTING
        0, ; not overlapped I/O
        0  ; hTemplate must be NULL for comm devices
    .if eax == INVALID_HANDLE_VALUE
        inv GetErrDescriptionx,soff("opencom12")
        ; handle error here
        inv wsprintf,addr emsg,addr emsgfmt,addr c12
        msg emsg

The only thing I found searching the internet, was some nonsense about having to use \\\\.\\COM12, but that, or any other combination of slashes and periods does not work.

For the normal case, where I would use "COM12:", I get the error comment-
    Error Code 123
    The filename, directory name, or volume label syntax is incorrect.

It works fine for "COM1:", just not anything over COM9.

If I try any other of the myriads of suggestions involving slashes, I get the error comment-
    Error Code 2
    The system cannot find the file specified.

which makes sense since the filename is bogus.


I don't want to do anything that would make the device come up on com1-9 because I am trying to write a generic program that would work on whatever the port was.


Does anyone have any code or experience with comports > 9 ?

jimg

Of course, after hours of screwing around, and finally asking here, minutes afterward I found a combination that works-

c12 db "\\.\COM12",0

does not work with colon at end.

TWell

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
QuoteTo specify a COM port number greater than 9, use the following syntax: "\\.\COM10". This syntax works for all port numbers and hardware that allows COM port numbers to be specified.

jimg

Of course, I first went here
https://support.microsoft.com/en-us/help/115831/howto-specify-serial-ports-larger-than-com9
You can see some of the things I tried in the first post.
I also saw the other but tried "\\.\COM10:" since 1-9 worked with the name returned by enumports and they all ended with a colon.
Pretty messy, Microsoft.