05-02-2014 05:44 PM
I have this VI that I created where Ch 5 is attached to a reed switch on a door and counts how many times the door is opened and writes a date and time stamp to file each time and also updates the numeric counter on the front panel. I would like to add 4 more switches with the same functionality and have them all write to the same file in different columns. I have tried a number of different approaches to make this happen but can figure out what I’m missing. Any thought on how I could add the same function with more switches? Eventually I would like to be able to not only record when the door is open but for how long it stays open for. Thank you.
Solved! Go to Solution.
05-05-2014 02:20 PM
Anyone have any suggestions on how I can make the above VI work with multiple counters? I have been looking through all sorts of example VI’s and cannot seem to come up with a working combination. Any help would be greatly appreciated. Thank you
05-05-2014 07:49 PM
When you say "more switches"; do you mean several channels with one switch each? If so, you can do the increment inside the inner while loop every time a true comes from the switch. If not, please post additional details about your application requirements.
Regarding how to use several counters, if the previous assumption is right, I guess you can just wire each switch's increment to sepparate indicator on the outer loop.
About the open door monitor, the easiest way would be implementing an Elapsed Time express VI so that it will start when the door is open and stop when the door closes. You can also use a couple of Tick Count (ms).vi functions for that purpose.
05-06-2014 09:57 AM
Thank you for the reply; I would like to add up to 4 additional switches to the DAQmx task on 4 additional Analog channels. Would I need to add 4 additional shift registers inside the inner loop? Or how do I get the signals from the inner loop to the outer loop and then split the signals to separate indicators in the outside loop and bring them back together to write to the file? Sorry for all the armature questions I really appreciate the help.
Thank you for the tip on using the Elapsed time VI or Tick CountVI’s I will try this out.
05-07-2014 03:29 PM
Still can’t seem to get this VI to work the way I envision. I have spent countless hours watching tutorials and searching the forms. I have tried splitting signals, using arrays, multiple shift registers, event cases, and every type of loop I could find. I just can’t seem to come up with a solution to add 4 more channels to my VI and hook up to a simple counter and write to file VI. Creating the 4 extra channels in the DAQ assit. is no problem it’s just were to go from there. Camilo V I’m still trying to figure out what you mean by “increment inside the inner while loop” Are you refering to adding the +1 for the counter portion? I think the part I have struggled with the most is getting 4 addional signals out of the inner loop and than seperating them out to 4 separate indicators than merging back to write to one file, If that makes sence. I sure appreciate the help this is just a project I’m expermenting with on the side outside of school. Even if someone could just give me some key words to search for more information and traing that would be helpful.
Thanks again,
Chad
05-07-2014 06:30 PM
Hello Chad,
I was able to work this out (and actually had some fun with it) after work. Give it a try.
I believe there should be a more "elegant" solution, but it is functional and addaptable to your project.
Hope it helps!
05-07-2014 06:53 PM
Wow this is great Thank you so much. It works exactly how I envisioned now hopefully I can find the correct way to incorporate it into my VI. I sure appreciate your time. Looking forward to experimenting with it tonight once I get the kids to bed.
Thank you,
Chad
05-09-2014 09:56 AM
I was able to incorporate your counter into my VI and somehow made it work. I’m sure using local variables to get data out of loops is not the recommended way of doing things but it seems to work as I wanted. I appreciate your help so much and learned a lot from it. Attached is what I came up with that works pretty well, I would like to figure out a way to only write the total time the switch was open rather than all the samples it collects while the switch is open but I will continue reading and see what I can figure out. Thanks again for your time this has been great.
Chad
05-12-2014 04:11 PM
It is true that local variables are not the most efficient communication method and they are not recomended to pass information among loops, mainly because they can create horrible reace condition errors. However, in this case I only read information from the local variables (except from the stop button, which should not be a problem either), so race conditions will not be a problem. Still, that's why a "more elegant solution" probably exists.
Also, I used a flat sequence structure to initialize the controls before execution and to force the initialization to happen before enything else. I guess you can use is to initialize the 0 constant outside the top while loop (even though I doubt there will be a rece condition there, it might e the only possible source for any).
About how to display only the total time, you should be able to do that by playing a littile with the shift registers and the select function. For example, what I did was to show the Elapsed Time.vi output if the boolean controls are on, and show the shift register value if they are off. Instead, you can simply add a second Select function on each elapsed time "circuit" so that the indicators will show the shift register value only when the boolean controls are off.