var
Form1: TForm1;
lista: TStringList; implementation
{$R *.DFM} //sair do programa// procedure TForm1.BitBtn1Click(Sender: TObject); begin
Close; end; //conecta e desconecta a comunicação// procedure TForm1.BitBtn2Click(Sender: TObject); begin if BitBtn2.Caption = 'Conectar' then begin
BitBtn2.Caption := 'Desconectar';
sp1.OpenPort(sp1.CommPort);
BitBtn3.Enabled:=false;
BitBtn4.Enabled:=false;
timer1.Enabled := true; end else begin
BitBtn2.Caption := 'Conectar';
timer1.Enabled := false;
BitBtn3.Enabled:=true;
BitBtn4.Enabled:=true;
sp1.ClosePort(); end; end; // efetua leituras function TForm1.leitura(Sender: TObject): integer; var st:string;
p: word; begin
st := sp1.GetData;
memo1.Lines.Add('<'+st+'>'); //memo1.lines.add(st) if(pos(#9,st)>0)then begin
p:= pos('C1',st); if (p>0) then begin
result:=strtoint(copy(st,p+3,4)); end; end; end;
procedure TForm1.Timer1Timer(Sender: TObject); var volts:real; begin if (Lmax<>Lmin)then begin
volts:= Vmin+(vmax-Vmin)*(Leitura(Sender)-Lmin)/(Lmax-Lmin);
label1.caption:=format('%4.2fV',[volts]); end else begin
BitBtn2Click(sender);
ShowMessage('Erro de Calibração! Favor recalibrar');//Label1.caption:='Erro'// end; end; //calibração em valores minimos procedure TForm1.BitBtn3Click(Sender: TObject); var soma:real;
i:word; begin
soma:=0; for i:= 1 to 10 do begin
soma:=soma+Leitura(sender); end;
SetLmin(soma/10);
SetVmin (strtofloat(Edit1.Text));
label7.caption:=(floattostr(Lmin)); end;
procedure TForm1.SetLmax(const Value: real); begin
FLmax := Value; end;
procedure TForm1.SetLmin(const Value: real); begin
FLmin := Value; end;
procedure TForm1.SetVmax(const Value: real); begin
FVmax := Value; end;
procedure TForm1.SetVmin(const Value: real); begin
FVmin := Value; end; //calibração de valores maximo procedure TForm1.BitBtn4Click(Sender: TObject); var soma:real;
i:word; begin
soma:=0; for i:= 1 to 10 do begin
soma:=soma+Leitura(sender); end;
SetLmax(soma/10);
SetVmax (strtofloat(Edit2.Text));
label8.caption:=(floattostr(Lmax)); end;
procedure TForm1.FormShow(Sender: TObject); begin
Lista:=TStringlist.create; if FileExists('calibração.txt')then begin
Lista.LoadFromFile('calibração.txt');
Vmin := strtofloat(Lista[0]);
Lmin := strtofloat(Lista[1]);
Vmax := strtofloat(Lista[2]);
Lmax := strtofloat(Lista[3]);
Edit1.Text:=Floattostr(Vmin);
Edit2.Text:=Floattostr(Vmax);
Label7.caption:=Floattostr(Lmin);
Label8.caption:=Floattostr(Lmax);
end else Showmessage('arquivo de calibração não encontrado favor recalibrar');
Lista.Destroy; end;