unit uTestAntenna;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Registry, Vcl.StdCtrls, JvExControls, JvDialButton, JvArrayButton,
  Vcl.ExtCtrls, JvExStdCtrls,
  JvShapedButton, Vcl.CategoryButtons, Vcl.ButtonGroup, VrControls, VrDesign, JvExExtCtrls, JvRadioGroup,
  JvRadioButton, _GClass, AbLED, nrclasses, nrcomm, ComCtrls, nrcommbox,
  NMCLibI04;

type
  TForm9 = class(TForm)
    btnNmcInit: TButton;
    btnSimpleMessageBox: TButton;
    btnErrorBox: TButton;
    btnErrorPrintingOff: TButton;
    btnErrorPrintingON: TButton;
    btnNmcShutdown: TButton;
    btnNoOp: TButton;
    ledInit: TAbLED;
    btnTestDLL: TButton;
    nrDeviceBox1: TnrDeviceBox;
    nrComm1: TnrComm;
    btnSerialConfig: TButton;
    lvProperties: TListView;
    ledKerr: TAbLED;
    procedure FormCreate(Sender: TObject);
    procedure btnLoadDLLClick(Sender: TObject);
    procedure btnNmcInitClick(Sender: TObject);
    procedure btnSimpleMessageBoxClick(Sender: TObject);
    procedure btnErrorBoxClick(Sender: TObject);
    procedure btnErrorPrintingOffClick(Sender: TObject);
    procedure btnErrorPrintingONClick(Sender: TObject);
    procedure btnNmcShutdownClick(Sender: TObject);
    procedure btnNoOpClick(Sender: TObject);
    procedure nrDeviceBox1Change(Sender: TObject);
    procedure AddDeviceInfo(Dev: TnrDevice);
    procedure AddInfo(sCapt, sVal: string);
    procedure btnSerialConfigClick(Sender: TObject);
  private
    { Private declarations }

    resets: integer;
    dllHandle: cardinal;
    ComPortStr: string;
    function LoadComPort: boolean;
  public
    { Public declarations }

  end;

type
  TNmcInitFunc = function(ComPortStr: pAnsichar; baudrate: integer): integer; stdCall;

var
  Form9: TForm9;

implementation

uses math, uSETITypes;

{$R *.dfm}

procedure TForm9.btnNmcInitClick(Sender: TObject);
var
  nModules: integer;
  com: string;
  ndx: integer;
  res: boolean;
begin
  com := nrComm1.ComName;
  // If (NmcInit(nrComm1.ComName, nrComm1.baudrate) = 3) then
 If (NmcInit(Pointer(com) , nrComm1.baudrate) = 3) then

  begin
    ledInit.LED.ColorOn := clLime;
  end
  else
  begin
    ledInit.LED.ColorOff := clRed;
  end
end;

procedure TForm9.btnNmcShutdownClick(Sender: TObject);
begin
  ledInit.LED.ColorOff := clSilver;
  ledInit.Checked := false;
  NmcShutdown;

  ledKerr.Checked := false;
  ledKerr.Caption := 'Off';
end;

procedure TForm9.btnNoOpClick(Sender: TObject);
var
  res: boolean;
begin
  ErrorPrinting(0);
  res := NmcNoOp(byte(1));
  ShowMessage(' setNmcNoOp returned: ' + IntToStr(integer(res)));
end;

procedure TForm9.btnSerialConfigClick(Sender: TObject);
begin
  nrComm1.ConfigDialog;
end;

procedure TForm9.btnSimpleMessageBoxClick(Sender: TObject);
var
  PMsg: pAnsichar; // AnsiString;
  res: boolean;
  ReturnMessage: String;
  test: string;
begin
  test := 'test string test string sssssssss';
  SimpleMsgBox(test)

end;

procedure TForm9.btnErrorBoxClick(Sender: TObject);
var
  res: boolean;
  ReturnMessage: String;
begin

  ErrorMsgBox('Error Msg Box Example  .');
  ShowMessage('Error in MsgBox');
end;

procedure TForm9.btnErrorPrintingOffClick(Sender: TObject);

begin // TErrorPrintingProcedure = procedure(f: integer)stdcall; // 1=print,0=No Print
  ErrorPrinting(0); // 0 = Shut off error printing, 1 = Turn on error printing

end;

procedure TForm9.btnErrorPrintingONClick(Sender: TObject);
begin
  ErrorPrinting(1); // 0 = Shut off error printing, 1 = Turn on error printing
end;

procedure TForm9.btnLoadDLLClick(Sender: TObject);
var
  NmcInitFunc: TNmcInitFunc;
  nModules: integer;
begin

end;

procedure TForm9.FormCreate(Sender: TObject);
begin

  LoadComPort;
end;

function TForm9.LoadComPort: boolean;

begin

end;

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

procedure TForm9.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 TForm9.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;

end.
