怎么编程取得串口的I/O地址呢?(100分)

  • 主题发起人 IamWLJ888
  • 开始时间
多串口卡

//./COM5
 
楼主:估计我也要买多串口卡了,但我不用汇编的。。。所以不需要知道其IO地址[:D]

你用汇编写串口程序吗?
 
这么久了,难道真的没有人知道吗? :< [:(]
 
tseug 的做法是对的,
但是这种方法只能读到COM1---Com4这是BIOS定的.
要读到Com2---COm4 只要顺着400的地址往下读,
每个口,占用两字节共8字节.
超过Com4我就不知道了




 
我写的一个控件中也存在这个问题,关注
 
关注下列问题,一定对你有益:
http://delphibbs.com/delphibbs/dispq.asp?lid=1743719
http://delphibbs.com/delphibbs/dispq.asp?lid=1742072
http://delphibbs.com/delphibbs/dispq.asp?lid=1655569
http://delphibbs.com/delphibbs/dispq.asp?lid=1786356
 
这个问题不是很难,我有一个方法你可以一试 。
我也过并口通讯程序,并口操作范围是0378-037F,它的地址是内存0400:0008
你取0400:0008内存的内容可得0378,偏移1得0379……
你可以先看你机子的串口范围,再写程序搜索内存,看有没有何你串口相等的,有则……
此程序用C很容易实现。以下是我读写并口实例。
/*C代码*/
#include <stdio.h>
#include <dos.h>
char str_filename[20];

main(){
FILE *output_file;
int ch,i,h,first,second;
struct time t;
unsigned int port_data,port_in,port_ctrl;
unsigned int far *fpt=(unsigned int far *)0x00400008;
printf("please input file name:/n");
scanf("%s",str_filename);
if ((output_file=fopen(str_filename,"rb"))==NULL){
printf("can not open file %s/n",str_filename);
exit(0);
}
port_data=*fpt;/*378h 数据地址*/
port_in=*fpt+1;/*379h 状态线端口*/
port_ctrl=*fpt+2;/*37Ah 控制端口*/
printf("port_number = %x/n",port_data);
outportb(port_ctrl,0x01);/*初始化,发控制信号*/
outportb(port_in,0x00);/*初始化状态端口为0*/
以上是取并口输出范围
 
to lijianyu1982:
谢谢,不过我的程序要求的是要自动取得地址,运用在不同的机子中,如果再去查串口
地址范围,这个就不是自动的啦。
还是谢谢您的回答。

拜托大家啦。
我要的是 “我的电脑”->“属性”->“设备管理”->“端口”->通讯端口下的->”
属性“->”资源“->输入输出范围的设置值。要在程序中自动取得。
操作系统是怎样取得这个地址的呢?真的没有人知道吗?[:(][:(][:(][:(][:(]
 
晕 还没解决啊 ???
 
学到不少,呵呵。
 
var
reg:tregistry;
str:tstrings;
i:integer;
begin
reg:=reg.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
reg.OpenKey('hardware/devicemap/serialcomm',false);
str:=str.Create;
reg.GetValueNames(str);
for i:=0 to str.Count-1 do begin
combobox1.Items.Add(reg.ReadString(str.Strings));
end;
str.Free;
reg.CloseKey;
reg.Free;
end;
 
顶部