主题:请教:spcomm的发送接收问题;(急急急!!!解决后累计给分);
var sbuf,rbuf:arrar[1..10]of byte;
procedure TForm1.Button1Click(Sender: TObject);
begin
sbuf[1]:=byte($f0);
sbuf[2]:=byte($01);
sbuf[3]:=byte(83);
sbuf[4]:=byte(06);
sbuf[5]:=byte(27);
sbuf[6]:=byte(12);
sbuf[7]:=byte(34);
sbuf[8]:=byte(56);
sbuf[9]:=byte($f0);
sbuf[10]:=byte($01);
self.senddata;
end;
procedure tform1.senddata;
var i:integer;
commflg:boolean;
begin
commflg:=true;
viewstring:='';
for i:=1 to 10 do
begin
if form1.comm1.WriteCommData(@sbuf[i],1)=false then
begin
commflg:=false;
break;
end;
sleep(2);
end;
if not commflg then messagedlg('发送失败',mterror,[mbyes],0);
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
begin
showmessage('receive success');//若有数据时,显示消息;
end;
请教:执行时,为什么comm1receivedata不能被触发???
若该为'单击button2按钮后接受;
procedure TForm1.Button2Click(Sender: TObject);
var strreceive:string;
buffer:pointer;
bufferlength:word;
begin
setlength(strreceive,bufferlength);
move(buffer^,pchar(strreceive)^,bufferlength);
memo1.Lines.Add(strreceive);
memo1.Invalidate;
end;
为什么接受的会是乱码??
发送能按要求发送.但通过单击button2接受时,接受的代码为:'劺u3繼[冒^[脥@'
procedure TForm1.Button1Click(Sender: TObject);
begin
sbuf[1]:=byte($f0);
sbuf[2]:=byte($01);
sbuf[3]:=byte(83);
sbuf[4]:=byte(06);
sbuf[5]:=byte(27);
sbuf[6]:=byte(12);
sbuf[7]:=byte(34);
sbuf[8]:=byte(56);
sbuf[9]:=byte($f0);
sbuf[10]:=byte($01);
self.senddata;
end;
procedure tform1.senddata;
var i:integer;
commflg:boolean;
begin
commflg:=true;
viewstring:='';
for i:=1 to 10 do
begin
if form1.comm1.WriteCommData(@sbuf[i],1)=false then
begin
commflg:=false;
break;
end;
sleep(2);
end;
if not commflg then messagedlg('发送失败',mterror,[mbyes],0);
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
begin
showmessage('receive success');//若有数据时,显示消息;
end;
请教:执行时,为什么comm1receivedata不能被触发???
若该为'单击button2按钮后接受;
procedure TForm1.Button2Click(Sender: TObject);
var strreceive:string;
buffer:pointer;
bufferlength:word;
begin
setlength(strreceive,bufferlength);
move(buffer^,pchar(strreceive)^,bufferlength);
memo1.Lines.Add(strreceive);
memo1.Invalidate;
end;
为什么接受的会是乱码??
发送能按要求发送.但通过单击button2接受时,接受的代码为:'劺u3繼[冒^[脥@'