How can I know wich serial port has a computer ?
Posted on 2002-08-07 14:24:40 by greenant
Hi greenant,

Under DOS: check 0040:0000 here is bios data area and bios reversed 4 x dword for active port numbers. If dw = 0 not active port

03f8h, 02f8h, 03e8h, 02e8h COM hardware port numbers

For Windows (my idea) : put below code in a DLL.


getport proc

mov edx, [esp+0ch]
in al,dx
cmp al,0ffh
sete al,1

ret 0ch
getport endp

and load dll in your program call function like below:

xor ecx,ecx
xor eax,eax

call getport, 03f8h ; com1
add ecx,eax

call getport, 02f8h ; com2
add ecx,eax

call getport, 03e8h; com3
add ecx,eax

call getport, 02e8h ; com4
add ecx,eax


ecx = total port number.

have nice days,
Posted on 2002-08-08 19:43:41 by CYDONIA
I could be wrong but I don't think in/out can be used for direct port access under win32 (maybe that's why it has to be in a dll?). The way that win32 api says to acces com ports is using CreateFile/ReadFile/WriteFile.
Posted on 2002-08-08 21:00:22 by Kudos
Hi Kudos,

You right, i used these commands in a DLL library. Protect Mode not post persmission IN / OUT commands.

I coded simple example about com ports, included dll and main source file.

Have nice days

btw: sorry first message contain a bug:

[b] sete al,1 ---> wrong
setne al ----> right
Posted on 2002-08-09 04:00:12 by CYDONIA
use EnumPorts win-api, and look PortInfo1.pname for strings starting with 'Com'

Posted on 2002-08-09 04:13:46 by kamilh