LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuously appending an array in a while loop

Hi, everybody.

 

I'm not at all versed in arrays in LabVIEW and have been scratching my head for a while on this. I expect it should be an easy solution, however.

 

Posted in the picture below is a portion of the program I'm writing which is using VISA to communicate with a serial device. Near the bottom-right I am attempting to take the string response from VISA Read, convert it to a float number format, and then feed it into an array by appending it with the "Insert Into Array" VI for each iteration of the while loop and each VISA Read.

 

My issue is that I realize this VI requires an input array and an output array, whereas I am only providing the output array. The only task I am trying to accomplish is to store the data of the repeated outputs of VISA Read per each iteration of the while loop into an array for a future graph. Do you have any tips for how I should go about doing this?

 

Thank you very much.

 

Edit: To fix the image not posting

0 Kudos
Message 1 of 4
(7,364 Views)

Hi Oliver,

 

use a shift register (SR) to store your array. SRs are placed at loop borders...

 

- Your timing in the sequence is flawed: it will run in parallel with the rest of the code and so will hurt your serial port reading. Create a sequence frame in front of the existing one, and put the wait inside there. Waiting for "multpiple" isn't the perfect function here either...

- Usually you don't need BytesAtPort as either you wait for a TermChar (as configured by InitSerialPort) or a certain number of bytes. Then you also don't need an additional wait function.

- When your loops runs for a pre-determined number of iterations you should use a FOR loop instead of a while loop.

- Loop counters should be integers. There's a "-1" function available, too...

- You can put the CR/LF char directly into the string constants. No need to build up strings like you do... Read the help on "string formatting"!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(7,352 Views)
You should be using a shift register with the Build Array function. You should also get rid of the sequence structure and the VISA Read Bytes. Use data flow and the sequence structure is not required. It appears that your instrument uses a termination character so make sure you have it enabled and simply set a high byte count to read.

Both of these concepts have been discussed numerous times and the problem with the insert into array has been discussed today.
0 Kudos
Message 3 of 4
(7,346 Views)

Use a concatenated string then connect it to a shift register of a loop which is inside an event structure as shown below. Play with it and you will have an idea on how to use that concept in your intended program.

0 Kudos
Message 4 of 4
(5,783 Views)