unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StatusBar1:TStatusBar;
    Panel1:TPanel;
    Label1:TLabel;
    Memo1:TMemo;
    Label2:TLabel;
    Memo2:TMemo;
    nrComm1:TnrComm;
    nrDeviceBox1:TnrDeviceBox;
    nrLogFile1:TnrLogFile;
    Label3:TLabel;
    nrZModem1:TnrZModem;
    GroupBox1:TGroupBox;
    ProgressBar1:TProgressBar;
    Label4:TLabel;
    Label5:TLabel;
    Edit1:TEdit;
    Label6:TLabel;
    Button1:TButton;
    OpenDialog1:TOpenDialog;
    chkReceive:TCheckBox;
    chkActive:TCheckBox;
    bSend:TButton;
    bBreak:TButton;
    Button2:TButton;
    ImageList1:TImageList;
    nrSemaphore1:TnrSemaphore;
    nrSemaphore2:TnrSemaphore;
    nrSemaphore3:TnrSemaphore;
    nrSemaphore4:TnrSemaphore;
    procedure chkActiveClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure bBreakClick(Sender: TObject);
    procedure bSendClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure chkReceiveClick(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);
  private    { Private declarations }
    procedure WMDeviceChange(var Msg:TMessage); message WM_DEVICECHANGE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.chkActiveClick(Sender: TObject);
begin
  nrComm1.Active:=chkActive.Checked;
  bSend.Enabled:=nrComm1.Active;
  bBreak.Enabled:=False;
end;

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

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

procedure TForm1.bBreakClick(Sender: TObject);
begin
  Label5.Caption:='Aborted';
  nrZModem1.Abort;
  bBreak.Enabled:=false;
end;

procedure TForm1.bSendClick(Sender: TObject);
begin
  Label5.Caption:='Sending ...';
  nrZModem1.Send(Edit1.Text);
  bSend.Enabled:=False;
  bBreak.Enabled:=True;
  Label4.Caption:=nrZModem1.FileName;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  nrComm1.ConfigDialog;
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.WMDeviceChange(var Msg: TMessage);
begin
  nrComm1.Update;
end;

end.
