小编Ale*_*ren的帖子

Qt串行端口 - 一致地读取数据

我通过串口向设备发送(写入)字节.我正在使用QSerialPort(http://qt-project.org/wiki/QtSerialPort)模块来实例化设备IO支持.当我向INSTEON调制解调器(串行)发送消息时,在读取我的消息时,设备会发回我的消息副本+ 0x06(ACK Byte),然后是状态消息.

我使用DockLight(http://www.docklight.de/)测试了我的消息.我发送以下消息来查询设备的状态:

    02 62 1D E9 4B 05 19 00
Run Code Online (Sandbox Code Playgroud)

使用Docklight,我收到回复:

    02 62 1D E9 4B 05 19 00 06 02 50 20 CB CF 1E DA F7 21 00 FF
Run Code Online (Sandbox Code Playgroud)

返回的消息准确表明了我期望的设备是什么.如果关闭,如果设备关闭,调制解调器将在最后一个字节位置发回0x00.现在,我的问题 - 我必须正确设置我的功能才能发送然后接收响应字节.我尝试了很多不同的示例和配置,目前我正在使用以下内容:

设置信号槽连接:

QObject::connect(&thread, SIGNAL(sendResponse(QByteArray)), 
    this, SLOT(handleResponse(QByteArray)));
QObject::connect(&thread, SIGNAL(error(QString)), 
    this, SLOT(processError(QString)));
QObject::connect(&thread, SIGNAL(timeout(QString)), 
    this, SLOT(processTimeout(QString)));
Run Code Online (Sandbox Code Playgroud)

用于迭代设备QList的函数.如果设备是所需类型("Light"),那么我们将设备ID格式化为预期的QByteArray消息结构.将消息传递给线程以进行发送.(从QSerialPort BlockingMaster示例修改的线程.

void Device::currentStatus(QList<Device *> * deviceList){
    QString devID, updateQry;
    int devStatus, updateStatus;
    updateStatus=0;
    QSqlQuery query;
    for(int i=0; i<deviceList->size(); i++){
        if(deviceList->at(i)->type == "Light"){
            devStatus = deviceList->at(i)->status; …
Run Code Online (Sandbox Code Playgroud)

c++ qt serial-port qtserialport

6
推荐指数
1
解决办法
3万
查看次数

完整评论REGEX for LEX

我正在使用Lex和Yacc构建计算器编译器.该想法基于以下资源:http://epaperpress.com/lexandyacc/index.html.

对于给定的输入文件,我需要识别所有注释:

//.TEST -- JWJ
//.Step final  -- testing all requirements
//.source: test-1m.cal
//.expected output: test-1m_expected.out

/**
 *  This program will use Newton's method to estimate the roots of


 This should be a comment as well, but does not get picked up


 *  f(x) = x^3 - 3*x 
 */
 float xn;
 float xo;
// int num_iterations;
 xo = 3.0;
 xn = 3.0;
 num_iterations = 1;

 /* A do-while loop */
 do {
  print xo;
  xo = …
Run Code Online (Sandbox Code Playgroud)

regex compiler-construction lex bison

1
推荐指数
1
解决办法
4722
查看次数

标签 统计

bison ×1

c++ ×1

compiler-construction ×1

lex ×1

qt ×1

qtserialport ×1

regex ×1

serial-port ×1