unit Steuerung;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Cport, StdCtrls;
type
TForm2 =
class(TForm)
Edit1: TEdit;
Label1: TLabel;
connbutton: TButton;
portbutton: TButton;
Button3: TButton;
ComPort: TComPort;
Button1: TButton;
Memo1: TMemo;
CheckBox1: TCheckBox;
Edit2: TEdit;
Label2: TLabel;
Button2: TButton;
Button4: TButton;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ComPortAfterOpen(Sender: TObject);
procedure ComPortAfterClose(Sender: TObject);
procedure portbuttonClick(Sender: TObject);
procedure connbuttonClick(Sender: TObject);
procedure ComPortRxFlag(Sender: TObject);
procedure wertrausfiltern(
var bote:
string);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
botschaft:
string;
eve:
string; evec:char; los:boolean;
laenge:integer;
implementation
{$R *.dfm}
procedure TForm2.ComPortRxFlag(Sender: TObject);
var tat:integer;
begin
comport.ReadStr(botschaft,1);
if botschaft= evec
then los:=true;
if los=true
then begin
comport.ReadStr(botschaft,laenge);
Memo1.Lines.Add(botschaft);
end;
end;
procedure TForm2.wertrausfiltern(
var bote:
string);
//var i,v:integer;
begin
//i:=0;
//v:=0;
//repeat i:=i + 1 until bote[i] = chr(15);
//Showmessage(bote[i]+ bote[i+1]);
//if i<>1 then delete(bote,1,i);
//i:=0;
//repeat i:=i + 1 until ((bote[i] = evec) or (i=length(bote))) ;
//Showmessage(bote[i]+ bote[i+1]);
//Delete(bote,i,length(bote));
end;
procedure TForm2.ConnButtonClick(Sender: TObject);
begin
Comport.Connected :=
not comport.Connected;
los:=false;
botschaft:='
';
Memo1.Lines.Add('
---STOP---');
end;
procedure TForm2.ComPortAfterOpen(Sender: TObject);
begin
ConnButton.Caption := '
Disconnect';
end;
procedure TForm2.ComPortAfterClose(Sender: TObject);
begin
ConnButton.Caption := '
Connect';
end;
procedure TForm2.PortButtonClick(Sender: TObject);
begin
ComPort.ShowSetupDialog;
end;
procedure TForm2.Button3Click(Sender: TObject);
//übernehmen button vom Eventchar
begin
if checkbox1.Checked =false
then begin
if length(Edit1.Text)>0
then begin
eve:=Edit1.Text;
evec:= eve[1];
comport.eventchar:= evec;
end;
end
else
if length(Edit1.Text)=2
then begin
eve:=Edit1.Text;
evec:= chr(strtoint(eve));
comport.eventchar:= evec;
end;
edit1.Text := evec;
end;
procedure TForm2.Button2Click(Sender: TObject);
//übernehmen button von länge
begin
if Edit2.Text <> '
'
then laenge :=strtoint(Edit2.Text);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
comport.eventchar:= #15;
evec:=#15;
laenge:= 16;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm2.Button4Click(Sender: TObject);
begin
Memo1.Clear;
end;
end.