Execute case structure only once

Hi everybody.
I want to execute a case structure inside a while loop only once. The case strucutre is controlled by a counter, so that every time the counter has a value multiple of N, the program records an acoustic signal and calculate the main peaks of the FFT. The problem I have at the moment is that, every time the case is executed, it records and analyze the sound several times until the counter jumps to the next value. I want the case to execute only once every time the counter has a value multiple of N. I atttach the vi.
Thank you for your attention guys!!!
Attachments:
Pulsations2.vi ‏243 KB

GERD is right.  You should use a feedback node to store the previous count value.  If the current count is Not Equal AND the remainder is Equal To Zero run your case.
Since your counts are all integers, I would also recommend changing the representation to an integer type.  I32 would likely be the most appropriate.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

Similar Messages

  • Execute Case Structure with Button Press Slows Down VI

    Hi -
    I'm fairly new to LabView, and I am having some issues with using a button to run a timed while loop.
    I am writing a VI that outputs a timed voltage pulse to an output channel on a DAQ; meanwhile, the VI reads and graphs the voltage on three input channels on the DAQ. When I use a timed loop that automatically executes when the VI runs, the program works. However, I would like to include a button so I can control the timing and number of voltage pulses sent to the output channel, instead of sending only one voltage pulse each time the VI runs. I have tried to do this using a button wired to a case structure. If the button is 'true,' the VI should send the voltage pulse. If the button is 'false,' the VI should keep the voltage at zero.
    When the button is 'false,' the VI runs normally; however, when the button changes to 'true,' the VI slows down and never sends the pulse. Why does this happen? How can I fix it?
    Also, how can I send the voltage pulse only when the value of the button changes?  I only want the timed loop to execute once when the button changes value.
    Thanks for any help or advice!!!
    Attachments:
    Sensor Read6.vi ‏85 KB

    The graph is in the same while loop as the case structure.  The while loop won't iterate until all the code inside of it has completed.  So the graph only gets updated once, and won't update again until the while loop iterates again.  If you need more continual updating you may want to put that in a loop that executes a couple of times, or completely separate your code into 2 while loops.  Is it that long of a wait considering your pulse length is 1 second?
    Your analog output code is just writing a voltage out (7 volts) until it eventually writes out 0 volts.  There is no reason for it to drop down unless you have some sort of electrical problem between your DAQ device and the device on the other end that is reading the 7 volts.  What are you connecting that analog output too?
    What if you don't use LabVIEW and try to test out that analog output using Measurement and Automation Explorer?  Does it do the same thing?

  • Execute case structure a certain number of times within a while loop

    Hi guys,
    I was wondering if it was possible to execute a case structure a specified number of times within a while loop. Basically I'm running a camera where each iteration of the outer while loop displays a frame of a live video feed and I'd like to capture the next x amount of frames (specified by the user) each time the 'Start Capture' button is clicked. The block diagram within the case structure captures and saves an image frame. As the program is written right now, frames will continue to be captured until the 'Start Capture' button is clicked again. Instead of having to click the button again to stop the case structure from executing for each iteration of the while loop, I'd like it to only execute for the next x iterations of the while loop. Any help would be appreciated. Thanks.

    Hello Uxorious,
    A while loop has a iteration counter that gives an integer value of how many times the loop has iterated. You can utilise this to count the number of frames captured. I assume that the program could be running for any amount of time before clicking start capture, if that is the case then you will need to be able to detect when you have clicked the button and add the desired number of frames you wish to capture to the current loop iteration.
    If you use a shift register on the outer loop with the start capture button connected to it (inside the loop) you will be able to compare its current value to its previous value. If it changes from false to true then you can add the desired number of frames to it to give you the loop iteration value where you need to stop.
    Then you can compare the current loop iteration value to that number and once reached, you can use a property node to change the value of your start capture button back to false.
    One final thing, don't forget to initialise the shift register I suggested to false so that you don't run the risk of missing the first time you press the button.
    I hope that makes sense.
    Alistair
    Best regards,
    Ali Bailey
    National Instruments
    Don't forget to Kudos useful posts!

  • Need help in executing EEM applet only once

    Do we have any sample script for EEM applet counter ?  We want applet to execute once after reload after matching a string . We tried couple of solutions like “ server suspend  “( customer does not like server suspend)   and event counter ( this does not allow syslog string matching ). Please let me know if there are any options.
    At the router reload, match the string , bring down the interface and run this applet only once . I have been trying multiple messages in Bootup log for this for bringing the interface down.
    The issue we are facing is that most of the bootup log messages can be triggered when the router is up as well which will result in triggering of the applet which is what we want to avoid.
    event manager applet Interface_down
    event syslog pattern "SPA removed from subslot 0/0"
    trigger delay 10
    action 1.0 cli command "enable"
    action 1.5 cli command "config t"
    action 2.0 cli command "interface gi0/0/0"
    action 2.5 cli command "shutdown"
    action 3.0 cli command "end"
    event manager applet Interface_up
    event syslog pattern "Bulk Sync succeeded"
    trigger delay 100
    action 1.0 cli command "enable"
    action 1.5 cli command "config t"
    action 2.0 cli command "interface gi0/0/0"
    action 2.5 cli command "no shutdown"
    action 3.0 cli command "end"
    end

    This is a bit dirty but you can create an applet to run at startup that creates the event detection applet. Then at the end of the detection applet, have it remove itself from the running config. This means that the  applet running at startup will always create the event detection applet but the event detection applet will only ever run once for that router boot period as it deletes itself after first run.
    The problem is that when you want to have one applet create another applet, you have issues with the inverted commas being correctly configured for the second applet which will cause it to run once, but fail after that. The way you can get around this is to write the applet to a text file on the flash and then copy the contents of the text file to the running config at boot. This preserves the structure of the applet being created and ensures that it will function correctly.
    The following example builds the event detection applet at system restart (BUILDAPPLET)  by copying the file "eventapplet.txt" to running config. The event detection applet (EVENTDETECT) detects a syslog pattern, in this case exiting global config, and runs the applet sending a puts command and outputting HELLO. The event detection applet then removes itself from the running config.
    !# configure the router
    conf t
    !# turn off file prompting to let the BUILDAPPLET run when copying
    file prompt quiet
    !# create the applet that runs at system restart and copies the flash applet to the running config
    event manager applet BUILDAPPLET
     event syslog pattern "%SYS-5-RESTART"
     action 10 cli command "en"
     action 11 cli command "copy flash:eventapplet.txt running-config"
    !# exit
    end
    !######## Create the flash file containing your run once applet ########
    ! enter the tclsh so we can write our applet to a file - put your event detection applet in here between the {} that you want to run once
    tclsh
    puts [open "flash:eventapplet.txt" w+] {
    event manager applet EVENTDETECT
     event syslog pattern "%SYS-5-CONFIG_I"
     action 1.0 puts "HELLO"
     action 2.0 cli command "en"
     action 3.0 cli command "conf t"
     action 4.0 cli command "no event manager applet EVENTDETECT"

  • What is the best approach for executing this code only once?

    Hi,
    What would be the best way to this using JSF/Java web architecture? I have a login page, login.jsf, that submits login credentials to another servlet and if successful, is redirected to a login success page, which I have called "main.jsf", my application's main page. What I want to do, however, is when the login success mechanism redirects to my application, I want to run a bit of Java code (which requires access to the session object) that executes only once, and then redirects to my application's main page.
    In other words, I could put this Java code on my application's main page, but then it would execute every time a user visited it.
    Any advice on the most efficient way to do this?
    Thanks, - Dave

    laredotornado wrote:
    Thanks for your reply but I have a question. If the filter is executed on every page, then, assuming the user is logged in, the code would be executed every time. How can I create this such that my code snippet is executed only once, preferably after the user is re-directed to the login success page?It is more secure. On login just put the User object as attribute of HttpSession and check in the filter if it is there.

  • [EVL] Execute constraint check only once (per model)

    Hi All,
    I have been working with Epsilon for a few days now and I love the tool so far
    I am currently working on a model validation but I cannot find an elegant way to perform a certain check only once for the entire model. The casus/Meta-Model is very simple. I have a Node that has 0..* references to itself. The idea is to have a very simple tree where nodes have a reference to their parent.
    What I want to check is that there is one and only one root node, so only one node without a reference. This results in the following check: AT!ATNode.allInstances.select(n|n.Parents.size() == 0).size() = 1
    I do not know where to perform this check however. If I perform it in the context of the node, it (correctly) returns an error, but does this for every node.
    I also tried to have the entire model as 'context' or to apply the check in a pre-condition, but could not get any of these approaches to work. I also could not find a suitable guard to put on the constraint.
    Can you help me find a more elegant solution?
    Greetings,
    David

    Hi David,
    Quote:an elegant way to perform a certain check only once for the entire model
    May be you could model the "entire model" ... I mean, it's a kind of a good practice to create a ModelRoot class containing all your nodes. [A better name could be "Tree" or another appropriate name according to your domain]
    Then your validation wizard, with the exactly same expression, could be set on this class, a.ka. the "entire model" ?
    Furthermore, you could also ensure the root unicity by setting proper cardinalities in the metamodel, and avoid writing a check.
    I even met a special case where I had to model explicitely the RootNode as a class => A tree contains one root node which itself contains nodes ...
    Cheers,
    --Eric

  • Executing the webservice only once by the pdf

    Hi,
    I am using a WebService call in my pdf form but I want to call that webservice only once from the form by that particular user. How can we do that?
    I tried to do this by adding the invisible text field in the form and maintain a flag to check the webservice is executed or not. but when I close the pdf and again reopen then the webservice is executed at the first time so how can I solve this problem?
    Thanks
    Ninad

    Set the Hidden fields Binding property to 'Normal' that way the value in that field is persistent. And then always check for the flag before you execute the code for calling WSDL. Hope this helps.
    Good Luck,
    SekharN

  • [begginer] start button executing sub vi only once

    Hi, I'm very confused by, what it looks, very simple task.
    I have a piece of code and I need to plug it to "start" button which will execute it once when button is pressed, execute once again if I press the button again and so on.
    I tried with "while" loop and true/false button connected to it but, as you know, code inside the loop executes itself continously as long it's true which is incorrect, it doesn't stop when it should.
    I woul'd like it like that: Press start->code in block executes once and thats it, no more unsless I press the button again..
    Please advice.
    ps: I attached piece of vi I need to connect with button. It actually works as inteded but I fail to make it executable with button.
    Solved!
    Go to Solution.
    Attachments:
    untitled.vi ‏13 KB

    Here you go, 2009 version. note that one file is missing.
    Regards,
    Even
    Certified LabVIEW Associate Developer
    Automated Test Developer
    Topro AS
    Norway
    Attachments:
    RunButton.vi ‏14 KB

  • Execute delay only once the entire time

    I need ideas on how to execute a delay only once after start (and that's it, no more calling the delay ever again after start) in a while loop without affecting other codes in that same loop...
    Something like this http://forums.ni.com/t5/LabVIEW/put-a-delay-for-executing-case-structure/m-p/1095396/highlight/true#... but it is not working

    Why? That makes no sense. You need to change the loop termination inside the subVI as I already mentioned.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    DelayMod.png ‏10 KB

  • PreparedStatement vs Statement - When executing only once

    Are there any performance implications in using PreparedStatement vs
    Statement when you are executing the SQL only once? I am talking about all
    kinds of SQL (Select, Update, Insert and Delete). If PrepatedStatement is
    used, I would expect some overhead in setting values for different columns
    separately and precompliling. Is that overhead significant enough to
    degrade performance? If we execute statement only once, I do not expect to
    any gain on performance.
    I would appreciate any comments.
    Sarat

    It also depends on the database/driver combination,several database can be
    configured to maintain a prepared statement cache at the DB level (I have
    never done it myself, but I know people who has done this. Lately I use
    mostly Oracle, for which I should not be configured an expert :)).
    Also the weblogic's prepared statement cache only caches first so many
    statements. If you have used them all up at the startup you are out of luck.
    I know you already knew that, but may be helpful to the original poster.
    .raja
    "Cameron Purdy" <[email protected]> wrote in message
    news:[email protected]..
    BTW - there is a case where prepped stmts are faster -- when they arecached
    by Weblogic's jdbc wrappers. So my previous answer can be wrong.
    Peace,
    Cameron Purdy
    Tangosol Inc.
    << Tangosol Server: How Weblogic applications are customized >>
    << Download now from http://www.tangosol.com/download.jsp >>
    "sarat" <[email protected]> wrote in message
    news:3b715901$[email protected]..
    Are there any performance implications in using PreparedStatement vs
    Statement when you are executing the SQL only once? I am talking aboutall
    kinds of SQL (Select, Update, Insert and Delete). If PrepatedStatement
    is
    used, I would expect some overhead in setting values for differentcolumns
    separately and precompliling. Is that overhead significant enough to
    degrade performance? If we execute statement only once, I do not expectto
    any gain on performance.
    I would appreciate any comments.
    Sarat

  • Execute query only once in mapping

    Hi All,
    I hav a scenario where I hav to Query a DB using all the child nodes. the source structure is as follows:
    <root>
         <employee>     -
    0..unbounded
              <empNo>
              <emdpName>
         </employee>
    </root>
    I hav to retrieve all the empNo and frame a query and shud execute the query only once and hav to retrieve the results and store it in a HashMap so that, i can map it to the target structure.
    I had followed JAVIER PORRAS blog. but it seems to be not the executed one. Can any one suggest me how to do it. Any help wud b appreciated.
    Thnx in Adv
    Anil

    Hi,
    My requirement is something like this.
    Source : External System
    Target : BW
    Source Structure:
    <Root>
         <Emp>
              <Col1>
              <Name>
         </Emp>
         <Emp>
              <Col1>
              <Name>
         </Emp>
         <Emp>
              <Col1>
              <Name>
         </Emp>
         <Emp>
              <Col1>
              <Name>
         </Emp>
    </Root>
    I'm getting Data from External System in which a column (Col1) has to be replaced by some other column (Col2)
    which exists in the DB. Col2 can b accessed using a query (select col1, col2 from myTable where col1 = x1 or x2 or x3 etc..). The values of X1, X2, X3 etc hav to be filled using the
    Col1 values of each segment of the <Emp> in the source structure. The condition here is that, i shud execute the query only once for all the values of col1 to prevent the bottleneck.when i get the result, i hav to store it in a hashmap and use the result to map it to the target structure element by element.
    This is my require ment. seems to b exactly the blog of JAVIER PORRAS. but the blog doesn't seem to b the executed one.Any help in resolving this.
    Thnx
    Anil

  • Execute Javascript in SCRIPT_ITEM onload, but only once

    Hi,
    if I publish my webtemplate then the javascript function (executeJS_SET_ITEM_PARAMETERS_R) inside the script item is executed. The execution is done via onload="javascript:executeJS_SET_ITEM_PARAMETERS_R".
    Within the JavaScript I create some parameters to change some settings of the webtemplate. At then end the command is executed and the template is refreshed.
    1.The problem is that the Javascript is executed recursively (always onload). How can I ensure that the JavaScript is executed only once (the template only refreshed once)?
    2.Within executeJS_SET_ITEM_PARAMETERS_R these lines are commented:
      //To extract specific values of parameters refer to the following:
      //var key = currentState.getParameter( <b>PARAM_KEY</b>).getValue();
      //alert( "Selected key: " + key );
      What is meant by PARAM_KEY? Maybe I can use this parameter to create a condition that ensures to execute the code only once. Where can I found these PARAM_KEYs?
    Thanks for the info.
    BR, Andreas

    You might try this approach, using the following workflow...
    1) *Get Specified Finder Items* -- press the "+" sign, navigate to the target folder and choose it.
    2) *Set Folder Views* -- move the icon slider to 128, etc., and check "Apply Changes to Sub-folders."
    From Automator's File menu select Save As Plug-in > Plug-in for: Folder Actions.
    The AppleScript, located in the User > Library > Scripts > Folder Action Scripts folder, can then be modified:
    on adding folder items to this_folder after receiving added_items
    tell application "Macintosh HD:Users:username:Library:Workflows:Applications:Folder Actions:Make 128.app"
    run -- 'run' replaces 'open added_items'
    end tell
    end adding folder items to
    This has worked for me consistently (so far) using Mac OS 10.4.11; not tested in Leopard. Your results may vary.
    Good luck.

  • 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

  • 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.

  • Execute default case unless user presses one of several event buttons, in which case execute a different case only once.

    Hello everyone,
    I am communicating with a serial device using the VISA functions. My VISA commands are inside a loop, and per loop itteration I am sending a default command and receiving a message back from my device. However, I would like to incoroporate two non-default cases, which are to be initiated by buttons on the front pannel. When pressed, a corresponding command should be sent to the serial device only once, and then I'd like to go back to the default case. The message coming back fromt the device should be a string, common to all cases - I don't want a separate string per case. How can this be done efficiently?
    I tried to do a three-case case structure, but I haven't figured out how to use boolean switch buttons for more than two cases (I prefer buttons to a drop-down menu selection). I also tried an event structure (which I have no experience using), but these remain idle, and I can't figure out how to make a default case run actively.
    Thank you in advance for your help.
    Solved!
    Go to Solution.

    An event structure has a time out event which you could wire a value to.  The default value (nothing wired to it) is -1 which means never timeout.  You can put in a 0 which means zero timeout, execute the timeout case immediately if some other event hasn't already been queued.  Or put in any value meaning milliseconds.  Wait that many milliseconds and execute the timeout case if another event hasn't happened in the mean time.
    Do combine multiple boolean buttons, build them into an array.  Then search 1-D array for the first true.  A -1 means none are true, a number from 0 to n-1 means that particular element of the array is true.  So you just feed the value to the case structure.  (-1,default   0    1     2    ...)

Maybe you are looking for