Delphi 打开串口与关闭串口
procedure TForm1.btn1Click(Sender: TObject);
begin
cm1.CommName:=cbb1.Text;
cm1.BaudRate:=strtoint(cbb2.Items[cbb2.ItemIndex]);
case cbb3.ItemIndex of
:cm1.ByteSize:=_5;
:cm1.ByteSize:=_6;
:cm1.ByteSize:=_7;
:cm1.ByteSize:=_8;
end; case cbb4.ItemIndex of
:cm1.StopBits:=_1;
:cm1.StopBits:=_1_5;
:cm1.StopBits:=_2;
end; cm1.StopComm;//关闭串口
try
cm1.StartComm;//打开串口
except
ShowMessage('串口打开失败!');
Exit;
end; Delay();//延时
ShowMessage('成功打开串口:');
end;