Solved

Com Ports

Posted on 1997-09-13
1
376 Views
Last Modified: 2013-11-15
I have a Delphi 1 program that sends a phone number to the com port.

Since upgrading to Delphi 3 , I cannot compile the source as D3 uses the com ports differently.

I cannot understand the help on this subject and I am a beginner.

I would like the source, please.
0
Comment
Question by:kennys
1 Comment
 
LVL 1

Accepted Solution

by:
sassas081597 earned 100 total points
ID: 1344749
Here you are!
unit NpsPort;
//Copyright:            (ñ) NPS, 1997
interface

uses
  Windows,
  Classes;
type
{Abstract class}
TNpsPort = class(TComponent)
   private
      FAddress : Word;
    public
       constructor Create(AOwner:TComponent);      override;
   published
       property      Address      : Word read      FAddress               write FAddress;
end;      // TNpsPort

{Byte Port class}
TNpsPortB = class(TNpsPort)
private
      function      GetValue : Byte;
      procedure      SetValue(AValue:Byte);
public
      constructor Create(AOwner:TComponent);      override;
      property      Value      : Byte read      GetValue write SetValue;
end;      // TNpsPortB

{Word Port class}

TNpsPortW = class(TNpsPort)
private
      function      GetValue : Word;
      procedure      SetValue(AValue:Word);
public
    constructor Create(AOwner:TComponent);      override;
    property      Value      : Word read      GetValue write SetValue;
end;      // TNpsPortW

      procedure Register;

      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

{********************
 * Create component      *
 ********************}
constructor TNpsPort.Create(AOwner:TComponent);
begin
      inherited Create(AOwner);
end;      // Create

constructor TNpsPortB.Create(AOwner:TComponent);
begin
      inherited Create(AOwner);
end;      // Create

constructor TNpsPortW.Create(AOwner:TComponent);
begin
      inherited Create(AOwner);
end;      // Create
{**************
 * Get Value      *
 **************}
function      TNpsPortB.GetValue : Byte;
begin
      Result := PortReadByte(Faddress);
end;

function      TNpsPortW.GetValue : Word;
begin
      Result := PortReadWord(Faddress);
end;
{**************
 * Get Value      *
 **************}
procedure      TNpsPortB.SetValue(AValue:Byte);
begin
  PortWriteByte(Faddress,AValue);
end;      // Click

procedure      TNpsPortW.SetValue(AValue:Word);
begin
  PortWriteWord(Faddress,AValue);
end;      // Click
{************************************************************************
 * Component registration, change section name for you favorite Add In      *
 ************************************************************************}
procedure Register;
begin
  RegisterComponents('Add',[TNpsPortB]);
  RegisterComponents('Add',[TNpsPortW]);
end;      // Register

////////////////////////////////////////////////////////
// procedures and functions for maximall speed access //
////////////////////////////////////////////////////////

const
      Delay = 150;                        // dalay between two bytes operation
                                                              // depending of CPU speed and cards speed
{****************************************************************
 * Port Read byte function                                                                                                                  *
 * Parameter: port address                                                                                                                   *
 * Return:             byte value from given port                                                                         *
 ****************************************************************}
function PortReadByte(Addr:Word) : Byte; assembler; register;
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 work.      *
 ****************************************************************}
function PortReadWord(Addr:Word) : Word; assembler; register;
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 all cases, only to adjust DELAY if need            *
 ****************************************************************}
function PortReadWordLS(Addr:Word) : Word; assembler; register;
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                                                                                                                  *
 * Parameter: port address                                                                                                                   *
 ****************************************************************}
procedure PortWriteByte(Addr:Word; Value:Byte); assembler; 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 work.      *
 ****************************************************************}
procedure PortWriteWord(Addr:word; Value:word); assembler; register;
asm
      XCHG      AX,DX
      OUT            DX,AX
end;
{****************************************************************
 * LOW SPEED Port Write Word procedure                                                                              *
 * Parameter: port address                                                                                                                   *
 * Return:             word value from given port                                                                         *
 * Comment:       work in all cases, only to adjust DELAY if need            *
 ****************************************************************}
procedure PortWriteWordLS(Addr:word; Value:word); assembler; register;
asm
      XCHG      AX,DX
      OUT            DX,AL                  // port LSB
      MOV            ECX,Delay
@1:
      LOOP      @1                        // delay between two writes
      XCHG      AH,AL
  INC            DX                        // port+1
      OUT            DX,AL                  // port MSB
end;

end.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
If your app took Google’s lash recently, here are the 5 most likely reasons.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now