Unsolved I want make device execute command , when I press the radio-button in QT
-
callme() is function name.
-
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(); });
void MainWindow::monitor_mode_on() { " " } //I have write this, but between " " I do not know what code to write. is this 'mSerialport->"mon 1"' ? (mon 1 is command)
-
Hi
I assume you want to have
mSerialport->write("XXX");
To write the command to the device. -
@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)
-
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. -
@mrjj
I think mSerialport->write("XXX"); is wrong.
my device couldn't recognize command. -
@segtteee
Hi
In what way wrong?
the XXX was just example
you need
mSerialport->write("mon 1");
or what ever real command is. :) -
@mrjj
I wrote mSerialport-> write ("mon 1"); but device doesn't work.
So is not the code wrong? -
@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?
-
@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") . -
@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?
- The equipment does not carry out orders ("mon 1" or "mon 0") .
-
@mrjj
By writing behind "\ N" I had solved the problem . Thank you!! -
@segtteee
ahh, it was expecting a line. not just the text.
super :)