LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arrays caused by for loops, error clusters and error handling.

Solved!
Go to solution

Thank you for your help.

 

I am currently working on a program for 20+ sensors and will eventually post the "Alpha" code but I want to make it less of an embarrassment first. In the process of implementing the advice I've run into problem.

 

I went to put some code in a sub vi to make things simpler and because I know I'll be using the code multiple times. I went to wire the error cluster and found it was an array of 9 error clusters. Then I checked my code and found it's a product of for loops and all of the output data is in an array. I can see why that's the case but I'm trying to figure out the best way to handle it.

 

I'm considering adding another loop that checks the error clusters in the array and sends the first one with an error or a single error cluster if there isn't an error. But if there's a better way I thought I'd check with you all.

 

The resources I could find for error handling were a wall of text so if I missed a simple solution I apologize.

https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/error_checking_and_error_handling/

https://zone.ni.com/reference/en-XX/help/371361E-01/lvconcepts/error_checking_and_error_handling/

https://www.ni.com/getting-started/labview-basics/handling-errors

And YouTube, my go to source, wasn't much help

garthenar_0-1624572497774.pngmy "initializer" where the subVI will go

 

garthenar_1-1624572509044.pngthe subVI with some code showing whats going on.

 

 

 

------------------------------------------------------------

Special thanks to those who responded to my first post

GerdW

AeroSoul

Jamosgee

wiebe@CARYA

Mark_Yedinak

And also, to those who responded to my second post

RavensFan

rolfk

 

I hope you can all see your influence on my code.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.
0 Kudos
Message 1 of 10
(1,303 Views)
Solution
Accepted by topic author garthenar

@garthenar wrote:

Thank you for your help.

 

I am currently working on a program for 20+ sensors and will eventually post the "Alpha" code but I want to make it less of an embarrassment first. In the process of implementing the advice I've run into problem.

 

I went to put some code in a sub vi to make things simpler and because I know I'll be using the code multiple times. I went to wire the error cluster and found it was an array of 9 error clusters. Then I checked my code and found it's a product of for loops and all of the output data is in an array. I can see why that's the case but I'm trying to figure out the best way to handle it.

 

I'm considering adding another loop that checks the error clusters in the array and sends the first one with an error or a single error cluster if there isn't an error. But if there's a better way I thought I'd check with you all.

 

The resources I could find for error handling were a wall of text so if I missed a simple solution I apologize.

https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/error_checking_and_error_handling/

https://zone.ni.com/reference/en-XX/help/371361E-01/lvconcepts/error_checking_and_error_handling/

https://www.ni.com/getting-started/labview-basics/handling-errors

And YouTube, my go to source, wasn't much help

garthenar_0-1624572497774.pngmy "initializer" where the subVI will go

 

garthenar_1-1624572509044.pngthe subVI with some code showing whats going on.

 

 

 

------------------------------------------------------------

Special thanks to those who responded to my first post

GerdW

AeroSoul

Jamosgee

wiebe@CARYA

Mark_Yedinak

And also, to those who responded to my second post

RavensFan

rolfk

 

I hope you can all see your influence on my code.


The issue you see is because output tunnels default to "autoindex" which, as you've seen, sticks the result in an array.  For the error array issue, you have two options:

  1. Change the tunnel type to "last" value.  Do this if you want the FOR loop to execute the code inside even if you have an error.  The downside to this is that if your FOR loop executes zero time - for instance, autoindexing an empty array - any error from on the input will NOT appear on the output and you may be swallowing errors.
  2. Change the tunnel to a shift register.  This will ensure that any errors on the input will propagate to the output.  Use this method if you want to skip the code inside on error until all iterations have completed.
Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 10
(1,291 Views)

Thank you Bill! I was just trying to figure out how to add a shift register to it so you're comment came at a perfect time.

 

Once again, thank you for the help.


@billko wrote:

@garthenar wrote:

Thank you for your help.

 

I am currently working on a program for 20+ sensors and will eventually post the "Alpha" code but I want to make it less of an embarrassment first. In the process of implementing the advice I've run into problem.

 

