Solved

Com Ports

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

766 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