• C

Determining Comm Ports

Does anyone have any code that can determine what
comm ports are available on a computer.  I need
the source code.  Cheers
scotdanceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
For which OS?
0
MatthewLCommented:
Hi scotdance;

I agree with jkr, we need more info.  If you have an ibm pc the bios stores the base addresses at the following locations

COM port       address where base address is stored
 1                       400 (hex)
 2                       402 (hex)
 3                       403 (hex)
 4                       404 (hex)

If a com port is not installed then the base address is set to 0.

so for example (16 bit world) printf( "COM1: %x", *(unsigned int *)0x400 ); will print out the current base address for COM1.

but as I agreed we don't know what platform or O/S you are using.

Matt
0
scotdanceAuthor Commented:
It's for DOS
0
Choose an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

sumant032199Commented:
See my answer in C++ section.
If you feel satisfied with that answer then give me points.
I am here to give you more info about
serial ports.
0
scotdanceAuthor Commented:
I need the code to put in a C program to do this.  Not to use the MSD.EXE method.
0
MatthewLCommented:
Hi scotdance;

Is this what your looking for?

#include <stdio.h>

int isComInstalled( int PortNum );

void main( void )
{
      if( isComInstalled( 1 ) )
            printf("COM1 installed\n");

      if( isComInstalled( 2 ) )
            printf("COM2 installed\n");

      if( isComInstalled( 3 ) )
            printf("COM3 installed\n");

      if( isComInstalled( 4 ) )
            printf("COM4 installed\n");

}

int isComInstalled( int PortNum )
{
      unsigned int * baseAddr = (unsigned int *)0x400;
      baseAddr = baseAddr + 2*(PortNum-1);
      if( *baseAddr )
            return( 1 );
      else
            return( 0 );
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bsudhakarCommented:
Hi,
If you are using DOS OS then you can find the comport by doing this small exercise instead of writing application.

short the 2 and 3 pin of the serial port.  Assume COM1

type debug at the dos prompt then
hyphen prompt will appear
type o 0378 41

if the pins are shorted ie basically you are shorting the transmit and receive pins.  so you have to get back the chr you had sent.  Basically in the above said ex you are sending 41h ie A.
if you read the port by giving this commad you should get back same A
-i 3fd
..

I hope this answers your query.
0
MatthewLCommented:
Hi scotdance;

What's up? If you don't give us feedback on what's wrong with our proposals we can't fix them for you.

Matt
0
scotdanceAuthor Commented:
Thank MatthewL for you help it was good but I've another problem to solve now you might be able to help me with.

ScotDance
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.