08-08-2017 03:53 PM
When I write an expression in my program ("2+2-1" for example) I want my program to make an array of all numbers in the expression (2,2,1) and an array of all operators in the expression (+,-).
The program does that successfully. HOWEVER, when I input an expression and then run the program multiple times, the arrays stack the newer values on top of the old ones.
What I want the arrays to do is NOT to stack the values up, but to reset to their default values in the beginning of each run of the program. I'm a beginner in LabVIEW and I could not find a solution that I could understand. I tried everything: initializing a shift register connected to the array, using an invoke node, initializing via an empty array constant, etc. I wasted hours on a matter which should be trivial.
I uploaded a simple version of my program. Please modify it so that the arrays always start from their default values (which are the "empty" values).
I must be missing something fundamental but I simply could not get it to work.
Solved! Go to Solution.
08-08-2017 04:07 PM
Right-click the intializer terminal for your feedback nodes and choose Create constant, it will create an empty array.
That should solve your problem.
mcduff
08-08-2017 04:12 PM
I must confess that Feedback Nodes always confuse me -- I do understand the idea, I just find Shift Registers and While Loops easier to grasp.
That being said, look at the bottom of the Feedback Loop (point your mouse there on a Block Diagram). See the little (unwired, in your code) terminal called "Initializer Terminal"? Wire your desired Initial Value there, and see if that fixes your problem.
And don't worry -- unexpected terminals in LabVIEW functions eventually Byte all of us on the behind ...
Bob Schor
08-08-2017 04:27 PM
Okay wow. I knew my problem was stupid, but I didn't think it was this stupid. I can't believe I failed to grasp something so simple haha. Thank you guys! I would've spent many more annoying hours on this issue without your help!
08-09-2017 09:37 AM
@Bob_Schor wrote:
I must confess that Feedback Nodes always confuse me -- I do understand the idea, I just find Shift Registers and While Loops easier to grasp.
Ditto. Especially when used in conjunction with a while loop. If you already have a while loop, why not use shift registers?
08-09-2017 09:48 AM - edited 08-09-2017 09:49 AM
aputman ha scritto:
@Bob_Schor wrote:
I must confess that Feedback Nodes always confuse me -- I do understand the idea, I just find Shift Registers and While Loops easier to grasp.
Ditto. Especially when used in conjunction with a while loop. If you already have a while loop, why not use shift registers?
I thought the same until a few days ago. Then I realized that one of my Shift Register values was used only in a very small portion of the loop structure. Replace it with a Feedback Node and - voilà - I got rid of a long wire with less clutter in the block diagram!
08-09-2017 10:22 AM
@pincpanter wrote:
I got rid of a long wire with less clutter in the block diagram!
I avoid long wires by keeping my diagrams and loops small. If you have to scroll to see where a wire leads, you most likely have chosen a poor architecture or your wiring is just sloppy.
Feedback nodes can be stashed away in some far corner of a while loop and there is no visual indication of dataflow and IMO, they seem to break dataflow by routing a wire back into itself. That goes against all that is right and good. However, with shift registers, you can clearly see that there is data coming into the loop and it's easy to follow the logic. Personal preference I guess.
08-09-2017 10:24 AM
As has been discussed before, there are subtle differences between SR and FN (e.g. the two modes of "global initialization" for the FN). Yes, a FN can often be contained entirely in one case of a case structure which often makes simpler code. Still, we lack some functionality that would make this scenario even better. I typically use SRs for the main state machine, but FNs everywhere else.