[英]Program to test the loop back on serial port
程序是测试串口环回,我发现问题出在串口的端口号上。 如何在设备管理器中识别usb到uart桥COM39的端口号? 该程序已正确编译,但执行时会卡住。
#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;
}
我在我最初在程序中使用的资源选项卡下获得了 COM1 的 IO 范围,但它不起作用
我想用这个程序测试串口COM39,它只是UART到USB桥接器。 上述 COM39 没有资源选项卡。 如何在#define 部分中找到要使用的端口的 IO 范围?
我会查找 com 端口枚举。 这里的这个线程是查找所有这些的示例,但它应该很容易适应仅查找 COM10。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.