如何利用moden的驱动程序进行拨号,进行通讯啊

yangyugw 2002-10-23 05:49:34
我的程序在如果安装了moden的驱动程序,就无法打开串口
因为好象被驱动程序占用了,而且如果直接对moden通过AT指令的话
兼容性也不太好,那位做过用程序控制moden的,给个方法
最好有代码,因为我没有头绪
...全文
53 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanderung 2002-10-27
  • 打赏
  • 举报
回复

五、获取当前活动的连接及其连接状态
  1、获取当前活动的连接
    获取当前活动的连接的RasAPI函数为RasEnumConnections,其函数原型为:
function RasEnumConnections( var lprasconn : RASCONN ;//接收活动连接的缓冲区的指针
var lpcb: DWORD;//缓冲区大小
var lpcConnections : DWORD//实际的活动连接数
) : DWORD; stdcall;
function RasEnumConnections;external RasApiDll name 'RasEnumConnectionsA';
参数lprasconn提供了一个RASCONN类型数组的指针,指向一个接收活动连接的缓冲
  区,其中RASCONN的类型说明如下:
RASCONN = record
dwSize : DWORD;//该结构所占内存的大小(Bytes),一般设置为SizeOf(RASCONN)
hrasconn : HRASCONN;//活动连接的句柄
szEntryName : array[0..RAS_MaxEntryName] of char;//活动连接的名称
szDeviceType : array[0..RAS_MaxDeviceType] of char;//活动连接的所用的设备类型
szDeviceName : array[0..RAS_MaxDeviceName] of char;//活动连接的所用的设备名称
end;
    参数lpcb为缓冲区大小(Bytes).
    参数lpcConnections将返回实际的连接数目.

    函数返回值为0表示执行成功;否则为错误代码.

  2、获取指定连接的连接状态
    获取指定连接的连接状态的RasAPI函数为RasGetConnectStatus,其函数原型为:
function RasGetConnectStatus(
hrasconn : HRASCONN; //指定活动连接的句柄
lprasconnstatus : LPRASCONNSTATUS//连接状态参数
) : DWORD; stdcall;
function RasGetConnectStatus;external RasApiDll name 'RasGetConnectStatusA';
    连接状态参数lprasconnstatus是一个RASCONNSTATUS类型的指针,将返回连接状态参数.
  RASCONNSTATUS和LPRASCONNSTATUS的类型说明如下:
LPRASCONNSTATUS = ^RASCONNSTATUS;
RASCONNSTATUS = record
dwSize : DWORD;//该结构所占内存的大小(Bytes),一般设置为SizeOf(RASCONNSTATUS)
rasconnstate : RASCONNSTATE;//连接状态标识,一组DWORD类型数值的集合。
dwError : DWORD;//错误类型标识符
szDeviceType : array[0..RAS_MaxDeviceType] of char;//活动连接的所用的设备类型
szDeviceName : array[0..RAS_MaxDeviceName] of char;//活动连接的所用的设备名称
end;
    函数返回值为0表示执行成功;否则为错误代码.

    下面是一个应用例子,列出了当前系统中活动的连接的名称及其连接状态.
注意,应在RASCONN缓冲区的第一个RASCONN结构中设置dwSize.

const
MaxConnections = 10;//最多的拨号连接数目
var
connections : array[0..MaxConnections-1] of RASCONN;
longSize : dword;
intAvailabelConnections : dword;
intIndex : integer;
dwResult : DWORD;
strTemp : string;
RASCONNSTATUSData : RASCONNSTATUS;
begin
connections[ 0 ].dwSize := sizeof(RASCONN);//结构的大小
longSize := MaxConnections * connections[ 0 ].dwSize;//缓冲区大小
intAvailabelConnections := 0;//实际的活动连接的数目
//获取当前系统中活动的连接
dwResult := RasEnumConnections( connections[ 0 ], longSize,intAvailabelConnections );
if dwResult < > 0 then //获取当前系统中活动的连接
memo1.lines.add( '获取当前系统中活动的连接:' + GetRasError( dwResult ))
else
begin
memo1.lines.add( '当前系统中活动的连接' + inttostr( intAvailabelConnections )
+ '个,列举如下' );
for intIndex := 0 to intAvailabelConnections - 1 do
begin
strTemp := '连接名称:' + StrPAS( connections[ intIndex ].szEntryName )
+ ' 设备类型:' + StrPAS( connections[ intIndex ].szDeviceType )
+ ' 设备名称:' + StrPAS( connections[ intIndex ].szDeviceName );
//获取连接状态
dwResult := RasGetConnectStatus( connections[ intIndex ].hRasConn,@RASCONNSTATUSData );
if 0 < > dwResult then
strTemp := strTemp + ' 连接状态未知:' + GetRasError( dwResult )
else if RASCONNSTATUSData.rasconnstate = RASCS_Connected then
strTemp := strTemp + ' 连接状态:已连接'
else
strTemp := strTemp + ' 连接状态:(' +
inttostr(RASCONNSTATUSData.rasconnstate)+')';
memo1.lines.add( strTemp );
end;
end;
end;

以上程序在PWIN98+Delphi3.0下调试通过。
DelUser 2002-10-23
  • 打赏
  • 举报
回复
up
yangyugw 2002-10-23
  • 打赏
  • 举报
回复
我用的是spcomm控件
yangyugw 2002-10-23
  • 打赏
  • 举报
回复
你给的论坛里面没有sreach功能啊
My_first 2002-10-23
  • 打赏
  • 举报
回复
拨号上网的程序网上多的是,你上 www.playicq.com下一个

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