unit comterm;

{$mode objfpc}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, ExtCtrls
  , LCLType
  ,header_utils;

type

  { TComTermForm }

  TComTermForm = class(TForm)
    SendButton: TButton;
    ResetButton: TButton;
    ClearButton: TButton;
    InputEdit: TEdit;
    Label1: TLabel;
    InputMemo: TMemo;
    OutputMemo: TMemo;
    procedure ClearButtonClick(Sender: TObject);
    procedure InputEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure InputMemoChange(Sender: TObject);
    procedure OutputMemoChange(Sender: TObject);
    procedure ResetButtonClick(Sender: TObject);
    procedure SendButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  ComTermForm: TComTermForm;

implementation

{ TComTermForm }
procedure TComTermForm.InputEditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If (Key=VK_RETURN) then begin //remember to add LCLType in uses
  SendButtonClick(nil);
  Key:=0;
  end;
end;

procedure TComTermForm.InputMemoChange(Sender: TObject);
begin
    InputMemo.SelStart := MaxInt; //Always show last entry
end;

procedure TComTermForm.OutputMemoChange(Sender: TObject);
begin
  OutputMemo.SelStart := MaxInt; //Always show last entry
end;

procedure TComTermForm.ResetButtonClick(Sender: TObject);
begin
     StatusMessage('Send reset command.');
     sendget(chr($19),False,1,False);
     OutputMemo.Append('Sent 0x19 to reset the meter.');
end;

procedure TComTermForm.SendButtonClick(Sender: TObject);
begin
  InputMemo.Append(InputEdit.Text);
  OutputMemo.Append(SendGet(InputEdit.Text));
end;

procedure TComTermForm.ClearButtonClick(Sender: TObject);
begin
  OutputMemo.Clear;
  InputMemo.Clear;
  InputEdit.Clear;
  InputEdit.SetFocus;
end;

initialization
  {$I comterm.lrs}

end.

