(page requirements)
Search tips:
Downloads
Newsletter »

How to access ports

In the old days of DOS and 16bit Windows, writing to ports (serial, printer, game, video and other ports) in your computer was easy; all you had to do was use the "port[]" command.
 
Delphi no longer supports the "port[]" command, so you may have to use assembly functions as follows:
 
function ReadPortB
         ( wPort : Word ) : Byte;
begin
  asm
    mov dx, wPort
    in al, dx
    mov result, al
  end;
end;

procedure WritePortB
         ( wPort : Word; bValue : Byte );
begin
  asm
    mov dx, wPort
    mov al, bValue
    out dx, al
  end;
end;
Listing #1 : Delphi code. Download port (0.26 KB).
 
    NOTE:Some operating systems, such as Windows NT, may not let you access ports directly as demonstrated above. In this case, you may have to depend on a third party library to gain proper access to internal ports.
 
 
Applicable Keywords : Assembly, Delphi, Delphi 1.x, Delphi 2.x, Delphi 3.x, Functions, Source Code
 
 
 
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Designed using HTML Kit editor