1
votes

I got a Licor CO2-Logger (Li-820) for a scientific experiment. The Li-820 outputs an analog signal (voltage) and also offers a serial communication via a RS232 port. I would like to sniff the serial communication with an arduino uno and display the CO2 values on a LCD display such that I can control the analog signal that is logged in a computer system. I want to display both the analog and the digital signal.

I use a rs232 level shifter to connect the Licor CO2 analyzer to the arduino uno and I can sniff the COM port successfully both with the arduino serial monitor and a sniffer program. Over the rs232 port the Li-820 device outputs an xml-like line that is as follows:

<li820><data><celltemp>5.1252350e1</celltemp><cellpres>9.7159633e1</cellpres><co2>5.2527637e2</co2><co2abs>7.7893261e-2</co2abs><ivolt>1.1386718e1</ivolt><raw>3950702,3808028</raw></data></li820>

I would like to parse that information for the relevant part with the arduino uno which is the "5.2527637e2" ("CO2" value) and first output it to the serial monitor. Next, I will display that value on a LCD display. This last step should be a minor problem.

So, how can I parse the information for the relevant bits and then display it to the serial monitor.

I looked into many examples on the net. A modified version of the working code from here (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287446626) and here (http://stackoverflow.com/questions/8370918/rs-232-communication-using-an-arduino-duemilanove-and-the-cutedigi-rs-232-interf) was the closest I got.

I am aware of some xml libraries for the arduino platform. However, I cannot access the xml line in the first place.

Any direct help or linkage to other sources of information is greatly appreciated. Please tell me in case that this is the wrong forum or that you need further information about my electronic/sofware problem.

REMARK: I already posted this on [electronics.stackexchange.com/] but some good folks there recommended me to post this question also here. Due to low reputation I could not migrate the question.

2

2 Answers

1
votes

While you could use a heavy (slow) regex or xml parser, I'd go with a simple solution. If the data line is consistent, then we simply need the data between the 7th ">" and the 8th "<".

int i = 0;
int start = -1;
int end = 0;

string data = "<li820><data><celltemp>5.1252350e1</celltemp><cellpres>9.7159633e1</cellpres><co2>5.2527637e2</co2><co2abs>7.7893261e-2</co2abs><ivolt>..."

string result = "";

for(i=0;i<7;i++)
{
     start = data.indexOf('>', start + 1 )
}
end = data.indexOf('<', start++);

result = data.substring(start, end - start);

Serial.print("co value = );
Serial.println(result);
1
votes

Not sure if the #include <regex> will work with the Arduino IDE, but here's a snippet that will help.

Also, as a disclaimer, I would suggest an XML parser, but I know if the IDE makes that available either and it seems like a lot of cpu overhead for the arduino.

Here's a good tut on the below code.

#include <regex>

using namespace std::tr1;

string seq = "<li820><data><celltemp>5.1252350e1</celltemp><cellpres>9.7159633e1</cellpres><co2>5.2527637e2</co2><co2abs>7.7893261e-2</co2abs><ivolt>1.1386718e1</ivolt><raw>3950702,3808028</raw></data></li820>";
regex rgx("(<co2>).*(<co2>)");
smatch result;
regex_search(seq, result, rgx);
for(size_t i=0; i<result.size(); ++i)
{
    //tinker with this to find the correct result index.
    cout << result[i] << endl;
}