delphi 串口的打开与关闭

Delphi 打开串口与关闭串口

 1 procedure TForm1.btn1Click(Sender: TObject);
 2 begin
 3   cm1.CommName:=cbb1.Text;
 4   cm1.BaudRate:=strtoint(cbb2.Items[cbb2.ItemIndex]);
 5   case cbb3.ItemIndex of
 6     0:cm1.ByteSize:=_5;
 7     1:cm1.ByteSize:=_6;
 8     2:cm1.ByteSize:=_7;
 9     3:cm1.ByteSize:=_8;
10   end;
11 
12   case cbb4.ItemIndex of
13     0:cm1.StopBits:=_1;
14     1:cm1.StopBits:=_1_5;
15     2:cm1.StopBits:=_2;
16   end;
17 
18   cm1.StopComm;//关闭串口
19   try
20     cm1.StartComm;//打开串口
21   except
22     ShowMessage('串口打开失败!');
23     Exit;
24   end;
25 
26   Delay(50);//延时
27   ShowMessage('成功打开串口:');
28 end;
View Code
posted @ 2013-07-31 15:25  风的哀伤  阅读(696)  评论(0编辑  收藏  举报