Click here to Skip to main content
12,354,122 members (70,759 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C Visual-Studio
i have the information as shown below.
I have to parse the DATA PART that i will get from a machine and fill the values like Rinse mode,status of machine....
I will get data on Com Port,i have to do it in c++.
I have written the code to open the com port and send Data demand(command).
Can anyone help me to suggest how to do the parsing?


Data format
・ All data isASCII character code without checksumand CR.
・ Range ofMachineNumber start from0000 to 9999
・ If there is no top digit at data part, itwill be zero suppression and put space to fill it.
・ Calculate sum total from top till before checksum (1bite unit), then recognize this
complement of 1 as checksum.
・ Finish of format isCR Hexadecimal: OD


Data demand(command)
   CM”      “00”         Checksum       CR
(2 bite)   (2 bite)


Monitor data(response)
“RE”              “00”          MachineNumber    Data part
(2 bite)         (2 bite)         4bite            128 byte

Parameter              Data          byte               Unit              Status
Status of machine       #             1
Rinsemode               #             1
Bypass                  #             1
Dialysate flow         ###            3                      
Treated blood volume  ##.##           5  
W+B conductivity       ##.#           4  
Posted 30-Aug-12 0:54am
Comments
pasztorpisti 30-Aug-12 8:02am
   
Bite? That data structure seems to be quite aggressive...

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Create a structure consisting of all data items in the response, with the correct field sizes. You can then read the response into this structure, and pick out any of its data items.

HTH
  Permalink  
Comments
Tarun Batra 30-Aug-12 8:06am
   
Thanks for the reply sir...i have some doubts please explain them when i will get data how to reach the data part,as u can see in Monitor data(response) we have 6bytes before the data part start.
ChandraRam 30-Aug-12 8:10am
   
Create your data structure to include the _complete_ response (including the "header" information), even if you do not want to use them further.

So, your structure should start with:
Type - 2 bytes (to store the "RE")
Flag - 2 bytes (not sure what this data is since you do not mention that)
MachineNumber - 2 bytes
Status - 1 byte
....
and so on.

HTH
Tarun Batra 30-Aug-12 8:15am
   
Sir as all the info i have i have put it in the ques,according to "Data format" what do u think all data will be in ASCII Format? How will i take data in "Treated blood volume" as it is 5 bytes,sorry for silly ques i am a newbie and never done parsing before....
ChandraRam 30-Aug-12 8:17am
   
I have no idea what your data is like - you mention in your question that it is all ASCII, so it should be a matter of just reading it as strings, right? Why don't you put it into the structure and read it to see what you actually get?
Tarun Batra 30-Aug-12 8:30am
   
Sir i am confused how to take 5 byte data can u just tell through pseudo code?
ChandraRam 30-Aug-12 8:31am
   
You said it is stored as ASCII, right? If so, just create a string of the specified length and you should have it?
Tarun Batra 30-Aug-12 8:37am
   
sir can write a pseudo code for better explanation?
ChandraRam 30-Aug-12 8:40am
   
Have you managed to create the structure? Do you know how to create structures that hold strings (characters)? If yes, post what you have done here and I will attempt to go from there...
Tarun Batra 30-Aug-12 8:47am
   
struct parse
{
char Status of machine[2];
char Rinsemode[2];
char Treated blood volume[6];
}p;
ChandraRam 30-Aug-12 8:49am
   
Right. What happened to the header info? The first 6 bytes? If that is part of each response, you need to have that in the structure as well... as I told you right at the beginning :)
Tarun Batra 30-Aug-12 8:51am
   
struct parse
{
char RE[3];
char o[3];
char mc_no[5];
char Status of machine[2];
char Rinsemode[2];
char Treated blood volume[6];
}p;
Now can u explain how to take five byte data?
ChandraRam 30-Aug-12 8:55am
   
Why do you have one byte extra for each field? "RE" is just 2 char, right? Similarly for all the fields...

After fixing this (and getting it to compile ;), if, as you say the data is ASCII, then parse->TreatedBloodVolume should give you the value in a string. Like so - "10.20", for instance.
Tarun Batra 30-Aug-12 9:00am
   
sir i thing u didn't get me,what to assign to "parse->TreatedBloodVolume =???",the data should come from the DATA PART of the packet
ChandraRam 30-Aug-12 9:03am
   
Well, I think you haven't understood me at all... The response data is coming from a COM port, right? I have been asking you to read the response directly into your structure.
Tarun Batra 30-Aug-12 9:27am
   
well let me try i will ask u again,will it be ok...should i ask here or on your mail id?
ChandraRam 30-Aug-12 9:32am
   
You do that - and please post here...
Tarun Batra 31-Aug-12 8:38am
   
sir i did some what work can we discus?
ChandraRam 31-Aug-12 14:22pm
   
Sure - post what you have done so far.
Tarun Batra 3-Sep-12 2:34am
   
Sir please check the solution
Tarun Batra 30-Aug-12 9:34am
   
sure sir thanks for the help.....

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100