I went to put some code in a sub vi to make things simpler and because I know I'll be using the code multiple times. I went to wire the error cluster and found it was an array of 9 error clusters. Then I checked my code and found it's a product of for loops and all of the output data is in an array. I can see why that's the case but I'm trying to figure out the best way to handle it.

 

I'm considering adding another loop that checks the error clusters in the array and sends the first one with an error or a single error cluster if there isn't an error. But if there's a better way I thought I'd check with you all.

 

The resources I could find for error handling were a wall of text so if I missed a simple solution I apologize.

https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/error_checking_and_error_handling/

https://zone.ni.com/reference/en-XX/help/371361E-01/lvconcepts/error_checking_and_error_handling/

https://www.ni.com/getting-started/labview-basics/handling-errors

And YouTube, my go to source, wasn't much help

garthenar_0-1624572497774.pngmy "initializer" where the subVI will go

 

garthenar_1-1624572509044.pngthe subVI with some code showing whats going on.

 

 

 

------------------------------------------------------------

Special thanks to those who responded to my first post

GerdW

AeroSoul

Jamosgee

wiebe@CARYA

Mark_Yedinak

And also, to those who responded to my second post

RavensFan

rolfk

 

I hope you can all see your influence on my code.


The issue you see is because output tunnels default to "autoindex" which, as you've seen, sticks the result in an array.  For the error array issue, you have two options:

  1. Change the tunnel type to "last" value.  Do this if you want the FOR loop to execute the code inside even if you have an error.  The downside to this is that if your FOR loop executes zero time - for instance, autoindexing an empty array - any error from on the input will NOT appear on the output and you may be swallowing errors.
  2. Change the tunnel to a shift register.  This will ensure that any errors on the input will propagate to the output.  Use this method if you want to skip the code inside on error until all iterations have completed.

Thank you Bill! I was just trying to figure out how to add a shift register to it so you're comment came at a perfect time.

 

Once again, thank you for the help.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.
Message 3 of 10
(1,288 Views)

Hi garthenar,

 


@garthenar wrote:

garthenar_1-1624572509044.png

I hope you can all see your influence on my code.


Well, in this image there is only little influence visible… 😄

Please:

  • Don't convert arrays to clusters when you just want to use unbundle afterwards! A simple IndexArray will provide the very same result!
  • Do you really need to send your command byte-by-byte with a 25ms delay between each char? Isn't your device able to handle strings of 4 or 7 chars when sent within milliseconds?
  • What's the point of that 10ms wait outside the loop? (It will only take effect when the command string is empty: this should be handled in a different way!)
  • You don't need to wire a "0" constant to index the first element of an array…
  • As said before: learn about the different types of loop tunnels and about shift registers!
Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 4 of 10
(1,200 Views)
Solution
Accepted by topic author garthenar

Another method for dealing with the array of error clusters is to pass the array into the "Merge Errors" function after the loop is done.  The overall behavior is slightly different than the 2 methods billko mentioned.  An error occurring in an early iteration will still let you execute code normally in a later iteration.  But at the end of all iterations, you'll be able to know if *any* of them produced an error rather than just knowing if the *last* iteration did.

 

I've used all 3 approaches -- the best choice depends on the particular situation.   

 

I tend to use the Merge Error function a fair amount because there are times I don't wire the 'error in' of certain functions that need to run no matter what happened on the error wire upstream.  Then after it runs I merge it in *below* the original error wire.  (The error output of "Merge Errors" will be the 1st error seen of all the ones getting merged, working top to bottom.)

 

 

-Kevin P

Message 5 of 10
(1,178 Views)

@GerdW wrote:

Hi garthenar,

 


@garthenar wrote:

garthenar_1-1624572509044.png

I hope you can all see your influence on my code.


Well, in this image there is only little influence visible… 😄

Please:

  • Don't convert arrays to clusters when you just want to use unbundle afterwards! A simple IndexArray will provide the very same result!
  • Do you really need to send your command byte-by-byte with a 25ms delay between each char? Isn't your device able to handle strings of 4 or 7 chars when sent within milliseconds?
  • What's the point of that 10ms wait outside the loop? (It will only take effect when the command string is empty: this should be handled in a different way!)
  • You don't need to wire a "0" constant to index the first element of an array…
  • As said before: learn about the different types of loop tunnels and about shift registers!

