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. How to send data to Serial Port in Qt Test
Forum Updated to NodeBB v4.3 + New Features

How to send data to Serial Port in Qt Test

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 287 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.
  • E Offline
    E Offline
    egbiomated
    wrote on last edited by
    #1

    I am trying to write some integration tests around my serial device and it appears that i can't send data in my tests i get the following error message:

    QWARN  : Test::test_case3() QObject::startTimer: Timers can only be used with threads started with QThread
    

    My Test case:

    void Test::test_case3()
    {
        // MotorTest mt;
        // QThread* thread = new QThread( );
        // mt.moveToThread(thread);
        // thread->start();
    
        qDebug("MOTOR TESTS");
        Motor motor;
        // // QThread::sleep(1);
        QTest::qSleep(1000);
        motor.motor_jog_accel(10);
        // / QTest::qSleep(1000);
        motor.motor_jog_decel(10);
        // // QTest::qSleep(1000);
        motor.motor_jog_speed(10);
        // // QTest::qSleep(1000);
        motor.motor_jog_enable();
        // // QTest::qSleep(5000);
        motor.motor_jog_disable();
        // // QTest::qSleep(1000);
    }
    

    Here is some of the Code from the motor that is relevant:

    #include "motor.h"
    #include <string.h>
    #include <QIODevice>
    #include <QDebug>
    
    Motor::Motor()
    {
        sp.setPortName("COM1");
        sp.open(QIODevice::ReadWrite);
    }
    
    // void Motor::motor_send_command(char buff[], uint16_t buffLen)
    void Motor::motor_send_command(char buff[], uint16_t buffLen)
    {
        qDebug() << "SENDING: " << buff;
        char cbuff[50] = { '\0' };
        strncpy(cbuff, buff, 50);
        snprintf(cbuff, 50, "%s\r", buff);
        sp.write(cbuff);
    }
    
    void Motor::motor_send_command(char buff[])
    {
        qDebug() << "SENDING: " << buff;
        char cbuff[50] = { '\0' };
        strncpy(cbuff, buff, 50);
        snprintf(cbuff, 50, "%s\r", buff);
        qDebug() << "ABOUT: " << buff;
        sp.write(cbuff);
        qDebug() << "SENT: " << buff;
    }
    
    void Motor::motor_set_accel(uint16_t accel)
    {
    }
    
    void Motor::motor_set_accel_max(uint16_t accel)
    {
    
    }
    
    void Motor::motor_start_jog()
    {
    
    }
    
    void Motor::motor_change_speed(uint16_t speed)
    {
    
    }
    
    void Motor::motor_set_decel(uint16_t decel)
    {
    
    }
    
    void Motor::motor_jog_accel(uint16_t accel)
    {
        motor_send_command("JA1000");
    }
    
    void Motor::motor_jog_velocity(uint16_t velocity)
    {
    
    }
    
    void Motor::motor_jog_disable()
    {
        motor_send_command("SJ");
    }
    
    void Motor::motor_jog_enable()
    {
        motor_send_command("CJ");
    }
    
    void Motor::motor_jog_decel(uint16_t decel)
    {
        motor_send_command("JL1000");
    }
    
    void Motor::motor_jog_speed(uint16_t speed)
    {
        motor_send_command("JS1");
    }
    
    void Motor::motor_disable()
    {
    
    }
    
    void Motor::motor_enable()
    {
    
    }
    
    void Motor::motor_microstep_resolution(uint16_t resolution)
    {
    
    }
    
    void Motor::motor_set_direction(uint8_t direction)
    {
    
    }
    
    void Motor::motor_stop_jogging()
    {
    
    }
    
    void Motor::motor_velocity_max(uint16_t vmax)
    {
    
    }
    
    

    Is there any way to be able to start the main test with QThread? I guess the interrupts used for the serialport are not able to start because of that?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you using QTEST_MAIN for your tests ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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