# LabVIEW

cancel
Showing results for
Did you mean:

## Re: Count Occurence of Strings

I think my loop is running at 0.1 seconds.

Message 11 of 23
(883 Views)

## Re: Count Occurence of Strings

Probing the value coming out of the subtraction after the feedback node will tell you the exact loop time.  You can even plop down a waveform chart like I did to see how the value changes over time.

Message 12 of 23
(879 Views)

## Re: Count Occurence of Strings

The probe said it was alternating between 0,1, and 2, not neccesarily in that order.

Message 13 of 23
(876 Views)

## Re: Count Occurence of Strings

Attahced is a screenshot of the probe. Number 11 was alternating between like 1000, 500 and Inf.

Message 14 of 23
(873 Views)

## Re: Count Occurence of Strings

Then that makes total sense and is exactly what RavensFan described.  Your loop is running at 0ms, 1ms, or 2ms.  Notice how your probe has E-3 that means 1 * 10^-3.  99% of the time you get 0 messages in 1ms which is dividing by 0 which is where INF comes from.  Some times you get 1 message in 1ms.  If you get one message in 1ms then you are getting 1000 messages in one second.  You are going to need more logic to track the number of messages, over a longer period of time, or slow down your loop rate, which I'm guessing you don't want to do because it is used in a messenging scheme.  Maybe this would be a good place for an action engine, or functional global which can add new messages as it sees them.

Message 15 of 23
(865 Views)

## Re: Count Occurence of Strings

Ok, all this logic is in a case structure. Can you change the time for a case structure?

And I've never done anything with an action engine?

Thanks,

SM

Message 16 of 23
(860 Views)

Message 17 of 23
(844 Views)

## Re: Count Occurence of Strings

Here is an example using the other technique I mentioned.  Basically we keep track of how many As we see as we go along, and then once a second we reset the number back to 0.  There are still a couple of flaws with this design.  In my case I'm just looking for A which is a single character.  You might be looking for a series of characters, and if your message comes in, but cuts the message into two pieces, then this code detecting the start of the message might not be all there at once.  More logic could be written fix this but it probably isn't an issue for a small message like "10".  The action engine approach is a good one if you have time to learn about it.

Message 18 of 23
(813 Views)

## Re: Count Occurence of Strings

So yes I am in a time crunch and really don't have time to learn about the action engine stuff, although I certainly will read through it when I have the time.

Hooovahh, what would I need to change in the code you just posted to be able to check for a space at the beginning of the string. I can just have the robot send the strings with a space at the beginning so it'll be easier to detect an incoming string.

Thanks,

SM

Message 19 of 23
(786 Views)

## Re: Count Occurence of Strings

Well does the string start with a return character and then a space?  If so then that is what you would search for instead of "A".  You can just use a space instead of A but then you'll find all spaces, and since I don't know the typical strings you will see I can't say for sure if that would find other spaces that aren't the start of your message.

Message 20 of 23
(781 Views)