unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SPComm;
type
TForm1 = class(TForm)
Comm1: TComm;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
procedure Comm1ReceiveError(Sender: TObject; EventMask: Cardinal);
private
sBuf,rBuf:array[1..16] of byte;
sBuffer
ointer;
sBufferLength:Word;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
comm1.StartComm;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
self.Comm1.StopComm;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
sBuf[1]:=byte($68);
sBuf[2]:=byte($03);
sBuf[3]:=byte($03);
sBuf[4]:=byte($68);
sBuf[5]:=byte($72);
sBuf[6]:=byte($13);
sBuf[7]:=byte($05);
sBuf[8]:=byte($8a);
sBuf[9]:=byte($0d);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
vie:string;
begin
vie:='';
for i:=1 to 9 do
begin
caption:='正在发送'+inttostr(i);
if not self.Comm1.WriteCommData(@sBuf
,1) then
begin
showmessage('err');
break;
end;
vie:=vie+inttohex(sbuf,2)+' ';
sleep(2);
end;
memo1.Lines.Add(vie);
if self.Comm1.SendDataEmpty then
showmessage('发送为');
//self.Comm1.
end;
procedure TForm1.Button4Click(Sender: TObject);
var
strReceive:string;
begin
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
{var
strReceive:string;
begin
SetLength(strReceive,BufferLength);
Move(Buffer^,PChar(StrReceive)^,BufferLength);
Memo1.Lines.Add(strReceive);
} var
i:integer;
strReceive:string;
begin
strReceive:='';
move(buffer^,pchar(@rbuf)^,bufferlength);
for i:=1 to bufferlength do
strReceive:=strReceive+inttohex(rbuf,2)+' ';
strReceive:='接收:=>'+strReceive+' ';
memo1.lines.add(strReceive);
memo1.lines.add('');
end;
procedure TForm1.Comm1ReceiveError(Sender: TObject; EventMask: Cardinal);
begin
showmessage('err');
end;
end.