LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

arrays and shift registers

Hello NI community. 

 

I am having an issue with a system I am trying to develop. I have gotten it 95% but just cant push it over the finish line. The end goal is to output 5 measurements into an excel spreadsheet directly from lab view at the press of an external switch. Then repeat the process for ever time the switch is closed.

 

The issue is that I am unable to input data into an aray below the previous line (switch closure). I am trying to use shift registers right now, but cant seem to get only one value in the aray once the switch is pressed.

 

 

Thank you in advance for your help,

 

Andrew

0 Kudos
Message 1 of 11
(3,537 Views)

I assume you are talking about the small while loop in the upper right corner. Since it only iterates once and the shift register gets initialized with every execution of the FOR loop, the shift register makes no difference. Maybe you should place the shift register in the outer loop instead.

 

Instead of writing to excel, I would write to a plain tab delimited text file. If you just want to append the new data, you don't need a shift register at all, because the history is already in the file.

 

(... And please don't use creative colors on the diagram. The grey background makes boolean wired hard to see.)

 

You might also consider simplifying the code. You could use an array of tanks, for example. Having the extra indicator for each tank is also no needed. Simply right-click the tank and select "visible items..digital display". Move the digital display to the desired place and set the formatting if needed.

0 Kudos
Message 2 of 11
(3,532 Views)

Thank you altenbach,Very helpful

.

This is my first experience with LabVIEW, I have slowly went back and updated my completely inefficient code as I learn more. Thanks for the advice.

 

Im still not sure how to assemble the data into a file in the following way. I need to write a one dimentional(1x4 array) into a two dimentional (nx4 array) where n can be anything from one to inf. The 1x4 array is going to be the first set of data taken from the first first part. It will then be stored into the nx4 array. The next line that will be written will be a different part, activated by an external switch. This process will repeat for n number of parts. I have been incapable of producing anything that will accomplish this.

 

Any other comments would be greatly appreciated.

 

Andrew

 

 

0 Kudos
Message 3 of 11
(3,486 Views)

If you want to add a new row of four every time, you need to place the shift register in the outer loop and add the new to the 2D array using "build array". If you use a case structure, wire the array across the other case unchanged if nothing should be added there.

 

Here's a simple example.

 

 

0 Kudos
Message 4 of 11
(3,472 Views)

The sample provided was helpful.

 

I understand how to create an arbitrary array, but i need to be able to write to the next line at the press of a switch. (each switch press must create a new line.)

 

I tried using a case statement but it didnt seem  to work as I had hoped.

 

Thank you!

 

Andrew Gascon

0 Kudos
Message 5 of 11
(3,405 Views)

Sorry. Here is a copy of what I am working on. 

0 Kudos
Message 6 of 11
(3,402 Views)

I've taken the example previously posted and added an event structure to monitor a new button and the stop button. When either of them are pressed, the event fires and a new row is added to the array. You could also do this without an event structure, by wiring the "Add Row" switch into a case structure and building the array in the true case, and simply wiring the 2D array straight through the false case. 

Nathan Murphy
Message 7 of 11
(3,360 Views)

@gascon26 wrote:

Sorry. Here is a copy of what I am working on. 


This is still pointless. the shift register needs to sit on the big (outermost) while loop.

0 Kudos
Message 8 of 11
(3,339 Views)

Your attached code was very useful I was unaware of the power of a state structures. The problem that I am having now is passing the values of an array between two while loops. The problem is that a  changing array is created in while loop 1 while while loop two is to write the sampled data when button is pressed.

 

Attempted Solutions:

  1. I attempted to just wire them directly together...
    • Problem: The first loop only executes once and only that one piece of data is sent to the Next line of the  array at the push of the button.
  2. I attempted to move the contents of the 2nd while loop ( write to next line of array) into the main while loop...
    • Problem: Would not operate propperly (unknown reason)
  3. I attempted to place a while loop around both while loops.
    • Problem: The first loop only operates once, and that value and only that value is able to be sent to next line of array.
  4. I thought about using local variables, the solution that I thought would work perfectly (doesnt work to transmit array data from one loop to another??)

 

 

0 Kudos
Message 9 of 11
(3,237 Views)

What you are looking for is a "Master-Slave design pattern"  Read up on them from the example finder.

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 11
(3,219 Views)