From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract data and write into three columns

I have a system that receives data using GSM. It's a data from solid waste management system's Garbage Bin that informs when it has been emptied.

 

Below is the data received for when the bin gets full and for when the bin gets emptied.

 

\r\n+CMTI:\s"SM",1\r\nInCommingMassage[0]\s=\sCInCommingMassage[1]\s=\sMInCommingMassage[2]\s=\sTInCommingMassage[3]\s=\sIInCommingMassage[4]\s=\s:InCommingMassage[5]\s=\s\sInCommingMassage[6]\s=\s"InCommingMassage[7]\s=\sSInCommingMassage[8]\s=\sMInCommingMassage[9]\s=\s"InCommingMassage[10]\s=\s,InCommingMassage[11]\s=\s1AT+CMGR=1\r\r\n+CMGR:\s"REC\sUNREAD","+918460676836",,"15/03/18,00:49:52+22"\r\n*#Sb@!\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\r\n\r\nOK\r\nNumber\s=\sGR:\s"REC\sU*#Sb@!\s\s\s\s\s\s\s\s\s\sMassage\s=\s*#Sb@!\s\s\s\s\s\s\s\s\s\sAT\r\r\nOK\r\nAT\r\r\nOK\r\nAT+CMGF=1\r\r\nOK\r\nAT+CSCS="GSM"\r\r\nOK\r\nAT+CMGS="8866774133"\r\r\n>\sDustbin\sNo\s251\sFull,\sKindly\scollect\sthe\sgarbage\r\n+CMGS:\s46\r\n\r\nOK\r\nInCommingMassage[0]\s=\sCInCommingMassage[1]\s=\sMInCommingMassage[2]\s=\sGInCommingMassage[3]\s=\sSInCommingMassage[4]\s=\s:InCommingMassage[5]\s=\s\sInCommingMassage[6]\s=\s4InCommingMassage[7]\s=\s6InCommingMassage[8]\s=\s\rInCommingMassage[9]\r\nERROR\r\n\s=\s\nInCommingMassage[10]\s=\s\rInCommingMassage[\r\nERROR\r\n11]\s=\s\n\r\n+CMTI:\s"SM",2\r\nInCommingMassage[0]\s=\sCInCommingMassage[1]\s=\sMInCommingMassage[2]\s=\sTInCommingMassage[3]\s=\sIInCommingMassage[4]\s=\s:InCommingMassage[5]\s=\s\sInCommingMassage[6]\s=\s"InCommingMassage[7]\s=\sSInCommingMassage[8]\s=\sMInCommingMassage[9]\s=\s"InCommingMassage[10]\s=\s,InCommingMassage[11]\s=\s2AT+CMGR=2\r\r\n+CMGR:\s"REC\sUNREAD","+918460676836",,"15/03/18,00:50:33+22"\r\n!$@1400712094D1b\s\s\s\s\s\s\s\s\s\s\r\n\r\nOK\r\nNumber\s=\sGR:\s"REC\sU!$@1400712094D1bMassage\s=\s!$@1400712094D1b\02b\03\t\04GJ06\s3333\05\t\060:50:21\s18-3-15\07

 

From the above data, I want to extract the underlined data. The data between \02 and \03 in the first column, that between \04 and \05 in the second column, and that between \06 and \07 in the third column of an excel file. The system receives data whenever there's "empty" and "full" activity at the garbage bin. The following data that follows the previous one should be written into a different row. 

 

I've attached the VI I'm using to read the Serial RS232 data.

0 Kudos
Message 1 of 11
(2,979 Views)

Hi maulin

 

Use "match pattern" with "regular expression" equal to "\02" to find the begining of the requierd string then again use it for "\03" to find data between "\02" and "\03" and so on...

 

Kudos are appreciated

Regards

V.S

Message 2 of 11
(2,969 Views)

Match Regular Expression.vi is probably the best choice in this case. You can then use Write To Spreadsheet File.vi to write to a .csv text file that can be open by Excel.

 

Ben64

 

using match regular expression.png

Message 3 of 11
(2,956 Views)

Thank you V.V. and Ben64! It worked. But, it just detects once. Take for example, it has already read /02a/03/04GJDN1111/05/0612:00 18/03/2015/07

When the date changes to for eg: /02b/03/04GJDN1221/05/0613:00 18/03/2015/07 it doesn't show. Also It's not writing to a .csv file. I first converted it to an 1D array then gave the i/p to Write to Spreadsheet.

0 Kudos
Message 4 of 11
(2,925 Views)

You have to loop until the end of the string to find all matches.

 

Ben64

 

Data To csv.png

Message 5 of 11
(2,920 Views)

I did try that. I even tried giving a feedback loop from past offset to offset, but it just began blinking all the values. Also,why isn't it writing to a CSV file? I coonnected it the same way as you've. The spreadsheet stays blank. Smiley Sad

0 Kudos
Message 6 of 11
(2,909 Views)

One thing you can try:

 

1- right-click on the string constant \02(.*)\03.*\04(.*)\05.*\06(.*)\07

2- select '\' Codes Display. The string should now appear as \\02(.*)\\03.*\\04(.*)\\05.*\\06(.*)\\07

3- Still in Codes Display modify it to  \02(.*)\03.*\04(.*)\05.*\06(.*)\07

 

Ben64

Message 7 of 11
(2,896 Views)

Almost done! Now it's writing to the spreadsheet continuously rather than writing the data just once.

0 Kudos
Message 8 of 11
(2,867 Views)

@maulin wrote:

Almost done! Now it's writing to the spreadsheet continuously rather than writing the data just once.


So your initial question is solved.

 

It is writing continuously because of this:

ScreenShot015.png

 

Even if a new read return an empty string you concatenate it with the the previous one. It is not the terminal content that you should pass to the while loop but only wire the string from frame 1. Also put the loop in a case structure an execute it only if the string is non-empty.

 

Ben64

0 Kudos
Message 9 of 11
(2,861 Views)

Yep. Initial query got solved. Thank you. But didn't know that I was going to encounter this new thing. Actually, I'm confused. I found this hyper terminal emulator online. I modified it according to my needs, but, now I don't know where it's receiving the first frame.

0 Kudos
Message 10 of 11
(2,855 Views)