求助,spcomm控件接受单片机发送的数据,收不到数据,麻烦给看看哪出错了
程序很简单,只是接受单片机数据,显示啊memo1里。接受从单片机发送的数据,现在程序没有语法错误,就是接收不到数据,麻烦给看看哪错了。谢谢
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SPComm;
type
TForm1 = class(TForm)
Comm1: TComm;
Memo1: TMemo;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
viewstring: string;
i: integer;
rbuf:array[1..16] of byte;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
comm1.StartComm;
end;
//打开串口
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;
//关闭串口
procedure (Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
i: integer;
begin
move(buffer^, pchar(@rbuf)^, bufferlength);
for i:= 1 to bufferlength do
viewstring := viewstring+inttohex(rbuf[i], 2)+'';
viewstring := '接受' + viewstring;
memo1.Lines.Add(viewstring);
memo1.Lines.Add('');
end;
end.