unit uMain;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, CPort,
Vcl.StdCtrls;
type
TfrmMain =
class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
ComPort: TComPort;
procedure ComPortRxChar(Sender: TObject; Count: Integer);
end;
var
frmMain: TfrmMain;
Buffer:
PACKED ARRAY[0..1]
OF Byte;
implementation
{$R *.dfm}
procedure TfrmMain.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
ComPort.Close;
ComPort.Free;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
ComPort := TComPort.Create(
Nil);
ComPort.OnRxChar := ComPortRxChar;
ComPort.Port := '
COM1';
ComPort.BaudRate := br9600;
ComPort.Parity.Bits := prNone;
ComPort.DataBits := dbEight;
ComPort.StopBits := sbOneStopBit;
ComPort.Open;
end;
procedure TfrmMain.Button1Click(Sender: TObject);
begin
Buffer[0]:= $06;
Buffer[1]:= $13;
ComPort.
Write(Buffer, SizeOf(Buffer));
end;
procedure TfrmMain.ComPortRxChar(Sender: TObject; Count: Integer);
var
A:
String;
begin
ComPort.ReadStr(A, Count);
memo1.Text := memo1.Text + '
Daten: ' + A + #13#10;
end;
end.