QByteArray corrupts my data ???Why???
-
Nope... Still same problem.
For some reason I don't grasp, This function tends to randomly give problems. It now seems to have stopped functioning in the main .cpp file as well, and I know it did work before.I tried cleaning the project.
Changing Build directories.
Deleting Build directories.
Tested on other PCs. -
You should wait and check for the device to be ready to write.
-
Ok. I have simplified the code to the bare bone, and still getting the same problem.
But from what I can notice the problem does no longer seem to be related to the QByteArray.
The code bellow also displays corrupted data.@#include <QtSerialPort>
QSerialPort relays;void MainWindow::on_pushButton_clicked()
{
relays.setPortName("COM1");
relays.setDataBits(QSerialPort::Data8);
relays.setParity(QSerialPort::NoParity);
relays.setStopBits(QSerialPort::OneStop);
relays.setFlowControl(QSerialPort::NoFlowControl);
relays.open(QIODevice::ReadWrite);
relays.setBaudRate(QSerialPort::Baud9600);relays.write("all_offx"); relays.waitForBytesWritten(-1); relays.close();
}@
-
@
if (relays.open(QSerialPort::ReadWrite) {
// Set port settings here
QByteArray relay_arr("ch" + QByteArray::number(Ch_on) + "_onx");
relays.write(relay_arr);
}
@ -
Thanks Sierdzio.
I Will give your code a try tomorrow.Although I have found a semi sort of solution.
If I add a 1second delay after opening the ports and also a 1second delay before closing them, then it works.
This tells me that the <relays.waitForBytesWriten(-1)> does not work.
As far as I know this function is supposed to pause until all data has been written to the device. Can anybody maybe comment on this statement? -
- What is version of QtSerialPort?
- What is serial port type?
-
Hi kuzulis. Im not sure where to check the version number for QtSerialPort.
The Serial port is a RS232 device.Sierdzio. I implemented your above mentioned code.
No difference. The only thing I fount to work is if I add a 1sec delay after opening and before closing the port. -
2 achmed
bq.
Im not sure where to check the version number for QtSerialPort.From where you took the QtSerialPort?
bq. The Serial port is a RS232 device.
This is USB/Serial converter, on-board device or something else? What chip?
bq. The code bellow also displays corrupted data.
What do you see when do writing of relays.write("all_offx") ?
-
bq. They are all giving the same problem.
What is a problem? I repeat a question again: what do you see when do writing of relays.write(“all_offx”) on other side?
bq. Not sure where they got it from.
It is in your interests to know it. Without it further reasonings are senseless.
-
[quote author="kuzulis" date="1415359623"]What is a problem? I repeat a question again: what do you see when do writing of relays.write(“all_offx”) on other side?
[/quote]As Mentioned in the first post. The output data is corrupted.
Example: ^%$%^&*(
In Other words unreadable. -
This can not be in principle. Can you check same, but without closing of device?