加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

QSerialPort使用详解

(2013-03-26 22:14:47)
标签:

qt

串口

串口通信

qserialport

it

= 关于QextSerialPort =
 
QextSerialPort为Qt应用程序提供了串口的接口.它目前支持以下平台:Mac OS X, Windows, Linux, FreeBSD。  
 
官方地址:http://code.google.com/p/qextserialport/
 
== 使用方法 (1) ==
 
 * 下载源代码.
 
 * 把源代码放在你都文件夹下。例如, 3rdparty:
 
            |-- project.pro
            |-- ....
            |-- 3rdparty\
               |-- qextserialport\
               |
 
 * 把下面这句代码加入到你都Qt工程文件(.pro)中:
 
            include(3rdparty/qextserialport/src/qextserialport.pri)
 
 * 在你的代码中使用QextSerialPort。Enjoy it!
 
            #include "qextserialport.h"
            ....
            QextSerialPort * port = new QextSerialPort();
            ....
             
== 使用方法(2) ==
虽然使用上面都方法很容易就把QextSerialPort编译到你都Qt程序中了,但是, 我们更喜欢使用库文件。
下面介绍把QextSerialPort编译成库文件使用的方法。
 
 * 下载源代码,随意把它放在你喜欢的地方.
 
 * 进入该文件夹,执行下面都命令(根据你所使用都平台选择命令).  
 
          qmake
          make (or nmake)
          sudo make install (or nmake install)
 
 * 在你的Qt工程文件中加入以下代码
 
          CONFIG += extserialport
 
 * 在你的代码中使用QextSerialPort。 Enjoy it!
 
            #include "qextserialport.h"
            ....
            QextSerialPort * port = new QextSerialPort();
            ....
 
== 编译文档 ==
 * 执行
           qmake
           make docs
 
 * 说明: 你可以在 doc/readme.txt 中得到更多都信息
 
== 编译例子 ==
 * 进入例子的目录下, 执行
           qmake (or qmake -r)
           make (or nmake)

== 笔者建议 ==
至于QextSerialPort的使用网上都资料很多我就不在赘述,这里向大家推荐一种用法
   foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
           使用info.portName
   这里遍历当前环境下所有的串口,info.protName就是串口名。

建议多参考examples中的代码,这些都是精华。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有