//控件SPCOMM,到网上下载!下面例子delphi 6调试成功!接收十六进制
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls;
type
TForm1 = class(TForm)
Comm1: TComm;
Memo1: TMemo;
procedure FormCreate(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;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.startcomm;//创建窗体时,将comm1控件打开。
Memo1.Text := '';
end;
procedure TForm1.FormClose(Sender: TObject
var Action: TCloseAction);
begin
comm1.StopComm;//关闭窗体时,将comm1控件关闭。
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject
Buffer: Pointer;
BufferLength: Word);
var
BufferDate :array[0..512] of byte
//定义接收数组
i :integer;
begin
try
move(buffer^,pchar(@Bufferdate)^,bufferlength);
for i:=0 to BufferLength - 1 do
begin
Memo1.Text := Memo1.Text + IntToHex(Bufferdate, 2) + ' ';
end;
except
comm1.StopComm;
showmessage('通迅错误!');
end;
Memo1.Lines.Add('成功');
end;
end.