LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Output true values from case structure

 

I have been writing a program for about a week now.  This project involves communicating via RS-485 to a stepper motor driver as well as a displacement sensor.  Long story short I use the stepper motor to rotate a surface which gets measured with a displacement sensor.  To gain some confidence in the meaurement I repeat the measurement several times, take an average, and report that value.  At the click of a button this process is repeated.  Here is a quick summary of what I am trying to do.

 

I am using a case structure in such a way that when the user clicks a button a loop initiates.  This loop rotates the surface, measures it, rotates back and repeats this process five times.  An array is built which contains the five measurements.  I use several of these case structures so that ten of these measurements can be performed.  At the end of the program I have ten, seven element arrays.

 

Up to this point everything is fine.  Now comes the problem.  When trying to write the data to a text file I have tunneled the array out of the case structure.  Since the case is only true for the short time the loop is being performed the data does not persist upon the exit of the case structure.  Is there a way to pass the data out of the case structure while the case is true?  Maybe there is a trick for handeling the false case?

 

Thank you for the help.  I have atached two images to maybe clear up what I am getting at.

Download All
0 Kudos
Message 1 of 8
(3,825 Views)

It is very difficult to troubleshoot an image of a portion of a block diagram.  It is usually better to post your VI.

 

My guess is that you should use a shift register to pass the data from one iteration to the next. The True case puts new data into the shift register. The false case is wired straight through so the old data is retained.

 

Lynn

0 Kudos
Message 2 of 8
(3,801 Views)

Like Lynn said, Shift Register is the way to go. A simple example is shown.

 

Untitled.png


Kudos are the best way to say thanks 🙂
0 Kudos
Message 3 of 8
(3,779 Views)

Hi Lynn,

 

Thank you for your comment.  I originally tried using a single loop with a shift register and outputted the data as an array.  The problem I ran into was I could not figure out how to have the array essentially append to itself with each iteration.  After struggling with that for a while I thought to myself why be fancy and just created a subvi and make 10 instances.  Once all of that was figured out I ran into this problem with saving the data.  Thinking back I believe I would have had the same problem moving the data out of the case structure.

 

Chris

0 Kudos
Message 4 of 8
(3,773 Views)

Thank you for the idea.  I played around with a shift register but ran into a problem where I could not figure out how to append the current loops array to the previous.  I jut kept overwriting the array.  Rather than struggle for a few days I figured I would just create a subvi and implement 10 instances. That is where I ran into this problem saving the data.

 

It's not elegant but aside from writing the arrays to a file I have everything working well enough.  Once I am done with testing the hardware and feasibility a legitimate programmer will make a more suitable program.

0 Kudos
Message 5 of 8
(3,771 Views)

You could use something like this. On the "build array", you have to right click and check concatenate so it'll append the data. Otherwise, it'll add dimensions to your array. Hope this helps.

 

$20907732559E68E.png


Kudos are the best way to say thanks 🙂
0 Kudos
Message 6 of 8
(3,748 Views)

@97sportster wrote:

Thank you for the idea.  I played around with a shift register but ran into a problem where I could not figure out how to append the current loops array to the previous.  I jut kept overwriting the array.  Rather than struggle for a few days I figured I would just create a subvi and implement 10 instances. That is where I ran into this problem saving the data.

 

It's not elegant but aside from writing the arrays to a file I have everything working well enough.  Once I am done with testing the hardware and feasibility a legitimate programmer will make a more suitable program.


While it might be working now from your description I would not want to inherit this code to work on it later. It is well worth your effort as well as for the sanity of the next person to work on the code to learn how to properly use shift registers and avoid kludgey implementations. You will thank yourself in the long run.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 8
(3,734 Views)

Thank you all for your advice.  Being a new user of LV I kept going back and forth in ways to accomplish the goal.  In the end I made a more respectable code using shift registers and event structures rather than copying and pasting code over an over.

 

Anyway, thank you.

0 Kudos
Message 8 of 8
(3,703 Views)