hmmm ... hab es jetzt an meine Werte so wie ich denke das es Richtig ist angepasst. Es kommt keine Fehlermeldung aber es kommt auch kein Wert =(
Hab nachdem Edits und Memo nicht gingen Listbox reingemacht (obwohl das doch eigentlich egal ist).
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
PortInc, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
ListBox1: TListBox;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
y_wert : Real;
n_wert : Integer;
ReadStep : Int64;
implementation
{$R *.lfm}
{------------------------------------------------------------------------------}
function StrToFloat2(ValStr : String) : extended;
var
ValRea : extended;
i,Inf : Integer;
STX : String;
begin
STX := '';
for i := 1 to Length(ValStr) do
begin
if Copy(ValStr,i,1) = ',' then STX := STX + '.';
if Copy(ValStr,i,1) = '.' then STX := STX + '.';
if Copy(ValStr,i,1) = '+' then STX := STX + '+';
if Copy(ValStr,i,1) = '-' then STX := STX + '+';
if Copy(ValStr,i,1) = '1' then STX := STX + '1';
if Copy(ValStr,i,1) = '2' then STX := STX + '2';
if Copy(ValStr,i,1) = '3' then STX := STX + '3';
if Copy(ValStr,i,1) = '4' then STX := STX + '4';
if Copy(ValStr,i,1) = '5' then STX := STX + '5';
if Copy(ValStr,i,1) = '6' then STX := STX + '6';
if Copy(ValStr,i,1) = '7' then STX := STX + '7';
if Copy(ValStr,i,1) = '8' then STX := STX + '8';
if Copy(ValStr,i,1) = '9' then STX := STX + '9';
if Copy(ValStr,i,1) = '0' then STX := STX + '0';
if Copy(ValStr,i,1) = 'e' then STX := STX + 'e';
if Copy(ValStr,i,1) = 'E' then STX := STX + 'e';
end;
Val(STX, ValRea, Inf);
if Inf = 0 then StrToFloat2 := ValRea else StrToFloat2 := 0;
end;
{------------------------------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenCom(pchar('com' + Edit1.Text + ':9600,N,8,1'));
{Messgerät - INIT}
SendByte (4);
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('s'));
SendByte (ord('r'));
SendByte (2);
SendByte (ord('i'));
SendByte (ord('n'));
SendByte (ord('i'));
SendByte (ord('t'));
SendByte (10);
SendByte (3);
ReadByte;
end;
{------------------------------------------------------------------------------}
function ReadValue () : extended;
var i : Integer;
inB : Integer;
inW : String;
begin
SendByte (4);
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('s'));
SendByte (ord('r'));
SendByte (2);
SendByte (ord('f'));
SendByte (ord('e'));
SendByte (ord('t'));
SendByte (ord('c'));
SendByte (ord('?'));
SendByte (10);
SendByte (3);
ReadByte;
SendByte (4);
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('0'));
SendByte (ord('p'));
SendByte (ord('o'));
SendByte (5);
ReadByte;
inW:='';
i:=0;
repeat
inc(i);
inB:=ReadByte;
inW:=inW+chr(inB);
until (inB=13) or (i>20);
ReadByte;
ReadByte;
y_wert:=StrToFloat2(inW)*1000;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var Value: real;
begin
Value := y_wert;
if Value = 0 then
ReadStep := 0
else
begin
Inc(ReadStep);
if ReadStep = 3 then
begin
ListBox1.Items.Add(FloatToStr(Value));
Beep;
end;
end;
end;
{------------------------------------------------------------------------------}
end.