unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Label6: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Label7: TLabel;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button3Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses I7000,I7000u;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
   wRetVal,wT,wChkSum :Word;
   szStr :String ;

begin

     Button1.enabled := False;
     StrCopy( gszSend, PChar(Edit4.text) );
     szStr := Edit7.Text ;
     wChkSum := StrToInt(szStr);
     //wRetVal := Send_Cmd(gcPort,gszSend,Word(10000), wChkSum );
     //wRetVal := Read_Com_Status(gcPort,gszReceive,wT);

     wRetVal := send_Receive_Cmd(gcPort, gszSend,gszReceive,200, wChkSum,wT);
     Edit6.text := IntToStr(wRetVal);

     Edit5.text := gszReceive;
     Application.ProcessMessages;

     Button1.enabled := True;
     Edit5.text := gszReceive;
end;


procedure TForm1.Button2Click(Sender: TObject);
Var
    wRetVal:Word;
begin
     gcPort := Char(StrToInt(Edit1.text));
     gdwBaudRate := StrToInt(Edit2.text);
     wRetVal := IOpenCom(gcPort,gdwBaudRate);
     Edit3.text := IntToStr(wRetVal);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     gszSend    := StrAlloc(128);
     gszReceive := StrAlloc(128);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     StrDispose( gszSend    );
     StrDispose( gszReceive );
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
     Close_Com(gcPort);
     Close;           
end;

end.
