Thursday, November 26, 2015

Program konversi RTD dengan delphi

Program Konversi sensor RTD PT-100 dengan DELPHI









kali ini akan saya bagikan listing program software konversi ini, agar pembaca bisa mengembangkan software ini terus dan terus.

program yang saya gunakan adalah delphi 7 dengan menggunakan database access yang mudah - mudah saja. kebetulan kemampuan programming saya cuma pas - pas tapi saya tulis dengan sepenuh hati kok.

berikut adalah listingnya :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBXpress, FMTBcd, Grids, DBGrids, DB, DBClient, Provider,
  SqlExpr, StdCtrls, Mask, DBCtrls,math, ADODB, jpeg, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Edit3: TEdit;
    Button4: TButton;
    Edit4: TEdit;
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    img1: TImage;
    img2: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  temp1,temp2 : string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
    perintah : string;
begin
temp1:= 'pt100';
temp2:= 'Ohm';
ADOConnection1.Connected:=true;
ADOQuery1.SQL.Text:= 'select * from '+ temp1;
ADOQuery1.Active:= true;
datasource1.Enabled:= true;
dbedit1.DataField:= 'temp';
dbedit2.DataField:= temp2;
perintah:= 'select * from ' + temp1 +' order by '+ temp2 +' asc';
ADOQuery1.SQL.Text:= perintah;
ADOQuery1.Active:= true;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    perintah : string;
    r,s,t,data1,data2: real;
begin
r:= strtofloat(edit1.text);
s:= RoundTo(r,0);
t:= s - r;
if (r > 0) and (t > 0) then s:= s - 1 else  s:= s;   {untuk nilai plus}
if (r < 0) and (t < 0) then s:= s + 1 else  s:= s;   {untuk nilai minus}
if (r > 0) and (t > 0) then
  begin
    perintah:= 'select * from '+ temp1 +' where temp =' + floattostr(s + 1);
 adoquery1.SQL.Text:= perintah;
    ADOQuery1.Active:= true;
 data1:= strtofloat(dbedit2.Text);
 perintah:= 'select * from '+ temp1 +' where temp =' + floattostr(s);
 adoquery1.SQL.Text:= perintah;
 ADOQuery1.Active:= true;
 data2:= strtofloat(dbedit2.Text);
 t:= data2 + (data1 - data2)*(r - s);
 edit2.Text:= floattostr(t);
  end
 else
   begin
     perintah:= 'select * from '+ temp1 +' where temp =' + floattostr(s);
  adoquery1.SQL.Text:= perintah;
     ADOQuery1.Active:= true;
  data1:= strtofloat(dbedit2.Text);
  perintah:= 'select * from '+ temp1 +' where temp =' + floattostr(s - 1);
  adoquery1.SQL.Text:= perintah;
  ADOQuery1.Active:= true;
  data2:= strtofloat(dbedit2.Text);
  t:= data2 + (data1 - data2)*(1 - (s - r));
  edit2.Text:= floattostr(t);
   end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
    perintah : string;
    r,s,t,data1,data2,data3,data4: real;
    count1,i: integer;
begin
r:= strtofloat(edit3.text);
s:= RoundTo(r,0);
t:= s - r;
if t > 0 then s:= s - 1 else  s:= s;
perintah:= 'select * from '+ temp1 +' where '+ temp2 +' between ' + floattostr(s-1) + ' and ' + floattostr(s + 1) +' order by '+ temp2 +' asc';
adoquery1.SQL.Text:= perintah;
ADOQuery1.Active:= true;
count1:= datasource1.DataSet.RecordCount;
if count1 = 0 then application.MessageBox('Data yang anda cari tidak ditemukan','Kesalahan',mb_OK+MB_Iconstop);
if count1 = 1 then edit4.Text:= dbedit2.text
else
begin
adoquery1.First;
for i:=0 to count1 - 1 do
 begin
   t:= strtofloat(dbedit2.text);
   t:= r - t;
   if t < 0 then
     begin
       data3:= strtofloat(dbedit2.text);
       data1:= strtofloat(dbedit1.text);
       adoquery1.Prior;
       data4:= strtofloat(dbedit2.text);
       data2:= strtofloat(dbedit1.text);
     end;
   adoquery1.Next;
 end;
t:= (((r - data4)/(data3 - data4)) + data2);
t:= RoundTo(t,-2);
edit4.Text:= floattostr(t);
end;
end;

end.


Saya sediakan juga file programnya jadi biar tidak kawatir kalau tidak jalan hehehe...

siip klik aja link di samping :   file listing dan programnya



No comments:

Post a Comment