Solved

Com Ports

Posted on 1997-09-13
1
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
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…
This video shows how use content aware, what it’s used for, and when to use it over other tools.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

732 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