04-02-2021 01:36 PM - edited 04-02-2021 01:40 PM
Hi All,
I have looked all over for similar questions/scenarios with not much luck. I believe my question is fairly simple. I have a loop structure where I use DAQ Assistant to collect the voltage of two sensors. At the same time the loop begins (by pressing the Boolean start button to data collection) I want a case structure to begin that has a sequence containing time delays and a digital out which opens and closes a relay. Both structures work as intended on their own but I need them both to start at the same time so I can set a known timing for the digital out found in the case structure. I tried using a stream and tag write/read for the true/false signal but it still didn't work. Please find attached my VI.
I appreciate any suggestions/solutions and thank you in advance.
04-02-2021 02:13 PM
What exactly does "didn't work" mean? What did you expect to happen?
04-02-2021 04:37 PM
What is the purpose of the message channel in there?
Your case structure will only run once. I don't know channels in enough detail to know exactly what happens on their first execution. But my guess is that since nothing is written to the channel until the code inside the while loop has started executing, the channel reader probably will start with a default value of false. And it will only ever execute once.
I'm quite impressed that you've basically created a race condition using channels, which are alternatives to queues, and queues are supposed to prevent race conditions.
04-02-2021 05:10 PM - edited 04-02-2021 05:12 PM
You got some good advice already, here are a few more points:
04-04-2021 04:13 PM - edited 04-04-2021 04:33 PM
Hi paul_cardinale,
Thank you for your response.
What I was expecting to happen is that the case structure containing the digital out occurs only once while the case structure containing the saving continues to loop as it should. When I said "it didn't work" I meant that that upon pressing the start button the TRUE state is sent to the case structure containing the saving operation but not to the case structure outside of the loop which is used to toggle a relay (even after using tag/stream read and write, which I saw used on this forum to stop multiple loop structures at the same time with one button).
When moving the relay case structure within the loop it works, however the relay open and closes repeatedly as expected since it is inside a loop. I want the case structure containing the relay operation to only occur once upon the beginning of data saving which is why I'm trying to wire the relay case structure to the same button.
04-04-2021 04:27 PM - edited 04-04-2021 04:34 PM
Hi RavensFan,
I appreciate your input.
By message channel are you referring to the boolean read/write stream? I tried using this to send a TRUE state to the case structure outside the loop, after searching how to start/stop structures at the same time.
I initially had just a wire connecting the button to both case structures however the case structure containing the digital out never worked outside of the loop and still does not work even using the read/write stream.
04-04-2021 04:51 PM
Yes.
When you say you want the case structure to start the same time as the loop, do you mean the True case of the structure? Or the false case as well?
It seems like you are making this unnecessarily complicated.
Really, the digital output code belongs in the while with the acquisition. Don't use wait functions to delay the true and false. Just just the timing of your data acquisition to determine your loop rate and write a new digital output on each iteration of the lone while loop.
Altenbach already pointed out a number of issues you have including acquiring 1000 samples on each change in the DAQ Assistant, only throw out 999 of them.
04-04-2021 04:59 PM
Hi altenbach,
I thank you for all of your suggestions.
First off, yes, the top code should run once per session but my problem is that it is not running at all. It does not toggle the relay after 1s of pressing the button. When I placed that case structure within the loop (to test) it worked, but repeatedly toggled the relay (as expected).
Secondly, I agree, I think it is silly that all I am converting the dynamic data to DBL. I did not want to use DAQ Assistant but I could not wrap my head around setting up virtual channels, I found the examples in labview confusing and I couldn't find one reading multiple voltages. Also, the two voltage readings are configured differently in NI MAX, one is RSE the other is Differential. If there are any helpful resources/examples you know of and could provide I'd appreciate it.
Lastly, for saving two columns of data what would you suggest?
04-04-2021 05:11 PM
Hi RavensFan,
So you are basically suggesting to have two while loops with in the main loop? One that would open the relay at index 1000 (1s) and then at index 2000 to close the relay at 2s. How would I index the acquisition loop? Thanks.
04-04-2021 09:26 PM - edited 04-04-2021 09:32 PM
@PDE46 wrote:
By message channel are you referring to the boolean read/write stream? I tried using this to send a TRUE state to the case structure outside the loop, after searching how to start/stop structures at the same time.
What you researched isn't relevant to "a structure". It is specific to loops, and more about how to stop parallel loops than start them. A structure will start as soon as it has all inputs.
@PDE46 wrote:
I initially had just a wire connecting the button to both case structures however the case structure containing the digital out never worked outside of the loop and still does not work even using the read/write stream.
Yes, it never executed because it did not have all of its inputs. Actually, I suspect it executed once after you pressed stop and the final value passed out of the while loop. Have you tried watching any of this with Highlight Execution turned on? It should make it clear what is happening.
The thing you must understand is that any code not in some kind of loop will only execute once.
The way you have it now, what is happening is that on every loop iteration you are reading the Save button and writing its value to the stream. Your channel reader is not waiting for a True value, nor is your case structure. The very first time the Save button gets read and writes a False value to the stream, the reader will return that false value and your case structure will execute the False state, which is empty. It will then never execute again.
BTW, I'm not really very familiar with channel wires, but you have your stream size set to unlimited and you are only ever reading out a single element. I have a feeling that if you let this run long enough, you will crash due to running out of memory as the unread elements of the stream pile up.
What are you actually trying to do? It seems that you want to monitor data, but not save anything until the Save button is pressed? Should you be able to press save more than once, or should the VI exit after acquiring the saved data sample? Should the duration of the data to be saved match the timing on those relays? (Basically, can you describe your desired program flow?)