Event structure inside a case structure

Hi,
I've got a problem w/ my porgram, and managed to boil it down to this
simple example.  The program basically hangs if you change the
Numeric value when the boolean is false.  I don't understand
why.  I suspect it has to do with the way event structures are
treated, but if someone cou please explain this I'd be greatful.
Also, now imagine I have 7 numeric controls, handled by 7 cases in that
event structure, and I actually want to do things in response to the
value change for each.  Can someone suggest an elegant way to do
that?  I thought what I had here was a good design, but apparently
not.
Bjorn
(I'm using labview 7.1)
Attachments:
EventInCase.vi ‏24 KB

It is generally a bad idea to place event structures into cases. Events structures need to be able to breathe.
Maybe you can redesign your program and place the case structure inside the event structure, for example? (Also have a look at the online help for the event structure, especially the link "caveats and recommendations for using events ".)
Detailed analysis:
Your event case for the numeric is set to "lock front panel until event completes".  If you change the numeric while the case is false, the evet structure cannot execute, so the front panel locks forever. The observed behavior is as expected. All clear?
In addition, if the case is false, the main loop spins at nearly infinite rate, consuming all available CPU. Place a small wait to be more cosiderate to everything else running on your rig.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Trying to clear an array inside a case structure

    Good morning all.  I am trying (unsuccessfully, obviously) to clear an array inside a case structure.  (See case structure at right side of vi, I colored it green to make it easy to find).  Here's (briefly) what I'm trying to do.  I have 6 test probes in the process.  All six probes are connected to the Alcatel Detector through a 6-solenoid manifold.  As I run the test, I want to sample 1/second, for let's say 3 minutes.  For the first 30 seconds, I want to pull a sample from from probe 1, so I turn on solenoid one and leave it open for 30 seconds.  Now all 30 values are tagged as having come from Probe 1, and they're stored in array 1.  I can now compute an average value for probe 1. Then I close solenoid 1 and open solenoid 2, saving the next 30 values to array 2.  (and so-on, until I have measured all 6 probes for 30 seconds each).  Then I wait a pre-determined amount of time and repeat the process.  Here's my problem.  I want to clear out each array as I begin the second iteration, so that I can easily compute the average of the last 30 values.  If I initialize the array by connecting a constant 0 to the shift register on the for loop insid ethe case structure, it does not work, nor does it work to place the 0 outide the overall for loop (the next for loop going out, NOT the OVERALL for loop).  I know my programming skills are still crude, but I'm putting everything into this.  Anyone have any suggestions? 
    Attachments:
    HCMF rev 1 25 Apr.vi ‏485 KB

    Altenbach, I definately understand your approach, and I like it much better than my own.  But I still have no luck making it work.   I get the same result as before (my original attempt).  Value 0 of the array simply changes each iteration, with nothing "saved".  Each new value simply overwrites the last value.  Can you take a look at my new vi, with changes, and see if you can find the error of my ways.  I am but a rookie Jedi in the vast reaches of LabVIEW Space, and you are no doubt a Jedi MASTER
    Attachments:
    HCMF rev 1 25 Apr pm.vi ‏374 KB

  • How can I determine whether to use an event structure or a case structure?

    I'm starting a large project and need a state machine. I can't decide on whether to use a case structure or event structure. Is there an article  or other information that describes criteria for selecting between the two approaches?
    Thank you,
    Chuck
    Solved!
    Go to Solution.

    Hi Chuck,
    Well case structures and event structures differ quite alot.  Here's a link for indepth information on Event Structures, and using them in state machines: http://zone.ni.com/devzone/cda/tut/p/id/2962.  Hopefuly this will help you make up your mind.  
    Let me know if you have any questions after reading it. 
    Regards,
    Dominic Walker
    Cardiff University
    Electrical and Electronic Engineering Student

  • Red line inside of case structure?

    Easy question...why do I have a red line inside of my case structure?  When I run my code, it flashes and seems to pause it. Anyone know how I can remove this?
    Thanks!

    smercurio_fc wrote:
    And the point of all those local variables is... ????
    OH NO!!  It must be true!!  I must have turned to the dark side! 
    Of all people, how could I have missed all those Local abuses!! LOL!!
    Been looking at low level drivers all day..
    Good catch Saverio.
    Local abuse is when Local Variables are used when in fact they are not needed.  Local Variable buse leads to race conditions and unpredictable code execution.

  • How can I pass data generated in a SubVI inside a Case Structure out of the Case Structure?

    Hello,
    I am using a USB 2701 to control a heater.  I have three SubVIs that are all working properly on their own.  I'd like to use an Enum to select which of the SubVIs is running at a given time.  The problem is that no data is passing out of the case structure.  How can I pass the temperatures and heater outputs acquired by the SubVIs to the main VI?  I've attached my some of my code below.  I can't attach more than 3 files, but you can see how the main VI is configured.  Like I said, the SubVIs are working individually, so you shouldn't really need to look at them.
    Thank you,
    CJones581
    Attachments:
    RampHeater6-21-07.vi ‏305 KB
    69_Heater_Case.vi ‏23 KB
    HeaterTCD6-21-07.vi ‏210 KB

    CJones,
    You might check a couple of things.
    Your HeaterTCD... VI has a While loop with a stop button condition.  HeaterTCD pass out values only when it finishes running.  If it doesn't pop open the front panel (which usually doesn't happen when running a SubVI) you could run into a stuck loop because you don't have access to the Stop button.  This could appear in the form of no data being passed out (because the SubVI never stops running).  The primary VI opens the HeaterTCD VI, starts it, and waits for the VI to finish and pass final values .
    Secondary note: Unless you want your SubVI panel (which probably isn't open when running the main VI) to update continuously, consider moving your Temperature Graph and Temperature oC indicators outside the while loop.  Pass final values to them via a tunnel, since the main VI will only read their values after the loop finishes running, anyway.
    It might help to add error management to HeaterTCD like you have for RampHeater.  If you connect error lines with Error Outs to your main VI, that will help tell if there is an error somewhere that is preventing info output.
    RampHeater SubVI has the same issue with the stop button.  It is also probably getting stuck in the While loop waiting for a manual push of that SubVI's Stop button.
    An easy way to test this would be to set up a logic circuit so that when the While loop iteration counter reaches a certain number, it registers True and sends it to the conditional.  I know this isn't what you want to do long-term, but if that lets your SubVI return outputs it means that the SubVI was just never stopping.
    Hope that helps.
    David C, Applications Engineering
    David C
    Applications Engineering

  • I have problems for to use Start function inside a case structure.

    I am doing data acquisition using the Config, Start and Read functions, all them inside a while loop. I want to use Config function only when certain conditions occur, so I put the function inside a case and no problem. But when I put the start function inside the same case, the acquisition is not good. Please view my attachment. My application is client-server type.
    Attachments:
    scope_server(config_start).vi ‏160 KB

    Boxer,
    I checked your example and have several easy but important suggestions for you:
    1.- First, make sure that the first time you initialize the VI, the AI Config and AI Start are executed, because based on the debug I made, your program doesn't do it, and this is very important.
    2.- Add an AI Clear after the acquisition is done, so that you release the resources. This is a good programming technique, and may help you solve your issue.
    3.- Add an Error Cluster, so that you know if an error occurred at some point of the acquisition. This will help you track the issue.
    4.- What do you mean by "the acquisition is not good". What does it happen? What does it do? Do you get an error? <- This is the reason of step 3.
    5.- Finally, if you have doubts
    programming AI, check one of the shipping examples of LV. They can give you a much clearer idea.
    Hope this helps,
    L Aguila
    Applications Engineeer
    National Instruments

  • Case structure run other case structure

    HI all,
    I have a big programme in LabVIEW, but what I want to do is very simple to describe with simple example on picture bellow.
    I need to make that when 1. case structure will be true  to start "second" case (but I also need to start second case manually with switch "START"). Is there any "property node" which will tell me when 1. case is on true?
    If this exist I then only need to add "OR" boolean to second case.
    I hope that is clear what I want to do.
    Rookie; LV 2011 on WIN 7

    Switch when release will keep that switch set as True until you come back and switch it off yourself. Latch when release will keep that switch as true until the terminal is read by LabVIEW at which time LabVIEW will return the switch to false automatically.
    Well I need button which goes automatically back to same position as it was after it was pressed, so I used "switch when released", it's also working with "latch when released". It's make no sense.
    Case structure 1 will execute the true case as long as X=1. Are you saying that you don't want the True case of the 2nd case structure to continue to execute as long as X=1? Only execute on the first time that X becomes 1? If so, you will need a shift register or feedback node to keep track of that boolean wire and only execute the 2nd case when the boolean wire is True AND when the boolean wire in the previous iteration is NOT True.
    Yes exactly that, I will try to use " shift register", so I can get previous  iteration.
    So I need gate which will do next:
    wire  | button  | OUTPUT
    1         0            1
    0         1            0
    1         1            0
    0         0            0
    Which gate must I combine to get what I want?
    Rookie; LV 2011 on WIN 7

  • Event in case structure

    Dear all,
    I am using Event Structure in a Tab Control.
    On page 1, there is a Table Control and when the mouse is clicked on it, it returns the Cell Value. The event is working ablsolutely fine, but the problem is i have no idea how to Stop the Event.
    I am attaching my Vi here. Pls have a look at it and let me know of a possible solution.
    Thanks,
    Ritesh
    Solved!
    Go to Solution.
    Attachments:
    Event in Tab.vi ‏18 KB

    ritesh024 wrote:
    But, it means that the Events in Page 1 are getting triggered even when the Control is on Page 2.
    That would take the unnecessary memory and time as there is no need for the events on Page 1 to run when the Control is on a different page.
    No, the event will not get "triggered", because if you are on the other tab it is impossible to fire the table event and a mouse up cannot occur. The event structure is in memory no matter what and placing it inside a case structure only complicates the code and can will lead to problems.
    The event structure should always be in the dataflow, the tab position is irrelevant. Never hide an event structures inside a case structure!
    Here's a quick example (LV 8.5). Tab 1 has your table and senses the cell position. Tab 2 has a light switch. As you can see there is no case structure needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Event_in_TabMOD.vi ‏19 KB

  • Case structure for comparing values

    Hi,
    i just wanted to know if there is a special way to use comparison in case structures.
    I only kow how to create cases for things like if x=0 then ... if x=1 then ...
    Now I want to make it if x<0 then ... if x=0 then ... if x>0 then ...
    The only solution I found so far is creating a case structure inside a case structure.
    Is there a way to keep it all in just one case structure?
    Thanks and have a nice weekend,
    Bernie

    Case Structures are pretty flexible in how you can specify what triggers a particular case. You can specify ranges or various values per case.
    In your situation, if you specify three cases with the following values, you'll get what you want.
    '..-1' = x<0
    '0' = 0
    '1..' = x>0
    The two periods before or after a number indicate that the case should run if the value is anything less than or greater than the specified number, depending on which side of the number you place it. You can also use this to specify a range of number. '1..10' would trigger the case for any value 1 through 10. Using a comma between numbers lets you specify different non-sequencial numbers. '1,5,10' would run the case only those specified numbers.
    The same basic rules a
    lso work with text based Case Structures.
    Attached image shows the three cases you need.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
    Attachments:
    Case_Range_Values.gif ‏21 KB

  • How to get a case structure to execute only once in a loop

    I have a while loop that is monitoring temperature. Once the temperature meets or exceeds a given setpoint I want to start a timer. At this point I don't want to monitor the temperature anymore. That is, if the temperature should drop below the setpoint, I don't want to execute the case structure again when the temperture meets or exceeds the setpoint(the temp may oscillate about the setpoint for a given period of time). In any event, I need the case structure to execute only one time, not every iteration of the loop.

    You can put a local Boolean variable "Flag" inside that case structure and
    set "Flag" to False. Outside the case structure, use an "AND" function
    output to control the case structure. The "AND" function has two inputs. One
    goes to the comparison results between real temp and setpoint. The other
    inputs connects to the "Flag" variable. In this way, once you entered that
    case structure, the "Flag" will be turned to False, and then in next
    iteration, you won't get into the case again because the "AND" function will
    be False as your "Flag" is False now.
    Hope this helps.
    Rentian
    1. Inside the case structure, put a
    "BB Herman" wrote in message
    news:[email protected]..
    >I have a while loop that is monitori
    ng temperature. Once the
    > temperature meets or exceeds a given setpoint I want to start a timer.
    > At this point I don't want to monitor the temperature anymore. That
    > is, if the temperature should drop below the setpoint, I don't want to
    > execute the case structure again when the temperture meets or exceeds
    > the setpoint(the temp may oscillate about the setpoint for a given
    > period of time). In any event, I need the case structure to execute
    > only one time, not every iteration of the loop.

  • Case Structure timing/ writing data to a excel

    Hi all,
    I have written a program that has the main functions of allowing the user to generate a random number between either 0-10 or 5-15 by using the labelled switch. I also have a control which can switch this function on or off. When this switch is true it will display the random number and also write this number to an excel spreadsheet every 1 second (I hope). When false this will stop displaying the number and hence not write the number to a file.
    However, I am having the following issues:
    1. Excel file is corrupt once I begin to write the generated numbers to the spreadsheet. (I am trying to write to a .xlsx file)
    2. Once I begin to try write the numbers to file, the elapsed timer only displays the time is 1second intervals rather than the full time.
    I changed the .xlsx file to a .csv file and this solved issue 1. but it only recorded one random number rather than the numbers that were generated in that time since switched on/off.
    Should I have the write to spreadsheet function in the timed case structure?
    Should the file path control be outside this case structure?
    Have I set up the write to spreadsheet VI correctly?
    If anyone could help with these issues that would be a big help.
    Thanks!
    Attachments:
    Random Number tester.vi ‏30 KB

    lneill65 wrote:
    There is still an issue with the elapsed time. Once I begin I turn the top boolean control to true, the elapsed time begins changing at the set time increment inside the case structure. Is there anyway to stop this from happening?
    Your elapsed time display is independent of the boolean switches because it is on the toplevel loop diagram. I am not sure why you place a five second wait inside the case structure if you want to write once per second.
    I am not sure why you have two sequential case structures since the calculations of the first structure is not needed unless the other case is also true. Why not place it inside the true case?
    You should also adhere to some basic coding styles. Avoid overlapping and floating objects, hidden wires, right-to-left wiring.
    If it is sufficient if the code reacts once per second, just run the loop with a 1 second wait. If you don't want to display a stale random number if the switch is off, place the indicator after the case structure.
    Here's a quick draft. Modify as needed. I probably would use an event structure, but let's keep it simple at this stage. You should also modify it so it does not try to write with an illegal path and also retain the selected path once selected. I propably would use a file dialog instead of a FP Path control.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Random Number testerMOD.vi ‏9 KB

  • Can I put a READ function in a TRUE/FALSE case structure?

    Hi,
    I have a vi that operates as controller for a mechanical system of motors.  There are several sensors of various types, that provide input to the vi, including encoders, whose period is being measured.  The attached vi is the encoder period measuring part. It measures 15 periods and tells me the average of the 15 with each loop iteration.
    In my application, the encoder period measurement is not needed unless the vi knows that ALL THE OTHER sensors in the hardware configuration are measuring values within the desired range.  For example, Sensors A, B and C should all measure between 5-10.  If they are all showing values between 5-10, then, we want the encoder value to read and display.  If only one of the sensors, say A, is measuring 12, then, we don't want the period value to READ or be subsequently processed.  So, it is easy to set up the sensors A, B, C, to give a TRUE or FALSE based on whether they are within range or not, and if all 3 are TRUE, then, that value can easily be passed to the case structure that holds my READ function for the period.  Is this a good way to do this?  The goal is to eliminate unnecessary execution time that the period READ function would consume, as well as all subsequent calculations that are performed on the period value collected.  The period data is of no use if any one of the other sensors is not in the correct range.
    If any one of the other sensors is out of range, we want to skip the encoder READ step altogether.  So, it is easy to structure a BOOLEAN in my vi as shown in the attachment.  If I do it this way, will it throw an error, or just skip the READ until the BOOLEAN is true again?  Is there a better way to prevent the READ from happening if one of my other sensor values is not within the correct range?
    Thanks,
    Dave
    Solved!
    Go to Solution.
    Attachments:
    forum JUly 18.vi ‏26 KB

    Sure, you can put a Read inside a case structure. For your application, just check that your sensors are all within range (Comparisons palette), then AND the T/F's and use the result of that for your case structure. (If you are already doing the in-range check, I can't see it here because you have 5 subVIs that I cannot open here.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • How do i output multiple arrays from a case structure to create one larger array

    I currently have a vi that has one hardware input that i needed to take a measurement then be moved and take a similar measurement at a different point.  To accomplish this i used a while loop inside a case structure.  The while loop takes the measurement  and finds the numbers i need while the case structure is changed per the new measurement location.  I want to take the data points i have created in each case and output them into a single table.  I assumed to do this the best way would be to get the data from each case into its own built array and build a larger array but I cant get the information out of the case structure so that it all inputs at different places.
    thanks for your help
    Attachments:
    Array.vi ‏30 KB

    Hi Ross,
    attached you will find a solution for your table building problem.
    I would suggest thinking about program design - having the same case content in several cases doesn't make sense. I also would not want my user to press several stop buttons depending on choosen measurement...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    Array.vi ‏45 KB

  • How can I put a numeric indicator into a case structure using VI scripting

    I'm using VI scripting and I'm trying to add a numeric indicator inside a case structure.  I'm able to add the case structure and the numeric indicator just fine, but as soon as I specify the case structure as the "owner" of the numeric (as opposed to the block diagram being the owner) I get error 1060.  Is there any way around this?
    Note:  The reason I am doing this is because this specific pattern (indicator in a case structure) will prevent a VI from being inlined when it is being built.  This pattern will provide no functionality in itself, it only prevents the inlining.  It is added to a larger VI which is use to initialize objects in a simulation, and there are many of them in the total simulation.  If they are inlined, it takes a VERY long time to generate the C code, and performance on this VI isn't an issue since it is performed only once at the beginning of the simulation.  The rest of the VIs do need to be inlined for performance reasons.  Therefore, I'm open to other options to prevent a VIs from being inlined if the "indicator in a case structure" cannot be performed via scripting.
    If any of this is unclear please let me know and I can clarify.  Thanks.
    Solved!
    Go to Solution.

    I now understand what you were saying about inlining a subvi.  I did as you said and made a subvi with a case structure and an indicator within it.  I use the New VI Object node to add that subvi to the slow-inlining parent VI.  Then I tried to inline it using the invoke node, but I got error 1399, which make sense.  Is this what you meant for me to do, or did I misunderstand?
    Also, I tried the ControlTerminal reference approach you mentioned earlier.  Unfortunately when I called the move method on the control terminal property and had the 0th frame of the case structure as the owner I got error 1060 again.
    I really appreciate your help.  Do you have any other thoughts?

  • In the attached VI I dont understand why data from the inner case structures are not being transmitted to the array.

    In the attached VI I don't understand why data from the inner case structures are not being transmitted to the array.
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    TEMP.vi ‏25 KB

    It took me some time to figure what you are trying to do but I think I have it now.
    The SR is still required.
    What is happening is your "Bundle By Name" is replacing all of the fields of the cluster, not just the value coming out of the case structure. So to maintain the cluster stuff you do in earlier iterations you can either...
    1) Put the "Index array, Bundle by name, and Replace array" inside the case structure and ONLY bundle the value you are setting in that iteration. (as you will see Tim post shortly)
    OR
    2) Move the Index array before the Case, unbundle all of the fields and feed teh case structure and run them across the case so that ALL of your output tunnels come from the coresponding input tunnel EXCEPT for the filed you are trying to set.
    Ben
    Message Edited by Ben on 05-05-2010 01:31 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for