unit uMeasureDianzhu;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uMeasureBase, dxExEdtr, SPComm, ADODB, DB, ExtCtrls, dxBar,
  dxBarExtItems, ImgList, StdCtrls, MPlayer, dxTL, dxCntner,uFunMesClient;

type
  TfrmMeasureDianzhu = class(TfrmMeasureBase)
    TimSenderOrder: TTimer;
    procedure edtNumKeyPress(Sender: TObject; var Key: Char);
    procedure TimSenderOrderTimer(Sender: TObject);
    procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
  private
    Canrec: Boolean;
    procedure SendString(const str: string);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMeasureDianzhu: TfrmMeasureDianzhu;

implementation

uses PublicDBUnit;

{$R *.dfm}

procedure TfrmMeasureDianzhu.edtNumKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key = #13 then
  begin
    meNum := StrToFloat(edtNum.Text) ;
    if (meNum > MyWork.MaxNum)or (meNum < MyWork.MinNum) then
    begin
      ImgRed.Visible := true   ;
      ImgGreen.Visible := false ;
      edtNum.text := '';
    end
    else
    begin
      ImgRed.Visible := false   ;
      ImgGreen.Visible := true ;
      moCurRout.SetFocus ;
    end;
  end;
end;

procedure TfrmMeasureDianzhu.SendString(const str: string);
begin
  Comm1.WriteCommData(Pchar(str),Length(str));
end;

procedure TfrmMeasureDianzhu.TimSenderOrderTimer(Sender: TObject);
begin
  SendString('?'+#10);
end;

procedure TfrmMeasureDianzhu.Comm1ReceiveData(Sender: TObject;
  Buffer: Pointer; BufferLength: Word);
var
  C_num : real;
  str :string;
begin
  ImageOff.Visible  := false ;
  ImageOn.Visible   := true ;
  if edtCode.Text = '' then Exit;

  SetLength(Str,BufferLength);
  move(buffer^,pchar(@Str[1])^,bufferlength);
  C_num := Getdianzhu(str) ;
  if meNum <> C_num then
  begin
    ImgYel.Visible := not ImgYel.Visible ;
    meNum := C_num ;
    Exit;
  end;
  if (meNum > MyWork.MaxNum)or (meNum < MyWork.MinNum) then
  begin
    ImgRed.Visible := true   ;
    ImgGreen.Visible := false ;
  end
  else
  begin
    ImgRed.Visible := false   ;
    ImgGreen.Visible := true ;
  end;
  edtNum.Text := FloatToStr(meNum)+ '¦¸' ;




end;

end.
