ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How can i make a qt project that has qexserialport library?

asked 2013-12-09 08:28:04 -0500

mr.karimi gravatar image

updated 2014-01-28 17:18:46 -0500

ngrennan gravatar image

I write a program in qt for recieving data from serial port.I use qextserialport. I build this library(qextserialport) with qmake and use it. but when i want to build this qt project with rosmake to use it in ros, i see this error :

In file included from /home/user/ros_workspace/qt_test/qextserialport_test/widget.cpp:1:0: /home/user/ros_workspace/qt_test/qextserialport_test/widget.h:5:28: fatal error: qextserialport.h: No such file or directory

what should i do?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-12-22 02:26:15 -0500

Hamid Didari gravatar image

In order to use qexserialport in ros I suggest you this cmake.This program writes "h" on the port an receives some data from micro. Cmake

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)


find_package(Qt4 COMPONENTS QtCore QtGui)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
link_directories(/usr/include/qt4/QtExtSerialPort)

rosbuild_init()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

rosbuild_add_executable(first_test src/first_test.cpp)
target_link_libraries(first_test ${QT_LIBRARIES} -lqextserialport -lpthread)

and the program

/*
 * first_test.cpp
 *
 *  Created on: Dec 19, 2013
 *      Author: hamid
 */

#include "ros/ros.h"
#include <QtExtSerialPort/qextserialport.h>
#include "QDebug"
#include "QCoreApplication"


int main(int argc, char** argv)
{
    ros::init(argc, argv, "first_test");
    QCoreApplication app(argc, argv);

    ros::NodeHandle n;
    QextSerialPort *port;
    QByteArray bytes;
    QByteArray bytes2;


    QString portName = QLatin1String("ttyUSB0");
    port = new QextSerialPort(QString(portName), QextSerialPort::EventDriven);

    port->setBaudRate(BAUD9600);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_1);


    if (port->open(QIODevice::ReadWrite) == true)
     {
            qDebug() << "listening for data on" << port->portName();
         }
    else 
     {
               qDebug() << "device failed to open:" << port->errorString();
         }

    bytes[0]='h';
    int total = port->write(bytes,bytes.size());
    qDebug() << total;
    sleep(1);
    int a = port->bytesAvailable();
    qDebug() << a;
    bytes2.resize(a);
    port->read(bytes2.data(),bytes2.size());
    qDebug() <<(QString::fromAscii(bytes2).toUcs4());

    return 0;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-12-09 08:28:04 -0500

Seen: 1,559 times

Last updated: Dec 22 '13