为什么不能设置时间,只能接收到一个’Y‘请各位富翁们指点一二呀。我源程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SPComm;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Comm2: TComm;
procedure Button1Click(Sender: TObject);
procedure Comm2ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure senddata;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
buf1:array[0..35]of byte;
implementation
{$R *.dfm}
procedure tform1.senddata;
var
i:integer;
flag:boolean;
begin
flag:=true;
for i:= 0 to 35 do
begin
if not form1.Comm2.WriteCommData(@buf1,1)then
begin
flag:=false;
break;
end;
sleep(10);
end;
if flag=false then
messagedlg('发送失败!',mterror,[mbyes],0);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
comm2.Parity:=mark;
for i:=0 to 19 do
begin
buf1:=byte($34);
end;
buf1[20]:=byte($41);
buf1[21]:=byte($3f);
//for i:= 0 to 21 do
//begin
//comm2.WriteCommData(@buf1,1);
//sleep(4);
//end;
if not comm2.ParityCheck then
comm2.ParityCheck:=true;
comm2.Parity:=space;
buf1[22]:=$30;
buf1[23]:=$33;
buf1[24]:=$31;
buf1[25]:=$30;
buf1[26]:=$32;
buf1[27]:=$35;
buf1[28]:=$31;
buf1[29]:=$35;
buf1[30]:=$33;
buf1[31]:=$30;
buf1[32]:=$31;
buf1[33]:=$30;
buf1[34]:=$30;
buf1[35]:=$31;
senddata;
//for i:=22 to 35 do
// begin
//comm2.WriteCommData(@buf1,1);
//sleep(4);
// end;
end;
procedure TForm1.Comm2ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
s:string;
begin
setlength(s,bufferlength);
move(buffer^,pchar(s)^,bufferlength);
Memo1.Lines.Add(s);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
comm2.StartComm;
//comm2.ReadTotalTimeoutConstant:=8;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
comm2.StopComm ;
end;
end.