Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Com Ports

Posted on 1997-09-13
1
Medium Priority
?
386 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Curious about the latest ransomware attack? Check out our timeline of events surrounding the spread of this new virus along with tips on how to mitigate the damage.
Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

636 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