unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, nrcommbox, nrclasses, nrcomm;

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    nrComm1: TnrComm;
    nrDeviceBox1: TnrDeviceBox;
    Button1: TButton;
    GroupBox1: TGroupBox;
    lCts: TLabel;
    lDsr: TLabel;
    lRlsd: TLabel;
    lRing: TLabel;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    Memo1: TMemo;
    Memo2: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    procedure CheckBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure nrComm1TraceState(Com: TObject; Event: TTraceStates);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  try
    nrComm1.Active := CheckBox1.Checked;
  except
    CheckBox1.Checked := nrComm1.Active;
    raise;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  nrComm1.ConfigDialog;
end;

procedure TForm1.nrComm1TraceState(Com: TObject; Event: TTraceStates);
var ms : TModemSignals;
    s:string;
begin
  s := '[';
  ms := nrComm1.ModemSignals;
  lCts.Enabled :=  msCTS in ms;
  if lCts.Enabled then s := ' CTS';
  lDsr.Enabled :=  msDSR in ms;
  if lDsr.Enabled then s := s + ' DSR';
  lRlsd.Enabled := msRLSD in ms;
  if lRlsd.Enabled then s := s + ' Rlsd';
  lRing.Enabled := msRing in ms;
  s := s + ' ]';
  Memo2.Lines.Add(s);
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  nrComm1.SetStateDTR(CheckBox2.Checked);
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  nrComm1.SetStateRTS(CheckBox3.Checked);
end;

end.
