procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var strRecv:string;
begin
setlength(strRecv,BufferLength);
move(buffer^,pchar(strRecv)^,Bufferlength);
memo1.Lines.Add('已收到:'+intTostr(Bufferlength)+'字节的数据');
memo1.Lines.Add('s:'+strRecv);
Memo1.Invalidate;
end;
BufferLength: Word);
var strRecv:string;
begin
setlength(strRecv,BufferLength);
move(buffer^,pchar(strRecv)^,Bufferlength);
memo1.Lines.Add('已收到:'+intTostr(Bufferlength)+'字节的数据');
memo1.Lines.Add('s:'+strRecv);
Memo1.Invalidate;
end;
关于delphi中串口通讯控件的选择
mscomm:微软的东西,ActivX控件,使用简单,在VB中带的,性能一般,由于是ActivX控件,打包时需要注册好多信息,不推荐使用。
spcomm:比较好的vcl,算是比较专业的,解剖了一下,功能比较完善。
TurboPower:公认的专业通讯控件。可以到其站点下载,开放源码了。
我在制作串口通讯软件时三种都用过,最终全部使用TurboPower!所以也推荐大家使用它。
写了个例子,基本的串口通讯都可以实现,可提供参考。
下载地址:http://www.kaer.cn/default.aspx(网站安全性较差,经常当机,如果急用,mail我)
多多指正:[email protected]
BufferLength: Word);
var p:pchar
j:integer
s:string
begin
s:='';
p:=Buffer;
for j:=0 to Bufferlength-1 do
s := s + Format ('%0.2x ', [ord((p+j)^)]);
end
有SPCOMM的例子,可以参考一下