请问:编程如何直接读取串口第九针(地址$3FE)的状态。(10分)

  • 主题发起人 主题发起人 qgqg
  • 开始时间 开始时间
Q

qgqg

Unregistered / Unconfirmed
GUEST, unregistred user!
请问:编程如何直接读取串口第九针(地址$3FE)的状态?
我用如下代码嵌入汇编编程,提示特殊指令,不能执行。
function ReadPort(PortAdress:word) : byte; pascal;
begin
asm
mov dx,PortAdress
in al,dx
mov @result,al
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
w:Byte;
begin
w:=ReadPort($3fe);
Label1.Caption:=FloatToStr(w);
end;
 
nt系统下禁止直接访问硬件。
 
我是在XP系统下。
 
没必要这样吧,第九针不就是RI嘛,可以直接用 GetCommModemStatus 获取,然后
检测 MS_RING_ON 信号
 
98下可以直接操作端口。
XP不能用 BASM 直接读写端口了。
第九针如果是MODEM振铃,用 mscomm32 就可以了。
 
串口上没有接Modem,我准备用第九针作为程序运行的检测位,他为高,我的程序就运行,为低则不运行。
 
谁也没说必须接Modem阿,[:(]



GetCommModemStatus Function

Retrieves the modem control-register values.

Syntax

BOOL WINAPI GetCommModemStatus(
__in HANDLE hFile,
__out LPDWORD lpModemStat
);
Parameters
hFile [in]
A handle to the communications device. The CreateFile function returns this handle.

lpModemStat [out]
A pointer to a variable that receives the current state of the modem control-register values. This parameter can be one or more of the following values.

Value Meaning
MS_CTS_ON
0x0010
The CTS (clear-to-send) signal is on.

MS_DSR_ON
0x0020
The DSR (data-set-ready) signal is on.

MS_RING_ON
0x0040
The ring indicator signal is on.

MS_RLSD_ON
0x0080
The RLSD (receive-line-signal-detect) signal is on.


Return Value
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The GetCommModemStatus function is useful when you are using the WaitCommEvent function to monitor the CTS, RLSD, DSR, or ring indicator signals. To detect when these signals change state, use WaitCommEvent and then use GetCommModemStatus to determine the state after a change occurs.

The function fails if the hardware does not support the control-register values.

Requirements
Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Header Declared in Winbase.h; include Windows.h.

Library Use Kernel32.lib.

DLL Requires Kernel32.dll.


See Also
Communications Functions
Communications Resources
CreateFile
WaitCommEvent



Send comments about this topic to Microsoft

Build date: 6/19/2008
 
最好不要用 RING 线,用 RLSD 线或者 DSR 比较好。
 
用 RLSD 线或者 DSR 要怎么处理呢?
 
tseug 很精通串口啊
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
645
import
I
I
回复
0
查看
784
import
I
后退
顶部