发表于:2005/4/18 20:59:00
#0楼
本代码可以通讯,但是点击发送后,一直处于发送状态,停止不了,比如发送1234
后,Memo2的内容是12341234123412341234123412341234。求助高手/我该怎么办??
//Comm1发送数据
procedure TForm1.BitBtn4Click(Sender: TObject);
var
strSend:String;
i:Integer;
begin
try
Comm1.StopComm;
Comm1.StartComm;
except
Messagedlg('无法打开COMM1!' ,mterror,[mbOK],0);
end;
sleep(50);//等待一段时间
StatusBar1.Panels[1].Text:='串口1已启动';
for i:=0 to Memo1.Lines.Count-1 do
begin
StrSend:=Memo1.Lines[i];
try
StatusBar1.Panels[1].Text:='串口1正在发送数据';
Comm1.WriteCommData(PChar(strSend),Length(strSend));
//发送字符串数据
except
ShowMessage('发送错误');
end;
end;
end;
//Comm2串口接收数据
procedure TForm1.BitBtn6Click(Sender: TObject);
type
IArr=^integer;
var
RevP:array[1..4096]of byte;
i:integer;
CommRevstr:shortString;
BufferLength: Word;
Buffer: Pointer;
begin
SetLength(CommRevstr,BufferLength);
Move(IArr(buffer)^,Revp,bufferLength);
For i:=1 to BufferLength do
begin
CommRevstr[i]:=Char(Revp[i]);
end;
Memo2.Lines.Add(CommRevStr);//添加到Memo2中
StatusBar1.Panels[2].Text:='串口2正在接收数据';
end;
----------------------------------------------
后,Memo2的内容是12341234123412341234123412341234。求助高手/我该怎么办??
//Comm1发送数据
procedure TForm1.BitBtn4Click(Sender: TObject);
var
strSend:String;
i:Integer;
begin
try
Comm1.StopComm;
Comm1.StartComm;
except
Messagedlg('无法打开COMM1!' ,mterror,[mbOK],0);
end;
sleep(50);//等待一段时间
StatusBar1.Panels[1].Text:='串口1已启动';
for i:=0 to Memo1.Lines.Count-1 do
begin
StrSend:=Memo1.Lines[i];
try
StatusBar1.Panels[1].Text:='串口1正在发送数据';
Comm1.WriteCommData(PChar(strSend),Length(strSend));
//发送字符串数据
except
ShowMessage('发送错误');
end;
end;
end;
//Comm2串口接收数据
procedure TForm1.BitBtn6Click(Sender: TObject);
type
IArr=^integer;
var
RevP:array[1..4096]of byte;
i:integer;
CommRevstr:shortString;
BufferLength: Word;
Buffer: Pointer;
begin
SetLength(CommRevstr,BufferLength);
Move(IArr(buffer)^,Revp,bufferLength);
For i:=1 to BufferLength do
begin
CommRevstr[i]:=Char(Revp[i]);
end;
Memo2.Lines.Add(CommRevStr);//添加到Memo2中
StatusBar1.Panels[2].Text:='串口2正在接收数据';
end;
----------------------------------------------