Function global shift registers

Hi all,
I have a functional global that has multiple function.  I can create a file and store the reference in a shift register, open that file and append to it, close the file, etc. 
If I need to create and append for two files, I can't just use that function, since the reference would be lost.  What would be the best way to use functional global to save reference and process multiple files? 
Thanks!
Yik
Kudos and Accepted as Solution are welcome!

jyang72211 wrote:
Hi all,
I have a functional global that has multiple function.  I can create a file and store the reference in a shift register, open that file and append to it, close the file, etc. 
If I need to create and append for two files, I can't just use that function, since the reference would be lost.  What would be the best way to use functional global to save reference and process multiple files? 
Thanks!
Yik
It really depends on how you want to control which of the files get acted on. You could duplicate all of the code for another and add actions unique to thta file or you could keep an array of file refs internally and use a "reference" to control which file you are working on at that call. But if you are going to pass a ref around, it might just as well be a ref to a LVOOP class and that's where mtat's reply comes into play.. but that is hardly an Action Engine answer.
So please tell how the new file compares with the other and to what extent you see this growing in the future.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • Bypassing shift registers

    Being a beginner, I was experimenting with loops and shift registers. Originally I had an add operation that added 1 each time and the results passed back around via a shift register. Maybe I was thinking of op amps at the time but I thought why not just loop the output back to the input instead of going thru the shift register. Seems to work, is it a reliable design?
    thanx,
    jh 
    Solved!
    Go to Solution.
    Attachments:
    feedback.vi ‏19 KB

    jvh75021 wrote:
    Maybe I was thinking of op amps at the time but I thought why not just loop the output back to the input instead of going thru the shift register. 
     Your shift register has absolutely no function here, because you never even use its output anywhere. Click on the shift register and delete it. Run the VI again. Notice no real difference! Now you could right-click the feedback node and "replace it with shift register and still retain about the same functionality. Shift registers and feedback nodes are interchangeable to some degree.
    Important Details: Shift registers and feedback nodes are not completely equivalent. Notable differences exists in the way they can be initialized. A feedback node does not require the presence of a loop (at least in newer LabVIEW versions) and shift registers cannot be globally initialized. Feedback nodes can exist entirely inside a single case of a case structure. Shift registers require a loop on the same subdiagram. Shift registers can be resized on the left to access earlier histories. Feedback nodes can only access one history (selectable in newer versions).
    Shift registers and feedback nodes are central to elegant and efficient code, so make sure to become completely familiar with them. New users often do ugly local variable hacks to approach some of their functionality.
    LabVIEW Champion . Do more with less code and in less time .

  • Functional Global Variable in the CLAD sample Exam

    Hello,
    A question in the CLAD sample exam #2 keeps puzzling me. It's question number 32 about FGVs:
    32. Which is not an important part of creating a Functional Global Variable?
    a. Using Shift Registers to store information
    b. Changing the VI’s execution settings to Reentrant
    c. Setting the VI to inline into calling VIs
    d. Setting the While Loop to stop after one iteration
    The answer given is the following
    32.Correct Answer: B
    Topic: Functional Global Variables
    Justification: It is not necessary to inline functional global variables into their calling VIs. In fact, inlining requires that the subVI be reentrant, which is forbidden for functional global variables.
    Clearly, for an FGV to work properly, the VI must NOT be reentrant. So I would have selected answer B, but the justification seems to clearly point to answer C as well, doesn't it? Is it a typo, a subtlety in the wording? I am stuck on this one!
    Solved!
    Go to Solution.

    Well, inlining requires reentrant.  Therefore, the best answer should technically be C.  This looks like one of those rejected/retired questions since it isn't quite right and/or left up to too much interpretation.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Any way to sample segment length longer than loop iterations w/o shift registers?

    Hi all,
    My loop iterates approx every 0.06s and now i've been asked to add to the program a function which will sample the most recent 3s of data and return the max/min value for two of the signals.  I can think of a programmatically clumsy way to do this with shift registers- take the max/min for each iteration, save-repeat-compare until you have enough iterations to fill 3s of time.  But I can't help but think there has to be a cleaner(better?) way to do this. 
    Any help?
    Thanks
    Solved!
    Go to Solution.

    Hi there,
    Try looking into a circular buffer.  
    http://zone.ni.com/devzone/cda/tut/p/id/7188
    Once you've determined how often you're putting entries into the buffer, you'll know exactly how big of an array to grab and do the Min/Max on.  
    Another option is to use a circular array.  
    http://decibel.ni.com/content/docs/DOC-3414
    I would set this up to function a little like a Functional Global or an Action Engine.   The subVI would then be used in your DAQ loop to "stack" new data.   And then called in another loop or part of your code to be read every three seconds.  
    Patrick Allen

  • Multiple copies of functional global using vi references

    I have several producers aquiring data into a functional global (one functional global per producer). These functional globals are identical except for the name. Would it work to have only one functional global VI and obtain a separate reference for each producer? The matching consumer would also use the proper reference to consume the data.
    The functional global contains an array of the data which must be parsed by the consumer. It is possible that the array of data may not contain a complete set of data on a single "store" operation by the producer. The consumer, of course is written to check for a complete data record before completing processing on the record.
    Solved!
    Go to Solution.

    Les__Bartel wrote:
    tst wrote:
    Regardless of whether there is a better way, the answer to the question is yes. The FGV needs to be reentrant and the reference you open needs to be reentrant too and then you can use the CBR node to run the specific copy of the FGV.
    I thought a reentrant vi would not maintain the state of the uninitialized shift register from one call to the next.
    A reentrant VI will maintain the state of its uninitialized shift registers.  However, you need to be really careful how you do this.  First of all, you need to make sure it is set to Preallocate Clones.  What will happen in this situation is that each different place you call that subVI will each be a different clone.  This means that each call will have its own data.  The problem with this is that you can't share the data across multiple instances and therefore multiple loops.  If you don't believe me, go play with the Mean Point By Point VI.
    So what happens if you set it to shared clones?  A big freakin' mess.  You will have no control over which clone will be called where and there will be some major data corruption.
    This is why FGVs are almost always non-reentrant.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Static Shift registers

    My understanding of shift registers is that if you don't initiaze them
    then they will hold the value from the last instance, hence be static.
    I've created a subvi and placed multiple copies in a case statement,
    all it does is check to see if the value has changed, yet when it runs
    the second time it starts out at zero when it should be  whatever
    number went through the sub the last time.
    Am I missing something here?
    Bundle to byte array contains single to byte array sub vi
    Ron
    Attachments:
    Bundle to Byte array w change.vi ‏29 KB
    Single to Byte array w change.vi ‏10 KB

    You should always consider initializing shift registers. Keep in mind that if you just opened a VI that contains uninitialized shift registers, it won't remember the data from the last time it was run (because it has been unloaded from memory since then), so it's more likely the values in that shift register are garbage. That could be even more dangerous, since how LabVIEW interprets that data could cause very strange and erratic behavior in your application.
    Here's my solution that works for Functional Globals and general shift registers: Consider initializing them the first time the VI is called inside the While Loop, as demonstrated below:
    The First Call VI outputs a true the first time that instance of it is called, and false every other time. For Functional Globals you could alternatively have a dedicated Initialize case to perform this function. The advantage of the technique listed above is that you are guaranteed initialization on the first call, regardless of whether the client programmer remembers to call an initialization case.
    Message Edited by Jarrod S. on 04-11-200612:33 PM
    Message Edited by Jarrod S. on 04-11-2006 12:33 PM
    Jarrod S.
    National Instruments
    Attachments:
    Pic1.jpg ‏7 KB
    Pic2.jpg ‏14 KB

  • How can I activate a functional global without displaying a LabVIEW VI ??

    Hello. I'm using Teststand and have been got stuck on a problem now.
    Whenever I communicate to a LabVIEW VI which is activated as a functional global,  I purposely displayed the LabVIEW VI on front pannel to make sure the data communication.
    However once I released the check mark 'Show VI front pannel when called' , the data transmission including receiving vanished. As a matter of fact, always the numeric data resturns ' 0 '.
    So the data communication must be transacted with a shift resgister function at each step in Teststand, so it always provides a command to the functional global VI for an e-num  item selector.
    Therefore it looks the shift register function doesn't work at the point anymore in the functional global VI.
    Otherwise as long as I suspend the VI as a display, checking on the box 'Show VI front pannel when called' , I exactly can make sure the data communication , receiving the command and returning the data.
    Have you heard that kind of unusal problem before?
    Do you think it happened due to data communication or just simply Teststand applicational error?
    If it has some useful information, I try to fix them. 
    Thank you.
    Noriyuki

    hirose wrote:
    Hello. I'm using Teststand and have been got stuck on a problem now.
    Whenever I communicate to a LabVIEW VI which is activated as a functional global,  I purposely displayed the LabVIEW VI on front pannel to make sure the data communication.
    However once I released the check mark 'Show VI front pannel when called' , the data transmission including receiving vanished. As a matter of fact, always the numeric data resturns ' 0 '.
    So the data communication must be transacted with a shift resgister function at each step in Teststand, so it always provides a command to the functional global VI for an e-num  item selector.
    Therefore it looks the shift register function doesn't work at the point anymore in the functional global VI.
    Otherwise as long as I suspend the VI as a display, checking on the box 'Show VI front pannel when called' , I exactly can make sure the data communication , receiving the command and returning the data.
    Have you heard that kind of unusal problem before?
    Do you think it happened due to data communication or just simply Teststand applicational error?
    If it has some useful information, I try to fix them. 
    Thank you.
    Noriyuki
    I'm not sure about the current versions of TestStand but in previous versions you had the possibility to preload certain test steps or initializer VIs. TestStand made sure to keep them in memory for the entire duration of the particular test sequence. You create such an initializer VI and call your init method in there and mark that step as preload. On loading the sequence or initializing it your step gets called and stays in memory for the entire duration. I would be surprised if TestStand doesn't support this anymore.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Shift Registers not working properly with counter group .vi

    Because I'm not sure how to refer to them as a group.
    Well, because my previous vi only let my DAQ(STC) model no. 6020E read on one channel, I switched to a new set of .vis. They solved my channel problem, but in exchange, they introduced a set of new ones.
    First, when the .vi runs without shift registers(used a function generator for testing), the count ascends at a steady linear rate. That means with shift registers, I should be getting a horizontal line or close to it, right? For some reason, instead of a horizontal line, I instead get a zigzaging line that steadily ascends the amount its supposed to. 
    Sometimes, the count just zigzags up in down from 4 mill to 0 and back again for reasons I do not comprehend.
    I'll upload my new .vi and my old .vi.
    Screenshots too
    http://imageshack.us/g/192/shiftregisterproblem.pn​g/
    http://imageshack.us/photo/my-images/560/idonteven​p.png/
    Attachments:
    Pulse Counter attempt mkIII.vi ‏96 KB
    Pulse Counter attempt mkII.vi ‏43 KB

    Ok, here are the pictures and one of the vis uploaded .
    Attachments:
    idontevenp.png ‏238 KB
    shiftregisterproblem.png ‏223 KB
    daq-stc.llb ‏1736 KB

  • Calculate maximum value of subarray while creating it using a case structure and shift registers

    I have two 1D arrays that contain cyclical information (kind of like a sine wave).  One that contains information on position in degrees and another that contains torque.  I would like to calculate the maximum torque value each time the position is within a certain range (e.g. from 30-80 degrees).  The ranges are repeated - that's why it is cyclical.   I use the "in range" function, a case structure and shift registers to build a new array with values that fall within the range I specify - this was the easy part (see VI attached).  I'm struggling with a way to calculate a maximum value for each subarray formed when values are "in range".   Your help is much appreciated.
    Solved!
    Go to Solution.
    Attachments:
    Simple Calculate between anatomical position range.vi ‏16 KB

    It's not really noise - it's more inconsistency.  So a position output can run: 20, 30, 40, 50, 60 etc.  OR, it could run: 21, 24, 32, 41, 44, 51, 59 etc. But, it is always cyclical. 
    Attached you will find a .csv file with the data arrays - I'm using POS (ANAT) degrees column (column D if you open in excel).  There you also see torque in ft-lbs along with some other information.
    Attachments:
    025C.csv ‏224 KB

  • How do uninitialized shift registers work in reentrant VI's

    If I am using what NI calls "Functional Global Variables" (see link) where you use an unitialized shift register in a "one shot" while loop,  what happens to the functionality of the shift register if the VI is reentrant?
    http://zone.ni.com/reference/en-XX/help/371361A-01/lvconcepts/suggestions_for_exec/
    Solved!
    Go to Solution.

    I was tempted to say that they work as expected, but you have already said that you don't know what to expect.
    A reentrant VI is one that has its own dataspace.  That means that if I have two of them, they each have their own data and know nothing about each other.  This is great for VIs that need to save state for some reason.  Some examples of this are moving averages or some filters.  They need to know values from the last time they were called in order to calculate the answer for this time and they need to keep track of this answer for use in calculations next time they are called.  If these VIs had a single dataspace but were called in several places, their data from last run could be the data from the other call and therefore not be correct. 
    This is where reentrancy comes in.  You merely make this VI reentrant and it saves state correctly because now each call has its own dataspace and therefore its own data.
    Functional Globals work on the opposite principle.  You want to mix the data from one call location with the data from another.  You want to have it save state from this time and use that data reguardless of the caller the next time it is run.  You cannot make Functional Globals into reentrant VIs.
    I hope that this helped.
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • Initialising Shift Registers

    Hi
    I am totaly new to labview so assume that this question can be easily solved!
    I am trying to implement a FIR filter (can't use pre-designed sub vi's because it must operate in accordance with a specified transer function).
    I think I have the design sorted except that I am having trouble with initialising shift registers. I can't get them to work,
    any help would be apriciated.
    Chris
    Attachments:
    initial_filter_design_1.vi ‏57 KB

    You're correct. I should have mentioned this technique.
    The attached image shows how to do this.
    The "First Call" function will only produce a True the first time a VI is called, so the shift register will get initialized the first time the sub-vi runs, then the shift register will retain the value after each call.
    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:
    init_SR_in_loop.gif ‏5 KB

  • Is a functional global with loops inside case structure subject to race condition?

    Such as this one:
    Solved!
    Go to Solution.

    bmihura wrote:
    I'm being a bit dense here... would somebody write an example VI that demonstrates how functional global variables eliminate race conditions whereas a normal global variable would not? Or just describe it and I'll write the VI?
    The classic example used is a bank account.  Say you are making a deposit.  You have to read the current balance, add the deposit amount, and save the balance.  Now say you are making a withdrawal.  You have to read the current balance, subtract the withdrawal amount, and save the new balance.  Now let us say that both of these events happen at the same time.
    If you are using global variables, you read the global, perform the action, and save to the global.  But who reads what balance.  If both events read the balance at the same time, then whoever writes last will overwrite the other's action.  This is bad, especially if your deposit "didn't happen".
    Now using a FGV (or Action Engine), you can contain the critial parts of the code.  In this case the critical parts are the full read, act, and write.  So with the AE, you store the balance in a shift register.  You can perform whatever action you want inside of the AE VI.  Because the AE is not reentrant, only 1 action can be performed at a time.  So you make sure that deposit happens and is not overwritten by the withdrawal.
    Now for my caveat.  If all you do is a Get and Set inside of the FGV, it is basically a global variable, just slower.
    Read that acticle I linked to earlier and also read up on the Action Engine nugget.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Is there and alternativ​e to shift registers for saving data across iterations in a subVI operating inside a loop?

    I am creating a subVI state machine (case structure) which will run inside a while loop which will be executing every 250ms. The reason I wanted to make the state machine case structure into a subVI is because I want to execute 64 of the machines within the same loop. The goal is to monitor certain types of voltage changes on 64 I/O channels on a FP2200 RT module and report periodic details about state changes to a database. My thinking was that by executing each independent machine in the same loop structure, I will only worry about one thread. It seems that the alternative of having one state machine thread per I/O channel is probably more than the RT module can handle. Please correct me if I am wrong on that.
    The issue I'm now having is as I'm creating the state machine, I am finding that I need to keep track of some pieces of data from one loop iteration to the next. This is easy enough to do with shift registers but in order to use them, I have to create additional input nodes to my SubVI as well as output nodes. For example, I want to use a queue to buffer some I/O data but as of now, I have to create this queue outside the loop, pull it into the loop across a shift register, feed it to the subVI, and output it to the out Shift register. It would be better if I didn't have to output this queue because there's no reason for anything to have access to it outside the subVI. It just creates an extra set of wires to look at and makes me worry a bit about maintainability. 
    Is there a better way to approach this problem? 

    You could place a while loop inside your sub vi that has a true constant wired to the stop condition. Then add unitialized shift registers to that while loop to keep data between iterations.
    or you could use a feedback node inside the sub vi

  • LV 8.21: strange behavior with DAQ tasks, parallel running VI's and shift registers

    Hello,
    I have made a VI using DAQmx vi's. The VI uses shift registers to store DAQ tasks and other (internal) information. I have implemented  several modes of operation (enum control with a case structure) like 'init', 'read AD', 'config AD' etc. If I use this multi mode VI in a single main VI everything work as expected. I have attached a jpg that shows one example where the DAQ VI is called from 2 parallel running while loops. One loop aquires the data (LOOP 1) while the other loop configures the aquisition task (LOOP 2). If I implement the same thing by putting LOOP2 in a different VI that runs seperately from the first VI I get an error message (200428):
    Possible reason(s):
    Measurements: Value passed to the Task/Channels In control is invalid.
    The value must refer to a valid task or valid virtual channels.
    Task Name: EasyDAQ_AD
    Of course, the second VI is started manually after the 1. VI has passed the initialization part. The error message is triggered from the 1. VI that executes the DAQ task. From my understanding of the LV execution system this seems like a bug to me. Does anyone have an idea what could go wrong here?
    klaus
    Attachments:
    problem.jpg ‏30 KB

    1. In general, this kind of technique is something I've been using successfully for years.  (Ben recently wrote up a very nice treatment of these "Action Engines" as a "Community Nugget.")  So I don't start by expecting this to be a bug in the LV execution system.
    2. Your description of the problem sounds almost backwards.  You say you manually start the 2nd vi ("Config AD") *after* running the 1st vi ("Read AD").  Seems like you'd need to do the Config 1st and then do the Read, right?   I kinda suspect you actually did it in the right order, but described it wrong.
    3. The next likely scenario is that the Config failed, but you didn't trap the error and were unaware of it.  Then it makes sense that the Read would also fail.
    4. A couple issues I regularly deal with in these DAQ Action Engines is internal error handling.  I often keep a shift register inside to store errors generated inside the Action Engine.  But it can get a little tricky doing sensible things with both the internal error and any other error being wired in as input.
    I said all that so I can say this: if you have complex nested case statements, or lots of different action cases to handle, double check that the task wire makes it from all the way from left shift register to right.  Sometimes they get lost if they go through a case statement, the output tunnel is set to "use default if unwired", and 1 or more of the cases don't wire the output.
    -Kevin P.

  • Using functional global variables to transfer data between touch screen device and other targets

    Hi,
    We are currently developing a control system that will operate on a cRIO with a touch screen interface. During development we have been using functional global variables (FGVs) to handle most of the settings/data etc, however we have just realised that we may have an issue updating the data on the touch screen, and vice versa.
    Previously we have implemented similar programs using shared variables, however we were wondering if there is anyway to implement FGVs in a similar manner, whether it'd be a combination of FGVs and shared variables.
    Regards,
    Mike
    Software version: Labview 8.2.1

    See this thread on LAVA about sharing FGV's across projects. THis should be extendable to cross paltforms (I believe).
    You also may want to concider an upgrade to LV 8.5.1. We have found a number of performance related issues with LV 8.2.1 and RT.
    If you decide not to upgrade, just remeber what I wrote (above) when you have reason to question the performance.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • Relation  between BSIK,BSIK  and BSEG

    Hi  all , 1. what we mean by  the open items table (BSIK) and  item table (BSAK). 2. What  is the realtion between BSIK,BSAK  with mm tables ..please give me the realtionship. 3. when we post  in FB01 which are tables are updated 4. IF BSEG is the su

  • How to handle the failed records from the table when using DB Adapter

    Hi, I am reading some records from table using DB Adapter inside my synchronous BPEL process. Say like reading 100 records from table in between after successful reading of 90 records an error occured in 91st record due some various reasons(like DB d

  • Delays in ECC async background processing

    Hi all, Has anyone dealt with delays in ECC async background processing?  On our development system the delays are running in the 3-20 second range. I  have a BLS transaction that 1.  Creates a Time Ticket for operation confirmation 2.  Does COWBPACK

  • Iweb hyperlinks

    I'm new to iweb. I'm re-doing my web site that I manually entered HTML coding for. In iweb, I can't figure out to have hyperlinks appear as a different color from the main text, nor can I get it underlined. The links do work, but they are not obvious

  • Completion Insight seldom works

    Running ver. 3.1.07. Completion Insight seldom/seldom/seldom works. I have it turned on. Suggestions. I thought I sent a debug/trace file with a new thread but can't find it and don't find the directions recreate the debug/trace file. Any suggestions