[SOLVED] QtSerialPort - Need general information on what I'm reading
I'm working with a Bluetooth device (pulsioximeter) that uses Serial Port to send data.
"This Qt SerialPort/Terminal Example":http://doc.qt.io/qt-5/qtserialport-terminal-example.html is 100% working (I love these QtExample, you can start working without any problem when compiling and they are well written).
The problem that I'm facing is shown in this image:
!http://s23.postimg.org/icvidy1iz/spo2.jpg(Image of output)!
Everything seems working fine (I can see the text changing, maybe according to heart-rate; I can see a different output when the finger is not in the pulsioximeter, etc..), but I would like to know how to decode that text.
Device manufacture provided all technical info (that I'm already using correctly): no parity, 115200 boud rate, 1 stop bit, 8 data bits
And a table with details of the datagram.
#BIT0-3: signal strength
#BIT5: no finger inside boolean
BYTE 2 - 3 - 4 - 5 -6 - 7
(description for 8 bits, on of each byte)
So, I would expect to read a binary code (and then coding what I need, converting to heart.rate numbers). How can I do this?
The example uses this code:
@ QByteArray data = serial->readAll();
Rondog last edited by
Maybe something like this:
static const int SIGNAL_MASK = 0x0f; // bit 0-3
static const int FINGER_MASK = 0x20; // bit 5
char data_byte = byte_array_input.at(?); // see QByteArray help
int signal = data_byte & SIGNAL_MASK;
bool finger = (data_byte & FINGER_MASK);
QString text = QString("Signal: %1 Finger: %2").arg(signal).arg(finger);
Thank you for your help. This clarified the basic ideas.
It seems working (not with SIGNAL for example, but working with other parameters using the right mask. I have to spend a bit of time on each value).
I'll post the full code for decoding the serial input from my device (posting manufacture and model) as soon as I manage to read all the fields, so that someone can buy the same Pulse Oximeter (it is cheap!).
Here is the Bluetooth Pulse Oximeter that I'm using:
"Buy here":http://www.dx.com/p/bluetooth-fingertip-pulse-oximeter-orange-white-2-x-aaa-258859#.VLE3l8YcFzE (sorry for the link, I don't want to advertise that store, just in order to provide a link to the real product).
Manufacter: "Berry Med":http://www.berry-med.com
Specifications: "Your text to link here...":https://drive.google.com/file/d/0B5UmFnLqxqi4S3hMZmk0YjFVSWs/view?usp=sharing
I can pair it with Windows and MacOSX correctly.
I suggest this device if you are looking for something that can stream "live" the HeartRate and Blood Saturation to your computer wireless (it is the cheaper Bluetooth Pulse Oximeter that I found around. Requires 2 AAA batteries, Cons: it doesn't have an LCD display).
You can use this code in any project or starting from Qt/Serial/Terminal example (in readData part) or Qt/Serial/slave example (in readRequest part).
// all variables are int or bool
//I prefer to explicit (#numberOfByte - 1) since the Table from manufacter starts counting from 1
signal = (data.at(1-1) & 0x0f); // Mask Bits 0-3 (00001111) of #numberOfByte 1
signalBool = (data.at(1-1) & 0x10);
bargraph = (data.at(3-1) & 0x0f); // Mask Bits 0-3 (00001111) of #numberOfByte 3
saturation = (data.at(5-1) & 0x7F); // Mask Bits 0-6 (01111111) of #numberOfByte 5
pulserate = ((data.at(3-1) & 0x40)) | ((data.at(4-1) & 0x7F));
// Mask Bit 6 (01000000) of #numberOfByte 3 and shift it in Bit 7 position (10000000)
// Mask Bits 0-6 (01111111) of #numberOfByte 4
// Build the 0-7 Bits using OR (not 100% sure about this, please write me back if you think it is wrong)
pleth = (data.at(2-1) & 0x7F); // Mask Bits 0-6 (01111111) of #numberOfByte 2
sensorOn = !(data.at(3-1) & 0x10); // Mask Bit 4 (00010000) of #numberOfByte 3
// can be used to detect if finger is in. Go to 0 if no finger inside
stablePulse = !(data.at(3-1) & 0x20); // Mask Bit 5 (00100000) of #numberOfByte 3
// Is 1 when the pulse detection is stabilized. Go to 0 when detection is not ready yet
pulseBeep = (data.at(1-1) & 0x40);
SysTech last edited by
Cool little device. I'll check it out! Thanks for posting the info. If your issue is solved please edit your initial post and change the title to include [SOLVED].
That is something that helps here on the forums.