how to echo directly from dynamic input
-
@Mijaz You did not answer my questions from my previous post.
Do you mean you want to update out_altvoltage1_TX_LO_frequency inside /sys/bus/iio/devices/iio:device1/input ?
Because this:echo /sys/bus/iio/devices/iio:device1/input > out_altvoltage1_TX_LO_frequency
would write the content of /sys/bus/iio/devices/iio:device1/input into file out_altvoltage1_TX_LO_frequency in current working directory.
wrote on 24 Oct 2019, 06:13 last edited by@jsulm
No input is not a directory it is the string in which I have stored value in about command like this:QString input = ui->lineEdit_1->text();
ui->lineEdit_2->setText(input);
Now I want to use this "input" in which I already stored value to update my out_altvoltage1_TX_LO_frequency.
//
Detail explenation of my work:
Step 1:
I firstly executed following commands on my board where I am deploying my project like this:cd /sys/bus/iio/devices/iio:device1/
echo 111111 > out_altvoltage1_TX_LO_frequency
This worked fine;
Step 2:
I create project on my PC using following commands and GUI.system("cd /sys/bus/iio/devices/iio:device1/; echo 222222 > out_altvoltage1_TX_LO_frequency");
QProcess process1;
process1.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
process1.waitForFinished(-1); // will wait forever until finished
QString stdout1 = process1.readAllStandardOutput();
qDebug() << stdout1;
ui->lineEdit_3->setText(stdout1);
This also work correctly.
Step 3:
Now, because it is my task requirement that I need update register (out_altvoltage1_TX_LO_frequency) value at real-time, depends on the situation not remained fixed like (222222), therefore I update code like this:QString input = ui->lineEdit_1->text();
ui->lineEdit_2->setText(input);
QFile f("/sys/bus/iio/devices/iio:device1/input");
if (f.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray ba = f.readAll();
ui->lineEdit_3->setText(QString(ba));
f.close();
}whenever I will enter a new value to lineEdit_1 that should update register (out_altvoltage1_TX_LO_frequency) immediately,
this code not working as my requirements.
-
@jsulm
No input is not a directory it is the string in which I have stored value in about command like this:QString input = ui->lineEdit_1->text();
ui->lineEdit_2->setText(input);
Now I want to use this "input" in which I already stored value to update my out_altvoltage1_TX_LO_frequency.
//
Detail explenation of my work:
Step 1:
I firstly executed following commands on my board where I am deploying my project like this:cd /sys/bus/iio/devices/iio:device1/
echo 111111 > out_altvoltage1_TX_LO_frequency
This worked fine;
Step 2:
I create project on my PC using following commands and GUI.system("cd /sys/bus/iio/devices/iio:device1/; echo 222222 > out_altvoltage1_TX_LO_frequency");
QProcess process1;
process1.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
process1.waitForFinished(-1); // will wait forever until finished
QString stdout1 = process1.readAllStandardOutput();
qDebug() << stdout1;
ui->lineEdit_3->setText(stdout1);
This also work correctly.
Step 3:
Now, because it is my task requirement that I need update register (out_altvoltage1_TX_LO_frequency) value at real-time, depends on the situation not remained fixed like (222222), therefore I update code like this:QString input = ui->lineEdit_1->text();
ui->lineEdit_2->setText(input);
QFile f("/sys/bus/iio/devices/iio:device1/input");
if (f.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray ba = f.readAll();
ui->lineEdit_3->setText(QString(ba));
f.close();
}whenever I will enter a new value to lineEdit_1 that should update register (out_altvoltage1_TX_LO_frequency) immediately,
this code not working as my requirements.
@Mijaz OK, that means you want to write to /sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency file, because
cd /sys/bus/iio/devices/iio:device1/ echo 111111 > out_altvoltage1_TX_LO_frequency
does exactly that.
Then simply use QFile to write:QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency"); if (f.open(QIODevice::WriteOnly | QIODevice::Text)) { f.write(ui->lineEdit_2->text().toLatin1()); f.close(); }
-
@Mijaz OK, that means you want to write to /sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency file, because
cd /sys/bus/iio/devices/iio:device1/ echo 111111 > out_altvoltage1_TX_LO_frequency
does exactly that.
Then simply use QFile to write:QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency"); if (f.open(QIODevice::WriteOnly | QIODevice::Text)) { f.write(ui->lineEdit_2->text().toLatin1()); f.close(); }
wrote on 24 Oct 2019, 06:42 last edited byQFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
if (f.open(QIODevice::WriteOnly | QIODevice::Text))
{
f.write(ui->lineEdit_2->text().toLatin1());
f.close();
}this still not updating register ( out_altvoltage1_TX_LO_frequency) value.
-
QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
if (f.open(QIODevice::WriteOnly | QIODevice::Text))
{
f.write(ui->lineEdit_2->text().toLatin1());
f.close();
}this still not updating register ( out_altvoltage1_TX_LO_frequency) value.
@Mijaz You still did not answer any of my previous questions?
Did you check what happens? Please use debugger and see whether your if block was executed at all.
Did you check return value of open()?
Did you check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns? -
@Mijaz You still did not answer any of my previous questions?
Did you check what happens? Please use debugger and see whether your if block was executed at all.
Did you check return value of open()?
Did you check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns?wrote on 24 Oct 2019, 07:22 last edited by JonB@jsulm
Do you realise this thread is just a rehash of @Mijaz's own https://forum.qt.io/topic/107974/system-vs-process-command/ ? He asks exactly the same question there. You will see the same questions about thecat
command and the same answers about usingQFile
, the same issue about the current directory and paths, .... I tried to help, but he chose not to supply the necessary information, and is just going through the same stuff again. It gets so frustrating here when people choose not to follow through the advice they are given when they do not like it, and instead create a new thread to get the information all over again... -
@jsulm
Do you realise this thread is just a rehash of @Mijaz's own https://forum.qt.io/topic/107974/system-vs-process-command/ ? He asks exactly the same question there. You will see the same questions about thecat
command and the same answers about usingQFile
, the same issue about the current directory and paths, .... I tried to help, but he chose not to supply the necessary information, and is just going through the same stuff again. It gets so frustrating here when people choose not to follow through the advice they are given when they do not like it, and instead create a new thread to get the information all over again...@JonB Yes, I saw that thread and I agree that it is very frustrating if people do not answer questions and do not follow advices - what's the point to ask then in a forum? But it is how it is...
-
@Mijaz You still did not answer any of my previous questions?
Did you check what happens? Please use debugger and see whether your if block was executed at all.
Did you check return value of open()?
Did you check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns? -
@Mijaz Does it work now?
-
@Mijaz OK, that means you want to write to /sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency file, because
cd /sys/bus/iio/devices/iio:device1/ echo 111111 > out_altvoltage1_TX_LO_frequency
does exactly that.
Then simply use QFile to write:QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency"); if (f.open(QIODevice::WriteOnly | QIODevice::Text)) { f.write(ui->lineEdit_2->text().toLatin1()); f.close(); }
wrote on 24 Oct 2019, 12:30 last edited by Mijaz@jsulm
Now, If I want to update two different register (out_altvoltage0_TX_LO_frequency and out_altvoltage1_TX_LO_frequency ) with same value.
The how can execute code using single QFile .
I tried like follows but not worked:QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage0_TX_LO_frequency | out_altvoltage1_TX_LO_frequency");
if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
f.write(ui->lineEdit_2->text().toLatin1());
f.close();
} -
Hi,
You can't open two files at the same time like that. You can use a loop and open one after the other.
21/22