unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CPort;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
ComPort7: TComPort;
Edit1: TEdit;
Memo1: TMemo;
Memo2: TMemo;
procedure FormActivate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComPort7RxChar(Sender: TObject; Count: Integer);
private
FInBuffer: AnsiString;
procedure InterPretInBuffer;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
hcomm : THandle;
COM_enum : integer;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
begin
ComPort7.Connected := true
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.ComPort7RxChar(Sender: TObject; Count: Integer);
var
s: AnsiString;
begin
ComPort7.ReadStr(s, Count);
FInBuffer := FInBuffer + s;
InterPretInbuffer;
end;
procedure TForm1 .InterpretInbuffer;
var
i:Integer;
part:AnsiString;
begin
i := Pos(#10,FInBuffer);
Memo1.Lines.Add(FInBuffer);
while i>0
do
begin
Part := Copy(FInBuffer,1,i-1);
FInBuffer := Copy(FInBuffer,i+1,Length(FInBuffer));
Memo2.Lines.Add(Part);
i := Pos(#10,FInBuffer);
end;
end;
end.