Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I want make device execute command , when I press the radio-button in QT
Forum Updated to NodeBB v4.3 + New Features

I want make device execute command , when I press the radio-button in QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 2.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.
  • M mrjj
    25 Sept 2017, 06:01

    Hi
    I assume you want to have
    mSerialport->write("XXX");
    To write the command to the device.

    S Offline
    S Offline
    segtteee
    wrote on 25 Sept 2017, 06:08 last edited by
    #7

    @mrjj
    thank you for reply.

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        mSerialport = new QSerialPort (this);
        connect(ui->pushButton_send,&QPushButton::clicked,[=](){
            sendMsg(ui->command->toPlainText());
    
        });
        connect(ui->radioButton_on,&QRadioButton::clicked,[=](){
            monitor_mode_on();
        });
    
        connect(ui->radioButton_off,&QRadioButton::clicked,[=](){
            monitor_mode_off();
        });
    }
    

    Is this the right structure for the rules? Add two connectors below and it will not run . (Two sentences inclusing radio-button)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 25 Sept 2017, 06:12 last edited by
      #8

      Well on button you call sendMsg and for the
      radioButton_on you call monitor_mode_on() which will send a command and
      same does radioButton_off
      Which seem pretty ok if monitor_mode_on/off sends
      command to device to enable/disable something.

      S 1 Reply Last reply 25 Sept 2017, 07:46
      1
      • M mrjj
        25 Sept 2017, 06:12

        Well on button you call sendMsg and for the
        radioButton_on you call monitor_mode_on() which will send a command and
        same does radioButton_off
        Which seem pretty ok if monitor_mode_on/off sends
        command to device to enable/disable something.

        S Offline
        S Offline
        segtteee
        wrote on 25 Sept 2017, 07:46 last edited by
        #9

        @mrjj
        I think mSerialport->write("XXX"); is wrong.
        my device couldn't recognize command.

        M 1 Reply Last reply 25 Sept 2017, 08:03
        0
        • S segtteee
          25 Sept 2017, 07:46

          @mrjj
          I think mSerialport->write("XXX"); is wrong.
          my device couldn't recognize command.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 25 Sept 2017, 08:03 last edited by
          #10

          @segtteee
          Hi
          In what way wrong?
          the XXX was just example
          you need
          mSerialport->write("mon 1");
          or what ever real command is. :)

          S 1 Reply Last reply 25 Sept 2017, 08:08
          1
          • M mrjj
            25 Sept 2017, 08:03

            @segtteee
            Hi
            In what way wrong?
            the XXX was just example
            you need
            mSerialport->write("mon 1");
            or what ever real command is. :)

            S Offline
            S Offline
            segtteee
            wrote on 25 Sept 2017, 08:08 last edited by
            #11

            @mrjj
            I wrote mSerialport-> write ("mon 1"); but device doesn't work.
            So is not the code wrong?

            M 1 Reply Last reply 25 Sept 2017, 08:12
            0
            • S segtteee
              25 Sept 2017, 08:08

              @mrjj
              I wrote mSerialport-> write ("mon 1"); but device doesn't work.
              So is not the code wrong?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 25 Sept 2017, 08:12 last edited by
              #12

              @segtteee
              Nope, should send the string if port is open etc.
              The write function returns how many bytes written.

              so you can do
              qDebug() << "written->" << mSerialport->write("mon 1");
              (#include <QDebug>)

              Can you see on device if it gets the string?

              S 1 Reply Last reply 25 Sept 2017, 08:25
              1
              • M mrjj
                25 Sept 2017, 08:12

                @segtteee
                Nope, should send the string if port is open etc.
                The write function returns how many bytes written.

                so you can do
                qDebug() << "written->" << mSerialport->write("mon 1");
                (#include <QDebug>)

                Can you see on device if it gets the string?

                S Offline
                S Offline
                segtteee
                wrote on 25 Sept 2017, 08:25 last edited by
                #13

                @mrjj
                i wrote qDebug() << "written->" << mSerialport->write("mon 1");
                and i can see 'written-> 5' in application output window.
                What does this mean?
                The equipment does not carry out orders ("mon 1" or "mon 0") .

                M 1 Reply Last reply 25 Sept 2017, 08:43
                0
                • S segtteee
                  25 Sept 2017, 08:25

                  @mrjj
                  i wrote qDebug() << "written->" << mSerialport->write("mon 1");
                  and i can see 'written-> 5' in application output window.
                  What does this mean?
                  The equipment does not carry out orders ("mon 1" or "mon 0") .

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 25 Sept 2017, 08:43 last edited by
                  #14

                  @segtteee
                  It means that it wrote 5 chars to the serial port.
                  so it seems it does send it :)

                  • The equipment does not carry out orders ("mon 1" or "mon 0") .
                    And you are sure that is the syntax for the command?
                    And board are ready to accept commands etc?
                    Who wrote the code on the board?
                  S 1 Reply Last reply 25 Sept 2017, 08:58
                  1
                  • M mrjj
                    25 Sept 2017, 08:43

                    @segtteee
                    It means that it wrote 5 chars to the serial port.
                    so it seems it does send it :)

                    • The equipment does not carry out orders ("mon 1" or "mon 0") .
                      And you are sure that is the syntax for the command?
                      And board are ready to accept commands etc?
                      Who wrote the code on the board?
                    S Offline
                    S Offline
                    segtteee
                    wrote on 25 Sept 2017, 08:58 last edited by
                    #15

                    @mrjj
                    By writing behind "\ N" I had solved the problem . Thank you!!

                    M 1 Reply Last reply 25 Sept 2017, 09:00
                    0
                    • S segtteee
                      25 Sept 2017, 08:58

                      @mrjj
                      By writing behind "\ N" I had solved the problem . Thank you!!

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 25 Sept 2017, 09:00 last edited by
                      #16

                      @segtteee
                      ahh, it was expecting a line. not just the text.
                      super :)

                      1 Reply Last reply
                      1

                      16/16

                      25 Sept 2017, 09:00

                      • Login

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