Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I have a pulse oximetry device which communicate via bluetooth
my c++ program can connect it via COM3, and tries to retrieve its data(pulse rate and oxygen sat.)
but the data format of device is confused. here is the remark of data format:

The 9560 includes 6 bytes of header information, a minimum of 14 bytes of spot-check data, and 2 bytes of footer information.

To determine the total length for the expandable Spot-check data, the host must capture the data length from bytes 5 and 6 of the header.

With the minimum data length of 14, the data length defined in bytes 5 and 6 will be
(0x00) (0x0E) (14 bytes decimal).

The Spot-check data consists of – time of spot-check, SpO2, Pulse Rate, and status.

            Byte#  Data               Information                        Format
            1       00                 NULL start                         Hex
            2       02                 STX – start of pocket               Hex
Header      3       00                 Packet type MSB                    Hex
            4       0D                 Packet type LSB                    Hex
            5       00                 *Data Length MSB (variable)        Hex
            6       0E                 *Data Length LSB (variable)        Hex

            7       20                 Hundredths place of Year           BCD
            8  Year of Measurement     Year of Measurement                BCD
            9  Month of Measurement    Month of Measurement               BCD
            10 Day of Measurement      Day of Measurement                 BCD
            11 Hour of Measurement     Hour of Measurement (00-23)        BCD
expandable  12 Minute of Measurement   Minute of Measurement (00-59)      BCD
Spot-check  13 Second of Measurement   Second of Measurement (00-59)      BCD
data        14 00                      Fraction of second                 BCD
            15 STATUS MSB              See STATUS specification below     Hex
            16 STATUS LSB              See STATUS specification below     Hex
            17 Pulse Rate MSB          See HR format below                Hex
            18 Pulse Rate LSB          See HR format below                Hex
            19 00 to FF                Reserved for future use            Hex
            20 SpO2                    See SpO2 format below              Hex

footer      21 Checksum LSB           LSB of sum Footer of Spot-check Data    Hex
            22 03                     ETX – end of transmission             Hex


part of my code:
C++
        char buf[22];

DWORD read = 0;


if (ReadFile(comport,&buf,22,&read,NULL)){

    DWORD i;

    for(i=0;i<read;i++){
        printf(" %d\n", (unsigned char)buf[i]);
    }
    printf("\n");

}else {printf("cannot read...");}


I get output like this:
1 128 112 0 241 1 128 112 98 83 1 128 111 147 131 1 128 111 0 240 1 128

Could you please help me how to read and print data in correct format
thanks

i open the port with:
C++
if ((comport = CreateFile("\\\\.\\COM3",                // open com3:
                GENERIC_READ | GENERIC_WRITE, // for reading and writing
                0,                            // exclusive access
                NULL,                         // no security attributes
                OPEN_EXISTING,
                0,
                0)) == INVALID_HANDLE_VALUE)
{
    printf("cannot open the port\n");
}
Posted
Updated 29-Mar-11 2:18am
v5
Comments
Fredrik Bornander 29-Mar-11 4:48am    
How do you open your comport handle? That data doesn't look right at all.
Manfred Rudolf Bihy 29-Mar-11 7:30am    
Do you own one of these devices or are you doing this for work?
I was thinking of sprucing up an app for a mobile device that currently tracks my biking and hiking routes via GPS with a little bio metric information. Pulse and oxygen saturation seem to be some nifty parameters I'd also like to record. Do you know how much this device costs?
mstftrn 29-Mar-11 8:07am    
we bought it for a project
it is about 450 dollars
nonin 9560 pulse oximeter
Manfred Rudolf Bihy 29-Mar-11 10:07am    
Wow, 450 is a pretty steep price since I only intended to use it for recreational purposes.
Thanks for the information though. :)

If you read the documentation[^] carefully you'll find that there are different data formats that can be requested per command sent from the master to the device. From your data I can sense that the selected data format is "Data format 2. – provides real-time oximetry measurements with compressed waveform (8 bit waveform) every 1/75th of a second".

See page 8 of the documentation I linked to above and you'll see that your data seems to be exactly in that format.

Best Regards,
 
Share this answer
 
v2
Comments
mstftrn 29-Mar-11 8:12am    
exactly...
i ll try this and inform you
thank you all
mstftrn 29-Mar-11 9:11am    
i added
BYTE dataFormat[6]={0x02,0x70,0x02,0x02,0x02,0x03};
DWORD write = 0;
if (WriteFile (comport, &dataFormat, 6, &write, NULL)){
printf("Data format has changed to 2...\n");
}else {
DWORD dwError = GetLastError();
printf("Error %d\n", dwError);
}

everything is okay now
thank you...
Manfred Rudolf Bihy 29-Mar-11 10:06am    
That's great! I'm glad you got it right.
Sergey Alexandrovich Kryukov 29-Mar-11 13:18pm    
Great effort, my 5.
--SA
You specified a lot of detail but as I understand, you have the correct data and the question is just how to print your numbers as hex?
In this case the solution is as simple as changing your printf's %d to %x.
 
Share this answer
 
Comments
mstftrn 29-Mar-11 4:52am    
i tried that but no luck,
i think there is smt wrong with the way getting data...
[no name] 29-Mar-11 5:27am    
In your ReadFile call, buf is already a pointer so you can pass buf instead of &buf.
mstftrn 29-Mar-11 5:38am    
unfortunately nothing changed...
[no name] 29-Mar-11 5:53am    
What do you mean with nothing has changed? The output is still exactly the same after you change
ReadFile(comport,&buf,22,&read,NULL)
to
ReadFile(comport,buf,22,&read,NULL)?
mstftrn 29-Mar-11 5:59am    
a sorry
i mean i get output resembles the one above
smt like 1 130 90 etc
Try this

C++
unsigned char buf[22];
DWORD read = 0;

if (ReadFile(comport, buf, 22, &read, NULL))
{
    DWORD i;
    for(i=0; i < read; i++)
    {
        printf(" %X", buf[i]);
    }
    printf("\n");
}
else
{
    DWORD dwError = GetLastError();
    printf("Error %d\n", dwError);
}

If your read fails you should be able to see the reason why.
 
Share this answer
 
Comments
[no name] 29-Mar-11 5:56am    
This is definitely a good idea, but in this case I think the ReadFile call didn't fail because the numbers did get printf'd.
mstftrn 29-Mar-11 6:07am    
i got
1 FFFFFF80 4B 4B 17 1 FFFFFF80 4B FFFFFF93 5F etc.
most probably there are ngative values FFFFFF80 (you omitted unsigned part)
one point more:
it is also strange that the output repeats itself for every 5 index.
there should be 22 nearly different values
[no name] 29-Mar-11 6:27am    
Since you do get the values printed on the screen, it would appear that both opening the port and reading data from it is succesful.
Can you verify (maybe with 3rd party tool to read from your COM port) that this is indeed not the data which is sent by your device? Maybe you are supposed to send some bytes to the device first to initialise the connection (this is a guess, it would be in the documentation of the device) and only then you start receiving data in the format you are expecting?
Richard MacCutchan 29-Mar-11 9:05am    
No I think you omitted the unsigned part, it all printed correctly for me.
mstftrn 29-Mar-11 8:09am    
yes a used hercules and putty for the issue and see constant data output stream with stange characters like £$ <ß ı ö%/ ^+5 etc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900