08-11-2017 03:56 PM
Hello,
I'm trying to get my code to take a picture of my graphs every time a certain value is exceeded. My code works beautifully.... except that it doesn't stop taking pictures and I can't seem to figure out why.
Does anyone have any ideas as to what is causing my event structure to continuously loop?
Solved! Go to Solution.
08-11-2017 04:09 PM
This is not the right way to do this! You are using Value-signaling to get the Graph scaler to run (once) whenever some events in your sampling loop are true -- an artificial way to communicate between the A/D DAQ loop and the Graph Scale Controls loop.
I don't know how fast your DAQ loop runs, but I notice that your V Drop event takes at least 10 seconds. Let's say that your DAQ loop runs once/second for a minute, and that half the time, V Drop is signaled. So after a minute, you will have enqueued 30 x 10 second V Drop Events, so the loop will take 5 minutes to finish. Is this what you want?
I'm guessing not. You may want to re-think your logic, what you really want to do, and when you want to do it.
Bob Schor
08-11-2017 04:18 PM
Bob,
That's a good point! And it explains why it appears to be an endless loop. Unfortunately I'm using a DAQ (recommended by NI) that has a minimum sampling rate of ~1600 samples/sec. Perhaps if I increase my loop size to a few seconds or two, my problem will be solved.
I'll check the buffer of the daq to make sure i don't exceed its limit... & let you know if that solves the problem.
Thanks!
08-11-2017 04:31 PM
No, that's not the solution -- the solution is don't use a queue (which "remembers"), but possibly a Notifier (which only remembers the last value. Make yourself a separate loop that "does what you want when you tell it to do so" and feed it the Wait on Notification -- until you Notify it (in your DAQ loop), it will consume no CPU time, but when you say "OK, do something", it will do it (once). It only "remembers" the "latest" signal.
Bob Schor
08-11-2017 05:26 PM - edited 08-11-2017 05:27 PM
Thanks for the advice! I've only had bad luck with notifiers so I'll likely use a channel writer instead.
Now.. just for the sake of understanding: Ultimately I get that what you're recommending might be better practice, but won't the notifier/channel writer be updated just as often as the event structure does in my existing code? Especially because I have to set the same threshold in order to notify. If my set threshold is exceeded, the code will continue to notify until the voltage has returned back to its normal state. The event structure is also in a separate loop so it does not necessarily use more resources nor does it slow down my DAQ reading loop... what do you think?
08-11-2017 05:38 PM - edited 08-11-2017 05:39 PM
Some other points:
08-14-2017 11:17 AM
Altenbach,
Thanks for the pointers. They make a lot of sense.
I didn't figure out how to set a threshold in the producer with the 10 second wait without slowing down the producer loop. I also couldn't figure out how to set a threshold that only has a single entry... SO I ended up using a lossy channel writer... Yes, my producer is constantly sending T/F to the consumer, but the code responds very quickly & doesn't seem to hang.
Here's a screenshot of the simplified code just in case you or anyone else wants to see it as a reference.
08-14-2017 11:36 AM