Problem with data read from USB port
-
the problem is here:
serialBuffer += QString::fromStdString(serialData.toStdString());
how does your sensor encode the data?
-
@VRonin The sensor is based on capacitive technology. Any change in capacitance gives corresponding values.
@pj0909 said in Problem with data read from USB port:
values
This still does not answer my question. how are those values represented in binary format to the serial output? is it a 32 bit integer, a 64 bit double precision float, an ASCII encoded string?
-
@pj0909 said in Problem with data read from USB port:
values
This still does not answer my question. how are those values represented in binary format to the serial output? is it a 32 bit integer, a 64 bit double precision float, an ASCII encoded string?
-
@VRonin Sorry, I misinterpreted your question. The answer to your question is 64 bit double precision float.
@pj0909 Then you should use http://doc.qt.io/qt-5/qbytearray.html#toDouble without converting to string:
bool ok = false; serialBuffer += sensor->readAll().toDouble(&ok); if (!ok) // error
-
To add to @jsulm, you should also check that
serialData
contains 64 and only 64 bits of data (i.e.serialData.size()==8
) otherwise use QDataStreamvoid Dialog::readSerial() { QDataStream sensorStream(sensor); QVector<double> readValues; for(;;){ sensorStream.startTransaction(); double readValue=0; sensorStream >> readValue; if(sensorStream.commitTransaction()) readValues.push_back(readValue); else break; } qDebug() << "data read: " << readValues; }
P.S.
If your sensor sends the data in little endian order, you'll have to set the QDataStream byte order http://doc.qt.io/qt-5/qdatastream.html#setByteOrder -
@VRonin Sorry, I misinterpreted your question. The answer to your question is 64 bit double precision float.
@pj0909 said in Problem with data read from USB port:
The answer to your question is 64 bit double precision float.
Then you need to read the data as binary, not as text! Something like this (warning: the code isn't really portable):
QDataStream in(&serialData, QIODevice::ReadOnly); double value; in >> value;
-
Hi all!
I have the same problem, I need to communicate with a USB card reader, but I don't recognize it when i plug it with my PC ( Win 7)
serialportinfo.hasProductIdentifier() and serialportinfo.hasVendorIdentifier() all return false;
Who can help me? Thanks! -
What's relation between the serial ports and the USB card readers?
-
Reader Card connect directly to the computer using the USB port
Are there any libraries supporting this?
Thanks!