unit commtest3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, MSCommLib_TLB, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Timer1: TTimer;
MSComm1: TMSComm;
Edit1: TEdit;
Edit2: TEdit;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
temp:integer;
bzw:boolean;
sendstr:string;
senddata:array[1..10] of char;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
timer1.Enabled:=false;
mscomm1.CommPort :=2;
mscomm1.Settings := '9600,N,8,1';
mscomm1.InBufferSize := 1024;
mscomm1.OutBufferSize := 1024;
mscomm1.InputMode := comInputModeBinary;//接收模式
mscomm1.InputLen := 0;//一次读取所有数据
mscomm1.SThreshold := 0;//一次发送所有数据
mscomm1.InBufferCount := 0;//清空读取缓冲区
mscomm1.OutBufferCount := 0;//清空发送缓冲区
//mscomm1.PortOpen:=true;//打开端口
MSComm1.RThreshold :=47;//设置接收多少字节开产生oncomm事件
timer1.Enabled:=true;
sleep(100);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i:longint;