From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-24-2021 05:23 PM
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
my "initializer" where the subVI will go
the 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.
Solved! Go to Solution.
06-24-2021 05:57 PM
@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
my "initializer" where the subVI will go
the 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:
06-24-2021 06:05 PM
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
my "initializer" where the subVI will go
the 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:
- 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.
- 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.
06-25-2021 01:46 AM
Hi garthenar,
@garthenar wrote:
I hope you can all see your influence on my code.
Well, in this image there is only little influence visible… 😄
Please:
06-25-2021 08:39 AM
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
06-25-2021 10:49 AM
@GerdW wrote:
Hi garthenar,
@garthenar wrote:
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,
Thanks.
06-25-2021 10:53 AM
@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.
06-25-2021 11:30 AM
@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.
06-25-2021 11:55 AM - edited 06-25-2021 11:55 AM
@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.
06-25-2021 12:32 PM
@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.