LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parsing strings in loop

Hi, I have message coming from a microcontroler through serial port, and i am using VISA to read it. It has 6 byte Header and then 28 byte data. This sequence continues. Header is in ascii format and data in hex with MSB, LSB sequence for 14channels. I want to search header on message and on matching the header extract the next 28 byte data and convert it in 14 words with first two bytes as cor channel 1 and so on.
 
i am feeding the data to match pattern module and taking the before match string data. After that i want to flush these before, match and after fields and feed the previous after field to the input of same match pattern function, so i can parse the next set of 28 byte data from message. But i am unable to flush the fields and put it in a loop.
 
here is how my message looks like.
 
234523HEADER233423754F083A2368723C2A4F82HEADER43242F757F083B23F8753C2A4C25HEADER............( SO ON IT KEEPS ON REPEATING)
 
starting 234523 can be trashed but next 233423754F083A2368723C2A4F82 needs to be converted in 14 words and stored and then same for next 28 bytes after next HEADER and so on.
 
Any help is appreciated,
 
thanks, Avi


Message Edited by Mathur on 08-11-2008 02:30 PM
0 Kudos
Message 1 of 10
(3,700 Views)
Two simple ideas:
  1. Use "spreadsheet string to array" with "HEADER" as delimiter and a 1D array of strings as type.
  2. Use "scan strings for tokens" with "HEADER" as delimiter and built an array of strings.
  3. disregard short strings.


Message Edited by altenbach on 08-11-2008 12:38 PM
Message 2 of 10
(3,690 Views)

thanks for ur reply, i tried to use spreadsheet string to array and it works, but i am facing diff probem now. In my block diagram there is another data acquition running at 100samples/sec where as the serial port is running at 10 samples/sec. i have to run them in same loop. So on making loop time as 10msec i am just getting partial parsed string. I tried to use shift registers to concatinate it but i guess i am doing something wrong.  What i am trying to do is show the whole parsed string once and then show blank spaces other time to sinchronize the fast DAC with slow SERIAL PORT.

 

Second after parsing in array i want to convert it in word. e.g.    00502800002010000050280000201000005028000020100000502800     if this is the first index array i would like to take 0050(it is in HEX) and make it 80 in DEC. then take 2800 in hex and make it 10240 in dec and so on thus giving me 14 dec values. Using string number conversion pallet doesnt help.

 

Please suggest me some ideas,

 

Thanks

0 Kudos
Message 3 of 10
(3,651 Views)

You could place your serial code inside a case structure that only turns true every 10th iteration. Simply divide the iteration count by 10 using "quotient&remainder" and wire "remainder" to the case terminal. Place the serial code in case "0" and make the empty case the default.

 

A better opntion would be to retain incomplete tails from each parsing operation and then prepend it to the newly received string so you don't need to discard split tokens.

0 Kudos
Message 4 of 10
(3,643 Views)

Hi Mathur,

 

you can try TypeCasting the string to an U16 array...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(3,641 Views)

Mathur wrote:

Second after parsing in array i want to convert it in word. e.g.    00502800002010000050280000201000005028000020100000502800     if this is the first index array i would like to take 0050(it is in HEX) and make it 80 in DEC. then take 2800 in hex and make it 10240 in dec and so on thus giving me 14 dec values. Using string number conversion pallet doesnt help.


Just to be a bit more clear, Gerd's answer relates to your second question (quoted above). Notice that you simply get an array of 14 U16 numeric values. (decimal" is only a cosmetic property of the indicator and has no bearing on the underlying data.)

0 Kudos
Message 6 of 10
(3,633 Views)

Hi, thanks for your replies but i guess i am stuck again at stage 1. On running my program with 100ms time wait i am getting little strange representation in my array.

 

It looks like this

 

00
005028000020100000
005028000020100000
0050280000201000005028000020100000
0050280000201000005028000020100000
005028000020100000502800002010000050280000
00502800002010000050280000201000005028000020100000
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00
0050280000
00502800002010000050280000
00502800002010000050280000
0050280000201000005028000020100000
005028000020100000502800002010000050280000
00502800002010000050280000201000005028000020100000
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800
00502800002010000050280000201000005028000020100000502800

 

it just keeps on repeating this sequence.

 

i think it is the buffer problem as before it gets filled i am parsing it and on increasing my wait time to 1000ms it gets little better but i can't afford to increase that. Actually i want to decrease the wait time to 10msec. But then i hardly get any data before it parses. I was just wondering if their is any other way to read serial port or any way i can fix my prog. This is my first prog in lab view and I appreciate your help. i am attaching my prog with this. Kindly let me know any suggestions or changes.

0 Kudos
Message 7 of 10
(3,610 Views)

As I said, you need to accumulate the data in a shift register and only parse once you have sufficient bytes. and keep the leftover tails for the next parsing operation.

 

In addition, to avoid all these small chunks, you could activate the case if "bytes at port" is larger than a certain amount instead of every time it is not zero.

0 Kudos
Message 8 of 10
(3,599 Views)

Thanks for reply. I am now able to parse the data and see it in desired form.

 

I am trying to read voltage from ueiDAQ (Data Acquisition) card using LABVIEW. These cards are in my comp as PCI cards. Also i have installed the drivers for Windows from uei website. I was just wondering how can i do that. I tried to use MAX but couldnt understand it.

 

Thanks,

 

Avi

0 Kudos
Message 9 of 10
(3,553 Views)

Mathur wrote:

I am trying to read voltage from ueiDAQ (Data Acquisition) card using LABVIEW. These cards are in my comp as PCI cards. Also i have installed the drivers for Windows from uei website. I was just wondering how can i do that. I tried to use MAX but couldnt understand it.


 

 Since this is now an unrelated question about hardware, you should probably start a new thread over in the Multifunction DAQ forum.

0 Kudos
Message 10 of 10
(3,545 Views)