06-28-2017 09:58 AM
Hello,
I'm working on a small program that will build an array of devices connected to my computer via a chassis. DAQmx and DAQ Assistant are not an option for me due to my hardware. The application will simply initialize the connected devices (which it's already doing well), build an array of the device names, and enable me to switch LEDs on all the devices on simultaneously and then switch them off as well. I'd like to make this application so that I can trigger the LEDs as many times as I'd like and for whatever duration I'd like.
Later, this will be developed into a scope of sorts which will enable me to trigger all of the devices using an event at one channel and display the data from multiple channels on one graph or chart (like you can with a soft oscilloscope).
This application, however, is misbehaving. The array indicator isn't populating with device names. The trigger only works once. Once I turn off the LEDs, I cannot trigger them again, nor can I use the STOP button. I think it has something to do with an infinite while loop, but I've been unable to find a fix for that.
All help and suggestions are greatly appreciated!
Marshall
06-28-2017 10:12 AM
Your problem is the loop inside of the event case. The event case is set (by default) to "Lock panel until event case completes". So when you press the button, the panel is locked and your buttons will not work. Based purely on what I see in your code, I would get rid of the event structure and just use a case structure.
06-28-2017 10:36 AM - edited 06-28-2017 01:14 PM
In addition to what Tim just said, please start with a few simple LabVIEW tutorials, because large parts of your code make little sense.
For the loop on the right left (edit), you know the number of iterations before the loop starts, thus you should use a FOR loop. No need to check the counter with each iteration.
You are probably trying to build an array of instrument strings in this loop. Building the last reponse into an array with one element does not seem to be very useful? If you would use a FOR loop, you could create the array of all responses using an autoindexing output tunnel. Try it!
If you use an event structure, you also need an event for the stop button.
never use interactive loops inside event cases. You can use the outer loop for everything (e.g. by utilizing the timeout event). But I agree that you should not even use an event structure here.
In the inner loop you are doing a "not equal FALSE?" comparison. Try to make a truth table for all possible inputs and see of you can simplify the code. 😄 How different would the result be if you would just delete that function and only leave a wire?
Learn about mechanical action settings of booleans.
06-28-2017 12:51 PM
Thanks for the responses, gentlemen.
I'm an intern at the moment, and I'm seeing more LabVIEW on this internship than ever before. I've completed the Core 1 training and am beginning the Core 2 training, but I can still use Core 1 as a reference, so I'll go back and look at that while considering your suggestions. I'm not sure how I'll replace the event structure with a for loop and still get the program to wait for a trigger, but I'll look into it. Any suggestions on that would be helpful.
Thanks again,
Marshall
06-28-2017 01:06 PM
@mprince956 wrote:
I'm not sure how I'll replace the event structure with a for loop and still get the program to wait for a trigger, but I'll look into it. Any suggestions on that would be helpful.
Nobody suggested to replace the event structure with a FOR loop (I said that the outside while loop on the left should be a FOR loop instead).
In terms of program architecture, the magic word is "state machine". All you need is a single outer while loop with a state variable held in a shift register and a case structure to define what the program should do and where the program should go next as a function of state.
06-28-2017 01:34 PM
So the while loop on the left should be a for loop with N wired to Number of Instruments. I'll do that. Thanks.
If I put a state variable into a shift register on the while loop (I'm guessing you mean the one on the right, now?), will that make the program wait for the user to push the trigger to begin displaying data?
How do I make a state variable and put it into the shift register?
Thanks again,
Marshall
06-28-2017 01:51 PM
@crossrulz wrote:
I would get rid of the event structure and just use a case structure.
Would I include a FOR loop in that Case Structure in order to make sure that each of the 6 LEDs come on? If not, how could I make sure each of the LEDs come on. Also, I'm not having any success with the new FOR loop on the left side (where I replaced the WHILE loop). The error wire won't go into the case structure on the right. It tells me that the source and the sink are two different data types (1d array of cluster of 3 elements and cluster of 3 elements, respectively). Any suggestions?
Marshall
06-28-2017 02:05 PM - edited 06-28-2017 02:07 PM
@mprince956 wrote:
So the while loop on the left should be a for loop with N wired to Number of Instruments. I'll do that. Thanks.
Here's how that could look like (sorry, I don't have your subVIs)
Of course you probably want to add a bit more intelligent error handling, e.g. if one returns an error, for example.
@mprince956 wrote:
If I put a state variable into a shift register on the while loop (I'm guessing you mean the one on the right, now?), will that make the program wait for the user to push the trigger to begin displaying data?
One of the states is the "idle state" that just waits for the controls to change and goes to another state depending on the new values.
@mprince956 wrote:
How do I make a state variable and put it into the shift register?
Have a look at the examples and design templates that ship with LabVIEW.
06-28-2017 02:11 PM
@mprince956 wrote:
. Any suggestions?
You really need to go back to the tutorials and learn about the various types of tunnels. The default FOR loop output tunnel is autoindexing, turning your error into an array of errors. You can change the tunnel to "last value", use a shift register, or insert a "merge error" afterwards.
06-28-2017 02:32 PM
Alright!
The trigger is working beautifully and far more simply now. Thanks for your help. I'll keep working on the array indicator to find out why it's not printing the names of the devices.
Good day.