home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / apdtr.zip / ADMODEM.INT < prev    next >
Text File  |  1995-05-26  |  13KB  |  352 lines

  1. {$G+,X+,F+}
  2.  
  3. {Conditional defines that may affect this unit}
  4. {$I AWDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   ADMODEM.PAS 1.00                    *}
  8. {*        Copyright (c) TurboPower Software 1995         *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. unit AdModem;
  13.   {-Delphi modem component}
  14.  
  15. interface
  16.  
  17. uses
  18.   {-----RTL}
  19.   SysUtils,
  20.   Classes,
  21.   Messages,
  22.   WinTypes,
  23.   DsgnIntf,
  24.   Forms,
  25.   Controls,
  26.   {-----APD}
  27.   OoMisc,
  28.   AwModem,
  29.   AdMisc,
  30.   AdExcept,
  31.   AdPort,
  32.   AdModDB;
  33.  
  34. type
  35.   TLineSpeedEvent = procedure(M : TObject; Speed : LongInt) of object;
  36.   TConnectCountEvent = procedure(M : TObject; Remaining : Word) of object;
  37.  
  38. type
  39.   TCustomModem = class(TComponent)
  40.   private
  41.     ModemRec            : PModemRec;    {record passed to API calls}
  42.     FComPort            : TComPort;     {port modem is attached to}
  43.     Data                : TModemInfo;   {data about modem}
  44.  
  45.     FDialTimeout        : Word;
  46.     FAnswerTimeout      : Word;
  47.     FDelayFactor        : Word;
  48.     FCmdTimeout         : Word;
  49.     FDTRDropHold        : Word;
  50.     FCharDelay          : Word;
  51.     FTildeDelay         : Word;
  52.     FRingWaitTimeout    : Word;
  53.     FStarted            : Boolean;
  54.     FModemOk            : TNotifyEvent;
  55.     FModemConnect       : TNotifyEvent;
  56.     FModemBusy          : TNotifyEvent;
  57.     FModemVoice         : TNotifyEvent;
  58.     FModemNoCarrier     : TNotifyEvent;
  59.     FModemNoDialTone    : TNotifyEvent;
  60.     FModemError         : TNotifyEvent;
  61.     FGotLineSpeed       : TLineSpeedEvent;
  62.     FGotErrCorrection   : TNotifyEvent;
  63.     FGotDataCompression : TNotifyEvent;
  64.     FCmdTimedOut        : TNotifyEvent;
  65.     FDialTimedOut       : TNotifyEvent;
  66.     FAnswerTimedOut     : TNotifyEvent;
  67.     FDialCount          : TConnectCountEvent;
  68.     FAnswerCount        : TConnectCountEvent;
  69.  
  70.     procedure SetComPort(const NewPort : TComPort);
  71.       {-Change the modem's com port}
  72.     procedure SetModemStrPrim(const NewData : String; var Data : String; var RecData : PChar);
  73.       {-Set a modem's string field}
  74.     procedure SetInitCmd(Cmd : TCmdString);
  75.       {-Set the modem's InitCmd field}
  76.     procedure SetDialCmd(Cmd : TCmdString);
  77.       {-Set the modem's DialCmd field}
  78.     procedure SetDialTerm(Cmd : TCmdString);
  79.       {-Set the modem's DialTerm field}
  80.     procedure SetDialCancel(Cmd : TCmdString);
  81.       {-Set the modem's DialCancel field}
  82.     procedure SetHangupCmd(Cmd : TCmdString);
  83.       {-Set the modem's HangupCmd field}
  84.     procedure SetConfigCmd(Cmd : TConfigString);
  85.       {-Set the modem's ConfigCmd field}
  86.     procedure SetAnswerCmd(Cmd : TCmdString);
  87.       {-Set the modem's AnswerCmd field}
  88.     procedure SetOkMsg(Rsp : TRspString);
  89.       {-Set the modem's OkMsg field}
  90.     procedure SetConnectMsg(Rsp : TRspString);
  91.       {-Set the modem's ConnectMsg field}
  92.     procedure SetBusyMsg(Rsp : TRspString);
  93.       {-Set the modem's BusyMsg field}
  94.     procedure SetVoiceMsg(Rsp : TRspString);
  95.       {-Set the modem's VoiceMsg field}
  96.     procedure SetNoCarrierMsg(Rsp : TRspString);
  97.       {-Set the modem's NoCarrierMsg field}
  98.     procedure SetNoDialToneMsg(Rsp : TRspString);
  99.       {-Set the modem's NoDialToneMsg field}
  100.     procedure SetErrorMsg(Rsp : TRspString);
  101.       {-Set the modem's ErrorMsg field}
  102.     procedure SetRingMsg(Rsp : TRspString);
  103.       {-Set the modem's RingMsg field}
  104.     procedure SetLockDTE(Lock : Boolean);
  105.       {-Set whether the modem should lock the port rate or not}
  106.     procedure SetDialTimeout(Secs : Word);
  107.       {-Set the number of seconds before a dial attempt times out}
  108.     procedure SetAnswerTimeout(Secs : Word);
  109.       {-Set the number of seconds before an answer attempt times out}
  110.     procedure SetDelayFactor(Ticks : Word);
  111.       {-Set the number of ticks to wait between commands sent to the modem}
  112.     procedure SetCmdTimeout(Ticks : Word);
  113.       {-Set the number of ticks to wait for a modem response}
  114.     procedure SetDTRDropHold(Ticks : Word);
  115.       {-Set the number of ticks to hold DTR low during hangup}
  116.     procedure SetCharDelay(Ticks : Word);
  117.       {-Set the number of ticks to wait between each command character sent}
  118.     procedure SetTildeDelay(Ticks : Word);
  119.       {-Set the number of ticks to wait when a '~' is encountered in a command}
  120.     procedure SetRingWaitTimeout(Ticks : Word);
  121.       {-Set the number of ticks to wait before AutoAnswer resets}
  122.     procedure SetStarted(Start : Boolean);
  123.       {-Start or stop the modem}
  124.     procedure SetModemInfo(const Info : TModemInfo);
  125.       {-Set all fields for a modem}
  126.  
  127.   protected
  128.     procedure Notification(AComponent : TComponent; Operation : TOperation); override;
  129.     procedure CreateModemRecord;
  130.       {-Create the record passed to the API functions}
  131.     procedure DestroyModemRecord;
  132.       {-Destroy the record passed to the API functions}
  133.     procedure AssureStarted;
  134.       {-Make sure the modem has been started}
  135.  
  136.     {event methods}
  137.     procedure ModemOk; virtual;
  138.     procedure ModemConnect; virtual;
  139.     procedure ModemBusy; virtual;
  140.     procedure ModemVoice; virtual;
  141.     procedure ModemNoCarrier; virtual;
  142.     procedure ModemNoDialTone; virtual;
  143.     procedure ModemError; virtual;
  144.     procedure GotLineSpeed(Speed : LongInt); virtual;
  145.     procedure GotErrCorrection; virtual;
  146.     procedure GotDataCompression; virtual;
  147.     procedure CmdTimedOut; virtual;
  148.     procedure DialTimedOut; virtual;
  149.     procedure AnswerTimedOut; virtual;
  150.     procedure DialCount(Remaining : Word); virtual;
  151.     procedure AnswerCount(Remaining : Word); virtual;
  152.  
  153.     {com port this is linked to}
  154.     property ComPort : TComPort
  155.       read FComPort write SetComPort;
  156.  
  157.     {commands, timeouts, etc.}
  158.     property InitCmd : TCmdString
  159.       read Data.InitCmd write SetInitCmd;
  160.     property DialCmd : TCmdString
  161.       read Data.DialCmd write SetDialCmd;
  162.     property DialTerm : TCmdString
  163.       read Data.DialTerm write SetDialTerm;
  164.     property DialCancel : TCmdString
  165.       read Data.DialCancel write SetDialCancel;
  166.     property HangupCmd : TCmdString
  167.       read Data.HangupCmd write SetHangupCmd;
  168.     property ConfigCmd : TConfigString
  169.       read Data.ConfigCmd write SetConfigCmd;
  170.     property AnswerCmd : TCmdString
  171.       read Data.AnswerCmd write SetAnswerCmd;
  172.     property OkMsg : TRspString
  173.       read Data.OkMsg write SetOkMsg;
  174.     property ConnectMsg : TRspString
  175.       read Data.ConnectMsg write SetConnectMsg;
  176.     property BusyMsg : TRspString
  177.       read Data.BusyMsg write SetBusyMsg;
  178.     property VoiceMsg : TRspString
  179.       read Data.VoiceMsg write SetVoiceMsg;
  180.     property NoCarrierMsg : TRspString
  181.       read Data.NoCarrierMsg write SetNoCarrierMsg;
  182.     property NoDialToneMsg : TRspString
  183.       read Data.NoDialToneMsg write SetNoDialToneMsg;
  184.     property ErrorMsg : TRspString
  185.       read Data.ErrorMsg write SetErrorMsg;
  186.     property RingMsg : TRspString
  187.       read Data.RingMsg write SetRingMsg;
  188.     property LockDTE : Boolean
  189.       read Data.LockDTE write SetLockDTE;
  190.     property DialTimeout : Word
  191.       read FDialTimeout write SetDialTimeout default DefDialTimeout;
  192.     property AnswerTimeout : Word
  193.       read FAnswerTimeout write SetAnswerTimeout default DefAnswerTimeout;
  194.     property DelayFactor : Word
  195.       read FDelayFactor write SetDelayFactor default DefDelayFactor;
  196.     property CmdTimeout : Word
  197.       read FCmdTimeout write SetCmdTimeout default DefCmdTimeout;
  198.     property DTRDropHold : Word
  199.       read FDTRDropHold write SetDTRDropHold default DefDTRDropHold;
  200.     property CharDelay : Word
  201.       read FCharDelay write SetCharDelay default DefModemCharDelay;
  202.     property TildeDelay : Word
  203.       read FTildeDelay write SetTildeDelay default DefTildeDelay;
  204.     property RingWaitTimeout : Word
  205.       read FRingWaitTimeout write SetRingWaitTimeout default DefRingWaitTimeout;
  206.  
  207.     {events}
  208.     property OnModemOk : TNotifyEvent
  209.       read FModemOk write FModemOk;
  210.     property OnModemConnect : TNotifyEvent
  211.       read FModemConnect write FModemConnect;
  212.     property OnModemBusy : TNotifyEvent
  213.       read FModemBusy write FModemBusy;
  214.     property OnModemVoice : TNotifyEvent
  215.       read FModemVoice write FModemVoice;
  216.     property OnModemNoCarrier : TNotifyEvent
  217.       read FModemNoCarrier write FModemNoCarrier;
  218.     property OnModemNoDialTone : TNotifyEvent
  219.       read FModemNoDialTone write FModemNoDialTone;
  220.     property OnModemError : TNotifyEvent
  221.       read FModemError write FModemError;
  222.     property OnGotLineSpeed : TLineSpeedEvent
  223.       read FGotLineSpeed write FGotLineSpeed;
  224.     property OnGotErrCorrection : TNotifyEvent
  225.       read FGotErrCorrection write FGotErrCorrection;
  226.     property OnGotDataCompression : TNotifyEvent
  227.       read FGotDataCompression write FGotDataCompression;
  228.     property OnCmdTimedOut : TNotifyEvent
  229.       read FCmdTimedOut write FCmdTimedOut;
  230.     property OnDialTimedOut : TNotifyEvent
  231.       read FDialTimedOut write FDialTimedOut;
  232.     property OnAnswerTimedOut : TNotifyEvent
  233.       read FAnswerTimedOut write FAnswerTimedOut;
  234.     property OnDialCount : TConnectCountEvent
  235.       read FDialCount write FDialCount;
  236.     property OnAnswerCount : TConnectCountEvent
  237.       read FAnswerCount write FAnswerCount;
  238.  
  239.   public
  240.     {creation/destruction}
  241.     constructor Create(AOwner : TComponent); override;
  242.     destructor Destroy; override;
  243.  
  244.     property Started : Boolean
  245.       read FStarted write SetStarted;
  246.     property ModemInfo : TModemInfo
  247.       read Data write SetModemInfo;
  248.  
  249.     procedure Initialize;
  250.       {-Send the initialization string to the modem}
  251.     procedure Configure;
  252.       {-Send the configuration strings to the modem}
  253.     procedure Dial(const Number : String);
  254.       {-Dial the modem}
  255.     function IsAttemptingConnect : Boolean;
  256.       {-Return TRUE if the modem is attempting to establish a connection}
  257.     procedure ExtendConnectAttempt(DeltaSecs : Integer);
  258.       {-Extend the amount of time the modem waits for a CONNECT result}
  259.     procedure CancelDialAnswer;
  260.       {-Cancel the dial/answer in progress}
  261.     function GetConnectSpeed : LongInt;
  262.       {-Get the actual speed of the connection}
  263.     procedure Hangup;
  264.       {-Hangup the modem}
  265.     procedure Answer;
  266.       {-Answer the modem}
  267.     procedure AutoAnswer(Rings : Word);
  268.       {-Answer the modem after Rings rings}
  269.     function FeatureWaitOver : Boolean;
  270.       {-Return TRUE if all modem features have been received and processed}
  271.     procedure WaitOnFeatures;
  272.       {-Wait until all modem features have been received}
  273.     procedure WaitOnResponse;
  274.       {-Wait until the modem finishes processing the last command}
  275.   end;
  276.  
  277.   TModem = class(TCustomModem)
  278.   published
  279.     {com port this is linked to}
  280.     property ComPort;
  281.  
  282.     {commands, timeouts, etc.}
  283.     property InitCmd;
  284.     property DialCmd;
  285.     property DialTerm;
  286.     property DialCancel;
  287.     property HangupCmd;
  288.     property ConfigCmd;
  289.     property AnswerCmd;
  290.     property OkMsg;
  291.     property ConnectMsg;
  292.     property BusyMsg;
  293.     property VoiceMsg;
  294.     property NoCarrierMsg;
  295.     property NoDialToneMsg;
  296.     property ErrorMsg;
  297.     property RingMsg;
  298.     property LockDTE;
  299.     property DialTimeout;
  300.     property AnswerTimeout;
  301.     property DelayFactor;
  302.     property CmdTimeout;
  303.     property DTRDropHold;
  304.     property CharDelay;
  305.     property TildeDelay;
  306.     property RingWaitTimeout;
  307.  
  308.     {events}
  309.     property OnModemOk;
  310.     property OnModemConnect;
  311.     property OnModemBusy;
  312.     property OnModemVoice;
  313.     property OnModemNoCarrier;
  314.     property OnModemNoDialTone;
  315.     property OnModemError;
  316.     property OnGotLineSpeed;
  317.     property OnGotErrCorrection;
  318.     property OnGotDataCompression;
  319.     property OnCmdTimedOut;
  320.     property OnDialTimedOut;
  321.     property OnAnswerTimedOut;
  322.     property OnDialCount;
  323.     property OnAnswerCount;
  324.   end;
  325.  
  326. const
  327.   DefModeData : TModemInfo =
  328.     ( Name          : '';
  329.       InitCmd       : 'ATZ^M';
  330.       DialCmd       : 'ATDT';
  331.       DialTerm      : '^M';
  332.       DialCancel    : '^M';
  333.       HangupCmd     : '+++~~~ATH0^M';
  334.       ConfigCmd     : 'ATE1Q0X1V1^M';
  335.       AnswerCmd     : 'ATA^M';
  336.       OkMsg         : 'OK';
  337.       ConnectMsg    : 'CONNECT';
  338.       BusyMsg       : 'BUSY';
  339.       VoiceMsg      : 'VOICE';
  340.       NoCarrierMsg  : 'NO CARRIER';
  341.       NoDialToneMsg : 'NO DIALTONE';
  342.       ErrorMsg      : 'ERROR';
  343.       RingMsg       : 'RING';
  344.       NumErrors     : 0;
  345.       Errors        : ('', '', '', '', '');
  346.       NumComps      : 0;
  347.       Compression   : ('', '', '', '', '');
  348.       LockDTE       : True;
  349.       DefBaud       : 19200
  350.     );
  351.  
  352.