unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, nrcommbox, nrlogfile, nrclasses, nrcomm, nrcommtapi, nrzmodem,
  nrsemaphore, ComCtrls, ExtCtrls, ImgList;

type
  TForm1 = class(TForm)
    StatusBar1:TStatusBar;
    Panel1:TPanel;
    Label1:TLabel;
    Memo1:TMemo;
    Label2:TLabel;
    Memo2:TMemo;
    nrDeviceBox1:TnrDeviceBox;
    nrLogFile1:TnrLogFile;
    Label3:TLabel;
    nrZModem1:TnrZModem;
    GroupBox1:TGroupBox;
    ProgressBar1:TProgressBar;
    Label4:TLabel;
    Label5:TLabel;
    OpenDialog1:TOpenDialog;
    chkReceive:TCheckBox;
    Button2:TButton;
    ImageList1:TImageList;
    nrCommTAPI1:TnrCommTAPI;
    Edit2:TEdit;
    Button3:TButton;
    CheckBox1:TCheckBox;
    GroupBox2:TGroupBox;
    bBreak:TButton;
    Button1:TButton;
    Edit1:TEdit;
    bSend:TButton;
    Label6:TLabel;
    Splitter1:TSplitter;
    Button4:TButton;
    Panel2:TPanel;
    nrSemaphore1:TnrSemaphore;
    nrSemaphore2:TnrSemaphore;
    nrSemaphore3:TnrSemaphore;
    nrSemaphore4:TnrSemaphore;
    Edit3:TEdit;
    Label7:TLabel;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure nrZModem1Abort(Sender: TObject; Error: TzAbortType);
    procedure nrZModem1AfterFileSend(Sender: TObject; FileName: String;
      flComplete: Boolean);
    procedure nrZModem1BeforeReceived(Sender: TObject;
      var FileName: String; var flSkip: Boolean);
    procedure nrZModem1Progress(Sender: TObject);
    procedure nrZModem1SuccessfulEnd(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure chkReceiveClick(Sender: TObject);
    procedure nrCommTAPI1LineConnected(Sender: TObject);
    procedure nrCommTAPI1LineDisconnected(Com: TObject; ByRemote: Boolean);
    procedure bSendClick(Sender: TObject);
    procedure bBreakClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure nrZModem1AfterFileReceived(Sender: TObject;
      FileName: String);
    procedure nrZModem1AfterFileSent(Sender: TObject; FileName: String;
      flComplete: Boolean);
  private
    { Private dec larations }
  public                       
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
begin
  nrCommTAPI1.DeviceConfigDialog;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  nrCommTAPI1.Phone:=Edit2.Text;
  nrCommTAPI1.Call;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Edit1.Text:=OpenDialog1.FileName;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  chkReceive.Checked:=nrZModem1.Active;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  nrCommTAPI1.HangUp;
end;

procedure TForm1.chkReceiveClick(Sender: TObject);
begin
   nrZModem1.Active:=chkReceive.Checked;
end;

procedure TForm1.nrZModem1Abort(Sender: TObject; Error: TzAbortType);
begin
  bSend.Enabled:=true;
end;

procedure TForm1.nrZModem1AfterFileSend(Sender: TObject; FileName: String;
  flComplete: Boolean);
begin
  Label5.Caption:='Ready';
  bSend.Enabled:=true;
end;

procedure TForm1.nrZModem1BeforeReceived(Sender: TObject;
  var FileName: String; var flSkip: Boolean);
begin
  Label5.Caption:='Receiving ...';
  Label4.Caption:=FileName;
  bSend.Enabled:=false;
end;

procedure TForm1.nrZModem1Progress(Sender: TObject);
begin
//
end;

procedure TForm1.nrZModem1SuccessfulEnd(Sender: TObject);
begin
  Label5.Caption:='Ready';
  bSend.Enabled:=true;
end;

procedure TForm1.nrCommTAPI1LineConnected(Sender: TObject);
begin
  bSend.Enabled:=True;
  chkReceive.Enabled:=True;
  bBreak.Enabled:=False;
end;

procedure TForm1.nrCommTAPI1LineDisconnected(Com: TObject;
  ByRemote: Boolean);
begin
  bSend.Enabled:=False;
  chkReceive.Enabled:=False;
  bBreak.Enabled:=False;
end;

procedure TForm1.bSendClick(Sender: TObject);
begin
  nrZModem1.Send(Edit1.Text);
  bBreak.Enabled:=True;
end;

procedure TForm1.bBreakClick(Sender: TObject);
begin
  bBreak.Enabled:=False;
  nrZModem1.Abort;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then begin
    nrCommTAPI1.RingsBeforeAnswer:=StrToInt(Edit3.Text);
    nrCommTAPI1.WaitForIncomingCall;
  end else nrCommTAPI1.HangUp;
end;

procedure TForm1.nrZModem1AfterFileReceived(Sender: TObject;
  FileName: String);
begin
  Memo2.Lines.Add('File '+FileName+' received.');
end;

procedure TForm1.nrZModem1AfterFileSent(Sender: TObject; FileName: String;
  flComplete: Boolean);
begin
  Memo2.Lines.Add('File '+FileName+' was sent.');
end;

end.
