我
我是变量
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TFCOMM.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;
procedure TFCOMM.FormShow(Sender: TObject);
begin
comm1.StartComm;
end;
procedure senddata;
var
i:integer;
commflg:boolean;
begin
viewstring:='';
commflg:=true;
for i:=1 to 6 do
begin
if not fcomm.comm1.writecommdata(@sbuf,1) then
begin
commflg:=false;
break;
end;
//发送时字节间的延时
sleep(5);
viewstring:=viewstring + inttohex(sbuf,2)+ ''; end;
viewstring:='发送'+ viewstring;
fcomm.memo1.lines.add(viewstring);
fcomm.memo1.lines.add('');
if not commflg then messagedlg('发送失败 !' ,mterror,[mbyes],0);
end;
procedure TFCOMM.Button1Click(Sender: TObject);
begin
sbuf[1]:=byte($f0); //帧头
sbuf[2]:=byte($01); //命令号
sbuf[3]:=byte($ff);
sbuf[4]:=byte($ff);
sbuf[5]:=byte($01);
sbuf[6]:=byte($f0); //帧尾
senddata;//调用发送函数
end;
procedure TFCOMM.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
i:integer;
begin
viewstring:='';
//SetLength(viewstring, BufferLength);
//move(buffer^,pchar(viewstring)^,bufferlength);
move(buffer^,pchar(@rbuf)^,bufferlength);
for i:=1 to bufferlength do
viewstring:=viewstring + inttohex(rbuf,2)+'';
viewstring:='接收' + viewstring;
memo1.lines.add(viewstring);
//Memo1.Invalidate;
end;
总是显示发送f001ffff01f0为什么没有显示接收的数据呢????谢谢高手帮我解答...
begin
comm1.StopComm;
end;
procedure TFCOMM.FormShow(Sender: TObject);
begin
comm1.StartComm;
end;
procedure senddata;
var
i:integer;
commflg:boolean;
begin
viewstring:='';
commflg:=true;
for i:=1 to 6 do
begin
if not fcomm.comm1.writecommdata(@sbuf,1) then
begin
commflg:=false;
break;
end;
//发送时字节间的延时
sleep(5);
viewstring:=viewstring + inttohex(sbuf,2)+ ''; end;
viewstring:='发送'+ viewstring;
fcomm.memo1.lines.add(viewstring);
fcomm.memo1.lines.add('');
if not commflg then messagedlg('发送失败 !' ,mterror,[mbyes],0);
end;
procedure TFCOMM.Button1Click(Sender: TObject);
begin
sbuf[1]:=byte($f0); //帧头
sbuf[2]:=byte($01); //命令号
sbuf[3]:=byte($ff);
sbuf[4]:=byte($ff);
sbuf[5]:=byte($01);
sbuf[6]:=byte($f0); //帧尾
senddata;//调用发送函数
end;
procedure TFCOMM.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
i:integer;
begin
viewstring:='';
//SetLength(viewstring, BufferLength);
//move(buffer^,pchar(viewstring)^,bufferlength);
move(buffer^,pchar(@rbuf)^,bufferlength);
for i:=1 to bufferlength do
viewstring:=viewstring + inttohex(rbuf,2)+'';
viewstring:='接收' + viewstring;
memo1.lines.add(viewstring);
//Memo1.Invalidate;
end;
总是显示发送f001ffff01f0为什么没有显示接收的数据呢????谢谢高手帮我解答...