Finding when data is present


Recommended Posts

For my optical tachometer, I am calculating RPM from the counter values. It works well, but I get an error (C1086) at the beginning. I think this is because I'm trying to calculate the RPM over a time of one second (to get reasonable resolution and speed), so until there's been a second of data collected, the calculation is trying to use data that doesn't exist.

I tried to solve the problem using the GetHistoryLength() function to ensure there was enough data before using it. Now I get a different error (C1000).

Here's my Event code from the Counter0 channel:

Var.blipsperrev = 3 // Use this to set the number of blips seen on for each revolution of the object

Var.deltaT = 1000 // Specify the number of milliseconds desired between RPM0 values (too short and resolution will suffer)

if (GetHistoryLength() < Var.deltaT) // If there's not enough data to see the count increase from it's start yet

RPM0.AddValue(0) // Then set RPM = 0

else // Otherwise calculate it correctly



Syntax error? Is there a better way?

After looking on the forum and knowledge base I tried the ignore(all) command as well, but that also didn't work (again I think I didn't know some nuance about how to write that code). I just put "ignore(all)" as the top line of that event code. Does it need to "system.ignore(all)" or something like that?



Link to comment
Share on other sites

The function you want is actually GetHistoryCount() and it is a function of the channel. Event code runs in the global namespace, so you still have to put the channel name in front. So you want:

if (Counter0.GetHistoryCount() < Var.DeltaT)

Better way? Not really, but I'm not sure why you are using variables, since you define them just before. Yes its good practice not to put magic numbers in your code, but you should use privates instead of globals then, or declare the globals outside the event. You are reexecuting the code that does nothing the way it is written.

Using ignore("all") instead of the if would work as well and actually would probably execute faster because the code will be shorter, but then you won't get 0 in RPM0 when you haven't collected enough.

As for ignore(), the all needs to be in quotes:


otherwise it is looking for a string channel named all.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.