LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace array subset in parallel for loop

Solved!
Go to solution

There are plenty more questionable code constructs. For example in your first loop it makes no sense to built the array in a shift register. You are also suppressing all errors except the one from the last iteration. Instead of the "merge error", you might even want to keep the array of errors so the later FOR loop runs correctly if one of the channels could not be created.

 

The alternative method is also safer, because of you enter a count that is higher than the array of channels, it will stop once it runs out of array elements.

 

Compare:

 

0 Kudos
Message 11 of 13
(893 Views)

@altenbach wrote:

I don't know if it makes a difference to the compiler, but the concatenating output tunnel in the previous example does NOT know the array size coming from each iteration. It would be worth investigating to ensure that each iteration outputs a 4 element array, even if fewer or more elements are returned or an error occurs.

 

Here is what I would try:

 

 

 

Since we are replacing a four element array with new data, the output will always be a 4 element array. Similarly, if an error occurs in one of the reads (e.g. timeout or other problems), you'll just get 4 NaNs. Seems much more deterministic and the final array size can be determined before the loop runs.

 

 


And of course you intended to pass the error cluster through using a shift register in the event that an upstream error resulted in an empty array of VISA refs.

 

Smiley Wink

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 12 of 13
(891 Views)

@Ben wrote:

nd of course you intended to pass the error cluster through using a shift register in the event that an upstream error resulted in an empty array of VISA refs.

 


No, I would carry an array of errors from the init loop shown in my message above. Since each serial port is independent, we don't want to ignore all of them if only one is faulty. 😄 There might still be some useful data, even if one channel is missing.

0 Kudos
Message 13 of 13
(888 Views)