在w2k和NT中,怎样实现对口地址的读写?类似c语言的outportb功能。急!(100分)

  • 主题发起人 主题发起人 1651gz
  • 开始时间 开始时间
1

1651gz

Unregistered / Unconfirmed
GUEST, unregistred user!
我在w98中可以通过汇编对口地址读写的,
function inportb(address:Word):Byte;
begin
Result:=0;
asm
Mov dx,address
In al, dx
Mov Result,al
end;
end;

procedure outportb(address:Word;data:Byte);
begin
asm
Mov dx,address
Mov al,data
Out dx,al
end;
end;
但到了w2k和NT就不行了,请教怎样才能解决?
 
在win2000和NT下对IO口地址进行读写操作,是工控的最基本功能。为什么这样难求解?
 
不难,只不过应用程序不能直接访问受操作系统保护的端口

可以用别的控件可以做到
这儿有一个例子,程序控制PC喇叭发音的,免费且有演示,
演奏美妙的而单调的音乐
作者没说支持D6,但我看要支持,不难
http://cn.torry.net/portaccess.htm
SmallPort v.1.4 FWS 202 Kb 28.08.00
By Alexander Weitzman. Simple component
to access hardware ports in
Windows 95, 98, NT and 2000 using VxD driver (included).

Fully functional
Source: Included
Exe-demo included
Download: D2 D3 D4 D5
 
是不是要调APi函数?
关注!
 
这好像和你的一样
unit Port95;
interface
function PortReadByte(Addr:Word) : Byte;
function PortReadWord(Addr:Word) : Word;
function PortReadWordLS(Addr:Word) : Word;
procedure PortWriteByte(Addr:Word
Value:Byte);
procedure PortWriteWord(Addr:Word
Value:Word);
procedure PortWriteWordLS(Addr:Word
Value:Word);
implementation
{*
* Port Read byte function
*Parameter:port address
*Return: byte value from given port
*}
function PortReadByte(Addr:Word) : Byte
assembler
regi
ster;
asm
MOV DX,AX
IN AL,DX
end;
{*
* HIGH SPEED Port Read Word function
* Parameter: port address
* Return: word value from given port
* Comment:may problem with some cards and computers that
can't to access whole word, usualy it works.
*}
function PortReadWord(Addr:Word) : Word
assembler
regi
ster;
asm
MOV DX,AX
IN AX,DX
end;
{*
* LOW SPEED Port Read Word function
* Parameter: port address
*Return:word value from given port
*Comment:work in cases,only to adjust DELAY if need
*}
function PortReadWordLS(Addr:Word) : Word
assembler
re
gister;
const
Delay = 150;
// depending of CPU speed and cards speed
asm
MOV DX,AX
IN AL,DX
//read LSB port
MOV ECX,Delay
@1:
LOOP @1 //delay between two reads
XCHG AH,AL
INC DX
//port+1
IN AL,DX //read MSB port
XCHG AH,AL //restore bytes order
end;
{* Port Write byte function*}
procedure PortWriteByte(Addr:Word
Value:Byte)
assemble
r
register;
asm
XCHG AX,DX
OUT DX,AL
end;
{*
* HIGH SPEED Port Write word procedure
* Comment:may problem with some cards and computers that
can't to access whole word, usualy it works.
*}
procedure PortWriteWord(Addr:word
Value:word)
assemble
r
register;
asm
XCHG AX,DX
OUT DX,AX
end;
{*
* LOW SPEED Port Write Word procedure
*}
procedure PortWriteWordLS(Addr:word
Value:word)
assemb
ler
register;
const
Delay = 150;
// depending of CPU speed and cards speed
asm
XCHG AX,DX
OUT DX,AL
MOV ECX,Delay
@1:
LOOP@1
XCHG AH,AL
INC DX
OUT DX,AL
end;
end. //单元结束
上述PORT95.PAS适用于Delphi 2.0/3.0、Windows 95 操作系统


///////////////////////////////////////



function InPort(PortAddr: word): byte;
{$IFDEF VER90}
assembler
stdcall;
asm
mov dx,PortAddr
in al,dx
end;



{$ELSE}



begin
Result := Port[PortAddr];
end;



{$ENDIF}



procedure OutPort(PortAddr: word
Databyte: byte);
{$IFDEF VER90}
assembler
stdcall;
asm
mov al,Databyte
mov dx,PortAddr
out dx,al
end;



{$ELSE}



begin
Port[PortAddr] := DataByte;
end;



{$ENDIF}
 
一般来说,你必须开发设备驱动程序来操作断口,因为2000和nt下端口对一般的应用程序是保护的
 
TVicHW32 好象就可以实现
我有破解的dll,需要可以给你
 

Similar threads

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