Hey GerdW,

  • Yeah, the arrays to clusters was just me messily taking a look at what was happening. It's not "actually part of the code" if that makes sense.
  • No, I don't think so at all. This was actually the start of me whittling down the number. The code I inherited had it at 50ms and other parts had numbers as large as 500ms. You probably saved me some time, I was going to go down in increments of 5ms but I'll go ahead and cut it straight down to 5ms for my next test and go from there. (I'm an undergrad so I have to get a feel for these things)
  • That delay is going to go on the outside of the subVI to give the device time to process the command. It's part of the code I inherited and I was going to mess with it later. Any advice?
  • Cool. I'll keep that in mind.
  • Yep, and I have been. In this case the hard way. recently though my focus has been on arrays, clusters, channel wires, OOP, etc. Tunnels are next up on the chopping block since they're the next stumbling block in my data flow.

Thanks.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.
0 Kudos
Message 6 of 10
(1,168 Views)

@Kevin_Price wrote:

Another method for dealing with the array of error clusters is to pass the array into the "Merge Errors" function after the loop is done.  The overall behavior is slightly different than the 2 methods billko mentioned.  An error occurring in an early iteration will still let you execute code normally in a later iteration.  But at the end of all iterations, you'll be able to know if *any* of them produced an error rather than just knowing if the *last* iteration did.


Thanks, that's going in to my notes (with credit of course). I'm trying to get a feel for the error handling right now so I'll play with all three methods today.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.
0 Kudos
Message 7 of 10
(1,166 Views)

@GerdW wrote:
  • What's the point of that 10ms wait outside the loop? (It will only take effect when the command string is empty: this should be handled in a different way!)

Turns out I don't even need that outside of the subVI like they had. When I started I put way to much faith in the code I inherited since it was written by an engineer at the company that made the product.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.
0 Kudos
Message 8 of 10
(1,159 Views)

@Kevin_Price wrote:

Another method for dealing with the array of error clusters is to pass the array into the "Merge Errors" function after the loop is done.  The overall behavior is slightly different than the 2 methods billko mentioned.  An error occurring in an early iteration will still let you execute code normally in a later iteration.  But at the end of all iterations, you'll be able to know if *any* of them produced an error rather than just knowing if the *last* iteration did.

 

I've used all 3 approaches -- the best choice depends on the particular situation.   

 

I tend to use the Merge Error function a fair amount because there are times I don't wire the 'error in' of certain functions that need to run no matter what happened on the error wire upstream.  Then after it runs I merge it in *below* the original error wire.  (The error output of "Merge Errors" will be the 1st error seen of all the ones getting merged, working top to bottom.)

 

 

-Kevin P


I TOTALLY forgot about this approach!  This is an excellent idea as well.  Kevin's post deserves a solution as well.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 10
(1,154 Views)

@billko wrote:

@Kevin_Price wrote:

Another method for dealing with the array of error clusters is to pass the array into the "Merge Errors" function after the loop is done.  The overall behavior is slightly different than the 2 methods billko mentioned.  An error occurring in an early iteration will still let you execute code normally in a later iteration.  But at the end of all iterations, you'll be able to know if *any* of them produced an error rather than just knowing if the *last* iteration did.

 

I've used all 3 approaches -- the best choice depends on the particular situation.   

 

I tend to use the Merge Error function a fair amount because there are times I don't wire the 'error in' of certain functions that need to run no matter what happened on the error wire upstream.  Then after it runs I merge it in *below* the original error wire.  (The error output of "Merge Errors" will be the 1st error seen of all the ones getting merged, working top to bottom.)

 

 

-Kevin P


I TOTALLY forgot about this approach!  This is an excellent idea as well.  Kevin's post deserves a solution as well.


All taken care of. I didn't know I could accept multiple solutions.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.
Message 10 of 10
(1,146 Views)