LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search and replace string function

Sure, here it is... I have no idea why this works and the above version does not. please note I have changed the code to analyze the string direct from the while loop instead of putting it all in an array and using that...but if I reconnect this same code where the Globals exist, the same thing happens again, it will not remove the commas.

 

 

 

heres an example of a message that I recieve:

2007,05,15,11,50,53,001322,L3,159,401.68042,-73.2 db,FF,FE,2F,F1,4A,B7,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,00
 

Andrew

 

0 Kudos
Message 11 of 15
(845 Views)


@smercurio_fc wrote:

You can use the "Filter 1D Array" to filter out the message you're looking for, and simply compare array sizes:




smercurio_fc,

In the latest version (2.7) of the OpenG Array Tools library (oglib_array package), we have added support for wiring scalars into the "items to filter" input of Filter 1D Array.  This elliminates the need for the Build Array function, allowing you to wire your "5" string contant, directly as an input to Filter 1D Array.

Cheers,

-Jim
0 Kudos
Message 12 of 15
(830 Views)
Good to know that, Jim.

To poster: two words: race condition. That is what you have in your latest code. You have two independent pieces of code. One is the while loop that collects your messages. The other is the search/replace stuff. The  LabVIEW dataflow paradigm dictates that functions execute when data is available. This means that both sections will run at the same time since there's no execution priority between the writing of the global and the reading of it. Thus you can (and probably will) read from the global variable before you've written anything to it. Of course, the next time you run the VI you'll be reading data from the previous run.

That said, let's try to clarify a few things, because I have to admit that I'm still a little confused here, and perhaps I'm just dense today. First, be aware that the way you're performing the serial port reading is flawed:
  • You do not pass the error around the loop via a shift register, so if any iteration has an error it gets lost on the next iteration.
  • You do not close the VISA session when you're done.
  • You should probably be terminating the loop if you get a serial port read error.
  • You're wiring a constant of 200 to the VISA Read. The VISA Read will stop once it sees the termination character, which by default is linefeed. If there's nothing on the port you'll get a timeout. Since you're not passing out the error, you probably are getting a VISA timeout and not seeing it. Normally, you check to see how many bytes are available, and feed that to the VISA Read function.
That said, you said that you're reading each message from the receiver and building an array. You then want to flatten that array into one big long string using commas, delete the commas, and then perform a dummy replace by searching for a big long string to get some count. OK... You gave an example of a message that you receive:

2007,05,15,11,50,53,001322,L3,159,401.68042,-73.2 db,FF,FE,2F,F1,4A,B7,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,00

Is this an actual response that you got from the read loop, or something that you expect? What were your individual array elements from the output of the loop? If you want to take the individual array elements and make a big long string, and your individual array element contain message components separated by commas, then you need to specify a comma as the delimiter for the "Array to Spreadsheet String".

For example, let's say you get the following from your loop:
  first iteration:
2007,05,15,11
  second iteration:
50,53,001322,L3
  third iteration:
159,401.68042,-73.2 db

Then, in order to get
"2007,05,15,11,50,53,001322,L3,159,401.68042,-73.2 db", you have to specify a comma as the delimiter. Anything else, and you won't be able to properly do the last part, which is your dummy replace. Why? because if the big long sequence of "55" gets split across multiple reads, and it looks like you're using a space as the delimiter for the spreadsheet string you'll end up with something like "55,55,55 55,55,55" from two separate "55,55,55" reads. Searching for "55,55,55,55,55,55" will yield no matches.

Bottom line:
  • Fix the way you're doing the reading.
  • Specify a comma as the delimiter for the "Array to Spreadsheet String".
  • Eliminate the global variable as this is not necessary and incorrect the way you've implemented it.
Message 13 of 15
(813 Views)
I am sorry for the confusion,  I inexperienced at this and appriciate all of the help.  The reciever does not send any termination character, and the way to use it according to the manufacturer is to Open a port and it will spit out its latest reading, there is no flow control on the hardware end of it, and I can t read anything at all from the unit unless there has just been a transmission, otherwise the buffer is empty.  I will follow your advice and query for the bytes at the port and then read this instead of just leaving it open all the time.
 
The string that comes out from the reciever is
 
2007,05,15,11,50,53,001322,L3,159,401.68042,-73.2 db,FF,FE,2F,F1,4A,B7,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,00
 
Its just one huge string, the commas come from the reciever.  I could seperate it out, but I want to just have one big string anyways.  As to the race condition and the flow control, thats the whole reasoning for the post....the code I had to remove the commas won t remove the commas, unless I use the global function (that said I imagine what is really happening is just what you state, its using the last value written to the global so its not analyzing what is measured each time, rather the last time that the while loop was run.)  and I can t figure out why. 
 
so to sum up the problem if I make a while loop that acquires the above string and run it through the search and replace function it won t work.  But if I just send the code straight in from a previously saved point like a global or from a constant it works just fine.
 
Thanks everyone for the help and suggestions,
 
Andrew
0 Kudos
Message 14 of 15
(801 Views)


@labstew wrote:
The string that comes out from the reciever is
 
2007,05,15,11,50,53,001322,L3,159,401.68042,-73.2 db,FF,FE,2F,F1,4A,B7,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,00

Instead of doing all that odd search/replace stuff, you should just feed this string to "Spreadsheet string to array", using a 1D DBL array as default type and comma a delimiter. You'll get an array of all numbers that you later can trim down using array subset. You can get any individual elements using index array.
Message 15 of 15
(791 Views)