Solved

Com Ports

Posted on 1997-09-13
1
379 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
The viewer will learn common shortcuts with easy ways to remember them. The viewer will then learn where to find all of the keyboard shortcuts, how to create/change them, and how to speed up their workflow.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

815 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

8 Experts available now in Live!

Get 1:1 Help Now