LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Count Occurence of Strings

I think my loop is running at 0.1 seconds.

0 Kudos
Message 11 of 23
(1,580 Views)

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.

0 Kudos
Message 12 of 23
(1,576 Views)

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

0 Kudos
Message 13 of 23
(1,573 Views)

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

0 Kudos
Message 14 of 23
(1,570 Views)

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.

0 Kudos
Message 15 of 23
(1,562 Views)

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

0 Kudos
Message 16 of 23
(1,557 Views)
Message 17 of 23
(1,541 Views)

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.

 

Example_VI.png

0 Kudos
Message 18 of 23
(1,510 Views)

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

0 Kudos
Message 19 of 23
(1,483 Views)

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.

0 Kudos
Message 20 of 23
(1,478 Views)