• 6644阅读
  • 5回复

[提问]QT串口设置问题,在线求助 [复制链接]

上一主题 下一主题
离线luoyang
 

只看楼主 倒序阅读 楼主  发表于: 2011-02-17
先上代码~
void chuanjoushiyan::on_pushButton_clicked()
{
    QString portName = "/dev/ttyS0";
    myCom = new Posix_QextSerialPort(portName, QextSerialBase::Polling);
    //这里QextSerialBase::QueryMode应该使用QextSerialBase::Polling
    if(myCom->open(QIODevice::ReadWrite)){
        QMessageBox::information(this, tr("打开成功"), tr("已成功打开串口 ") + portName, QMessageBox::Ok);
    }else{
        QMessageBox::critical(this, tr("打开失败"), tr("未能打开串口 ") + portName + tr("\n该串口设备不存在或已被占用"), QMessageBox::Ok);
        return;
    }
    //设置波特率
    myCom->setBaudRate((BaudRateType)9600);
    //设置数据
    myCom->setDataBits((DataBitsType)8);
    //设置校验
    myCom->setParity((ParityType)0);
    //设置停止位
    myCom->setStopBits((StopBitsType)1);
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(readMyCom()));
    //开启读取定时器
    timerdly = TIMER_INTERVAL;
    timer->start(timerdly);
    //设置数据流控制
    myCom->setFlowControl(FLOW_OFF);
    //设置延时
    myCom->setTimeout(TIME_OUT);
}
这是我打开串口的代码~~
程序没有问题~~当我点击这个按钮打开串口时候会出现打开串口成功的消息框,当我点击OK,确定的时候
会出现这样一个提示:Posix_QextSerialPort: 1.5 stop bit operation is not supported by POSIX.
请问这是什么原因?
离线luoyang

只看该作者 1楼 发表于: 2011-02-17
为什么我停止位配置的1~~他说不支持1.5的停止位啊~~不解
离线6a209
只看该作者 2楼 发表于: 2011-02-17
干嘛要加个强制转换? 直接设1可以么?
离线luoyang

只看该作者 3楼 发表于: 2011-02-17
回 2楼(6a209) 的帖子
不可以直接设为1的~~会出现这个
/home/gj/Qt--mytest/chuankou--shiyan-build-desktop/../chuankou--shiyan/chuanjoushiyan.cpp:50: error: invalid conversion from ‘int’ to ‘StopBitsType’
/home/gj/Qt--mytest/chuankou--shiyan-build-desktop/../chuankou--shiyan/chuanjoushiyan.cpp:50: error:   initializing argument 1 of ‘virtual void Posix_QextSerialPort::setStopBits(StopBitsType)’
离线6a209
只看该作者 4楼 发表于: 2011-02-17
不设停止位ok么?
离线luoyang

只看该作者 5楼 发表于: 2011-02-18
解决了~~~自己的问题~~~他把那个值设定了一个枚举~~~实际上那个1对应的是停止位的1.5~~~
enum StopBitsType
{
    STOP_1,
    STOP_1_5,               //WINDOWS ONLY
    STOP_2
};
快速回复
限100 字节
 
上一个 下一个