unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    nrDeviceBox1: TnrDeviceBox;
    nrComm1: TnrComm;
    lvProperties: TListView;
    Label1: TLabel;
    CheckBox1: TCheckBox;
    procedure nrDeviceBox1Change(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private    { Private declarations }
    procedure AddInfo(sCapt, sVal: string);
  public     { Public declarations }
    procedure AddDeviceInfo(Dev:TnrDevice);
    procedure WMDeviceChange(var Msg:TMessage); message WM_DEVICECHANGE;      
  end;

var
  Form1: TForm1;

implementation
uses nrwin32di, nrwin32;

{$R *.dfm}

procedure TForm1.AddInfo(sCapt, sVal: string);
var Itm:TListItem;
begin
  if Trim(sVal) = '' then exit;
  with lvProperties do begin
    Itm := Items.Add;
    Itm.Caption := sCapt;
    Itm.SubItems.Add(sVal);
  end;
end;

procedure TForm1.AddDeviceInfo(Dev: TnrDevice);
begin
  if dev = nil then exit;
  AddInfo('DOS', dev.NameDeviceDos );
  AddInfo('Friendly Name', dev.NameFriendly);
  AddInfo('Description', dev.Description);
  //AddInfo('PDO', dev.NamePDO);
  AddInfo('Service', dev.Service);
  AddInfo('Manufacturer', dev.Manufacturer);
end;

procedure TForm1.nrDeviceBox1Change(Sender: TObject);
begin
  lvProperties.Items.Clear;
  AddDeviceInfo(nrComm1.Device[nrComm1.DeviceIndex]);
end;

procedure TForm1.WMDeviceChange(var Msg: TMessage);
var i:integer;
begin
  i := nrComm1.DeviceIndex;
  nrComm1.WMDeviceChange(Msg);
  nrComm1.DeviceIndex := i;
  nrDeviceBox1Change(Self);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  Screen.Cursor := crHourGlass;
  try

   if CheckBox1.Checked
     then nrComm1.EnumPorts := epFullPresent
     else nrComm1.EnumPorts := epFullInfo;

    nrComm1.Update;
    nrDeviceBox1.DroppedDown := True;
  finally
    Screen.Cursor := crDefault;
  end;
end;

end.
