Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem with QextSerialport Receive in BeagleboardXM
Forum Updated to NodeBB v4.3 + New Features

Problem with QextSerialport Receive in BeagleboardXM

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    badzie
    wrote on last edited by
    #1

    I am trying QextSerialport with beagleboard xM to send and receive data. I connected the readyread() signal to a slot. I am connecting the beagleboard to a controller which transmits a string of characters serially.But my receive slot is not getting executed, while my transmit is working properly.

    Following is my code:

    SerialThread.h
    @
    #ifndef SERIALTHREAD_H
    #define SERIALTHREAD_H

    #include"qextserialport.h"
    #include "qextserialenumerator.h"

    class SerialThread : public QThread
    {
    Q_OBJECT

    signals:
    void SendSerialValues(QByteArray Values);
    void SendReceivedValues(QByteArray Val);

    public slots:
    void Write_To_SerialPort(void);
    void Config_Serial_Parameters(int brate);
    void Serial_Receive(void);
    private:
    QextSerialPort *port_on_thread;
    QextSerialEnumerator *enumerator;
    };

    #endif
    @

    SerialThread.cpp
    @
    #include"SerialThread.h"
    #include<QtCore>
    #include<QDebug>
    #include"mainwindow.h"
    #include<QDebug>
    #include"qextserialport.h"
    #include "qextserialenumerator.h"

    void SerialThread::run()
    {
    qDebug() << "hello from Serial thread " << thread()->currentThreadId();
    exec();
    }

    SerialThread::SerialThread(QObject *parent ):QThread(parent){
    moveToThread(this);
    }

    QByteArray Values_1;

    void SerialThread::Write_To_SerialPort(void)
    {

    Values_1[0]='a';
    Values_1[1]='b';
    Values_1[2]='c';
    Values_1[3]='d';
    
    
        port_on_thread->write(Values_1,sizeof(Values_1));
        emit SendSerialValues(Values_1);//emitting signal
    

    }

    void SerialThread::Config_Serial_Parameters(int brate)
    {
    PortSettings settings = {BAUD4800, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    port_on_thread=new QextSerialPort("ttyO2",settings,QextSerialPort::EventDriven);
    if(brate == 0)
    port_on_thread->setBaudRate(BAUD1200);

    if(brate == 1)
        port_on_thread->setBaudRate(BAUD2400);
    
    if(brate == 2)
        port_on_thread->setBaudRate(BAUD4800);
    
    if(brate == 3)
        port_on_thread->setBaudRate(BAUD9600);
    
    if(brate == 4)
        port_on_thread->setBaudRate(BAUD19200);
    
    if(brate == 5)
        port_on_thread->setBaudRate(BAUD115200);
    
      port_on_thread->open(QIODevice::ReadWrite);
      connect(port_on_thread,SIGNAL(readyRead()),SLOT(Serial_Receive()));
    

    }

    void SerialThread::Serial_Receive()
    {
    QByteArray Received_Data;
    Received_Data=port_on_thread->readAll();
    emit SendReceivedValues(Received_Data);
    }

    @

    MainWindow.h
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include"common.h"
    class QextSerialPort;
    class QextSerialEnumerator;
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);

    ~MainWindow();
    

    signals:
    void SendSignal(QByteArray t);
    void SendSerialParameters(int brate);

    private slots:

    void Get_From_SpinBox(void);
    void ValuesFromUSB(int t1,int t2,int t3);
    void ValuesFromSD(int t1,int t2,int t3);
    void UpdateWriteSerial(QByteArray v);
    void UpdateRecvSerial(QByteArray val);
    void onButtonClicked();
    // void onBaudRateChanged(int idx);

    private:
    Ui::MainWindow *ui;
    ProcessThread p;
    SerialThread s;

    };

    #endif // MAINWINDOW_

    @

    MainWindow.cpp

    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include<QDebug>
    #include<QDir>
    #include<QFile>
    #include<QString>
    #include "ProcessThread.h"
    #include"SerialThread.h"
    #include<QLabel>
    #include<QThread>
    #include<QObject>

    int baud_value;
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(Get_From_SpinBox()));
    connect(this,SIGNAL(SendSignal(QByteArray)),&p,SLOT(Store_Temperatures(QByteArray)),Qt::QueuedConnection);
    connect(ui->pushButton_2,SIGNAL(clicked()),&p,SLOT(WriteFileToUSB()));
    connect(ui->pushButton_3,SIGNAL(clicked()),&p,SLOT(WriteFileToSD()));
    connect(ui->pushButton_4,SIGNAL(clicked()),&p,SLOT(LoadValuesFromUSB()));
    connect(ui->pushButton_5,SIGNAL(clicked()),&p,SLOT(LoadValuesFromSD()));
    connect(&p,SIGNAL(SendStoredTempValues(int,int,int)),this,SLOT(ValuesFromUSB(int,int,int)));
    connect(&p,SIGNAL(SendStoredTempValuesSD(int,int,int)),this,SLOT(ValuesFromSD(int,int,int)));

    ui->BaudRateBox->addItem("1200", BAUD1200);
    ui->BaudRateBox->addItem("2400", BAUD2400);
    ui->BaudRateBox->addItem("4800", BAUD4800);
    ui->BaudRateBox->addItem("9600", BAUD9600);
    ui->BaudRateBox->addItem("19200", BAUD19200);
    ui->BaudRateBox->addItem("115200",BAUD115200);
    

    //configuring of serial port
    connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(onButtonClicked()));
    connect(this,SIGNAL(SendSerialParameters(int)),&s,SLOT(Config_Serial_Parameters(int)));

    //transmit
    connect(ui->pushButton_6,SIGNAL(clicked()),&s,SLOT(Write_To_SerialPort()),Qt::QueuedConnection);
    connect(&s,SIGNAL(SendSerialValues(QByteArray)),this,SLOT(UpdateWriteSerial(QByteArray)));

    //receive

    connect(&s,SIGNAL(SendReceivedValues(QByteArray)),this,SLOT(UpdateRecvSerial()));
    
    p.start();
    s.start();
    

    }

    void MainWindow::UpdateWriteSerial(QByteArray v)
    {
    ui->textEdit->insertPlainText(v);

    }

    void MainWindow::UpdateRecvSerial(QByteArray val)
    {

    ui->textEdit_2->insertPlainText(val);
    

    }

    int baudrate;
    void MainWindow::onButtonClicked()
    {

    baudrate=ui->BaudRateBox->currentIndex();
    emit SendSerialParameters(baudrate);
    

    }

    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      badzie
      wrote on last edited by
      #2

      Sorry guys, that was a problem with the hardware and now its working properly!!

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved