delphi MSComm1自动获取串口


本文整理自网络,侵删。

 
如果PC端串口x存在且没有被占用,我们用TMScomm控件可以顺利打开并且关闭串口x,如果该端口x被占用或者不存在则会出现错误。利用这个原理,通过try强行打开串口x获取可用串口。具体代码如下:

i:integer;

combobox1.items.clear;
for i := 1 to 32 do  //一般PC端串口都小于32 
  begin
    try
      MSComm1.CommPort := i;
      if MSComm1.PortOpen = false then
      begin
        MSComm1.PortOpen := true;
      end;
      MSComm1.PortOpen := false;
      ComboBox1.Items.Add(inttostr(i));
    except
    end;
  end;
――――――――――――――――

原文链接:https://blog.csdn.net/Nevermore_anger/article/details/79012875

相关阅读 >>

Delphi10.3.1安卓照相

Delphi 为richedit设置行号

Delphi整理二(object pascal语言)

Delphi 以低用户权限启动一个进程.比如vista或者win7中的ie

Delphi webbrowser设置自己定义user-agent

Delphi中tinifile类 操作ini文件

Delphi 2009 新增单元 character isletter、isupper、islower、isdigit、isnumber

Delphi动态创建控件的例子

Delphi 判断字符是否是汉字,bytetype字符串中判断是否英文

Delphi根据字符分割字串成数组

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...