LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Really challenging, Really Tough Array problem

Hi,
 
I'm working on a parsing problem. I need some help regarding storing numbers in a string to a arrays. I have a text file shown below,
 
TEXT FILE
-----------------------------
N1 G98 G12 G21
N2 G14 G34 M43
N3 G65 M10 T84
N4 G96 T02 M62 
-----------------------------
 
I want to store all numbers that appear after each G in Array1, numbers appearing after each M in Array2 and number appearing after each T in Array3 in such a manner as shown below,
 
ARRAY 1
 
   0         1       2       3        4      5      6     7      8
---------------------------------------------------------------
: 98   :  12   :  21   : 14   :  34  : 65  : 87 : 96  :  : 
---------------------------------------------------------------
 
ARRAY 2
  
   0         1       2        3        4      5      6     7      8
----------------------------------------------------------------
0    :    0   :   0    :   0    :  43  : 10  :  0  :  0  :   62 :
----------------------------------------------------------------
 
ARRAY 3
 
   0         1       2        3        4      5      6     7      8
----------------------------------------------------------------
:  0    :    0   :   0    :   0    :   0  :  84  :  0  : 02  :  0   :
----------------------------------------------------------------
 
Notice in the above arrays that when an M appears after the 4th G in the text file then the number after M has to be stored in the 4th element of Array2 and when T appears after the 7th G, then the 7th element of array2 is made 0 and 02 is put in the 7th element of array3, and so on..............  
0 Kudos
Message 1 of 17
(2,902 Views)
Just take each token string, split after the first character, convert the tail to a number and append to the appropriate array depending on the first character.
 
 
The attached example (LabVIEW 7.0) shows a simple implementation. See if it works for you. 🙂
Message 2 of 17
(2,903 Views)

Hi Altenbach,

Thanks a lot for the VI. Your VI has really helped me in my parsing project. You are too good. Now I'm almost done with the main part of my project. The whole credit goes to you.

We'll keep in touch.

Regards,

Giridhar Rajan

Automation Engineer

Cruiser Controls

Mumbai, India

0 Kudos
Message 3 of 17
(2,886 Views)

Hi Giridhar,

Have you noticed this thread?

 

http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=854&jump=true

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 17
(2,881 Views)

Hi Altenbach,

This is with reference to the VI (GMT.vi) that you made for me to seperate numbers appearing after each G, M and T from the following text file,

TEXT FILE
-----------------------------
N1 G98 G12 G21
N2 G14 G34 M43
N3 G65 M10 T84
N4 G96 T02 M62 
-----------------------------
It was really great. Now I want to add a bit more complexity to this VI. Now my text file looks like this,
 
 
TEXT FILE
-----------------------------
N1 G98 G12 G21
N2 G14 G00 X0 Y10 Z50 F100  M43
N3 G65 M10 T84
N4 G96 T02 M62 
-----------------------------
 
Notice the string X0 Y10 Z50 F100. I want to store all such strings that appear after each G00 till the next G,M or T appears on the text file to a string variable. After storing this string in a variable, I'll again apply technique in GMT.vi to seperate numbers appearing after X, Y, X and F. Please help me out with this. I have attached the VI below,
 
 
0 Kudos
Message 5 of 17
(2,844 Views)
Here's one simple possibility, maybe it is good enough for your purpose. (It will be a little bit more complicated if you want the exact string instead of the reassembled tokens).
0 Kudos
Message 6 of 17
(2,841 Views)
Hello sudhir,

I only want to make a comment, as Altenbach was faster:
Please do not include a case for every number from 0 to 100 if you only have 2 cases that do something. Use ranges of numbers and set a proper default case!


Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 17
(2,836 Views)

Thanks a lot GerdW for your suggestion. I've not yet added functions to those cases left empty. Keep in touch.

Bye

Regards,

Giridhar Rajan

Automation Engineer

Cruiser Controls,

Mumbai, India

0 Kudos
Message 8 of 17
(2,826 Views)

Hi Altenbach,

Thanks for the VI. Is there a way to obtain the string X0 Y0 Z0 F100 inside the case G0 instead of obtaining it outside the while loop. This is because I want to use that string in the Case 0 that runs inside Case G in runtime and feed the value after X, Y, Z and F to the axes of a motion control card.

Regards,

Giridhar Rajan

Automation Engineer,

Cruiser Controls,

Mumbai, India

0 Kudos
Message 9 of 17
(2,804 Views)
Hello sudhir,

that would have been my proposal:
in the G00 case put a "Search Pattern" with pattern [GMT] and search from the position after G00. This way you get the position of the next G,M or T token and so you have the  position (start,end) of the XYZ-string. Now  you can use this string to feed a "scan from string" with it - all inside the G00 case.


Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 17
(2,799 Views)