0

The program is to test the serial port loopback.I find the problem to be in the port number of serial port. How to identify the port number of usb to uart bridge COM39 in the device manager? The program is compiled properly but when executed it is getting stucked.

#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <math.h>
#include <dos.h>
#define MAX 5000        // max length of delay period of time
#define COM1 (unsigned short)0x006  // serial port COM1
#define COM2 (unsigned short)0x2F8  // serial port COM2
int TestSerial ();
void Delay (int num);
int TestSerial ()
{
  int index, value, result = 0;
  printf ("Begin to execute outp() & inp()...\n");
  for (index = 0; index < 10; index++)
    {
      printf ("Data sent to COM1 is: %d\n", index);
      _outp (COM1, index);
      Delay (500);
      value = _inp (COM1);
      printf ("Data returned from COM1 is: %d\n", value);
      printf ("\n");
      if (value != index)
        {
            printf ("Error in loop testing of the COM1!\n");
            result = -1;
            return result;
        }
    }
  return result;
}

void Delay (int num)
{
  int m, n, cycle = MAX;
  for (m = 0; m <= num * cycle; m++)
    n = m - 1;
  return;
}

void main (void)
{
  int rc = 0;
  printf ("\n");
  rc = TestSerial ();
  if (rc != 0)
    printf ("Error in TestSerial()!\n");
  else
    printf ("Success in TestSerial()!\n");
  return;
}

The output is as below enter image description here

I get an IO range for COM1 under resource tab which I used in program initially but it did not work

enter image description here

I want to use the program to test the serial port COM39 which is nothing but UART to USB bridge. There is no resource tab for the said COM39. How to find the IO range of the port to be used in the #define section? enter image description here

Deepak Kumar
  • 11
  • 1
  • 4

1 Answers1

0

I would look up com port enumeration. This thread here is an example of looking for all of them, but it should be easy to adapt to looking up just COM10.

What is proper way to detect all available serial ports on Windows?

DClyde
  • 96
  • 2