//串行口初始化
Begin
comm1.CommName:=commname;
comm1.BaudRate:=2400;
comm1.StopBits:=_1;
comm1.Parity:=None;
comm1.StartComm;
end;
procedure TForm_comm.commsureClick(Sender: TObject);
var
changed,t:boolean;
baudrt:integer;
begin
if comm1.CommName<>comname.Items[comname.ItemIndex] //若COM口改变
then
begin
comm1.StopComm;
comminitialize(comname.Items[comname.itemindex]);
end;
if comm1.Handle>0
<font color=red> //出错位置,当由无效COM口换成有效时,无法进入,但单步时可进入
<font color="#0000A0">
then
begin
changed:=false;
if speedlist.ItemIndex=-1
then speedlist.ItemIndex:=4
//默认为2400
if comm1.BaudRate<>strtoint(speedlist.Items[speedlist.itemindex])
then changed:=true;
if changed //如果速率改变,则发送数据
then
begin
t:=comm1.WriteCommData(frame_data,write_num);
if t then
begin
//showmessage('write success');
comm1.BaudRate:=strtoint(speedlist.Items[speedlist.itemindex])
// set port Baud Rate
end;
end;
end;
form_comm.Visible:=false;
end;