LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine which instance of a class casued an error

I have several classes that include some form of communication with different sensors. Occasionally the communications fail becasue a sensor drops the communication line. This generates an error.

 

I have multiple sensors, so have multiple objects of the same class. I also have several different classes, so several different objects

 

When an error is generated, the error cluster does not contain any infomation to tell me which particlar object of a class generated the error. So if I merge errors, or don't know the order at which the errors come in, I can't tell which sensor has a problem. Is there a sensible way to get this infomation?

 

I thought of writing a small sub vi that injects some object information into the error out cluster of each class method. Any other suggestions?

 

In this simplified example how do I tell which object generated an error?  (I know that, in the example, only the last error is caught even if multiple errors are generated)

 

 

DavidU_1-1647018802871.png

 

DavidU_2-1647019788026.png

 

 

 

0 Kudos
Message 1 of 8
(1,033 Views)

I would recommend that you use custom error codes for your classes. Have you class methods build the custom error and include the necessary information you nee such as class type, object instance, etc. Then in your for loop create an array of your error responses (you really only need to include error responses, no need to save the "no error" states) and then process, log or handle them as necessary.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 8
(1,026 Views)

Try this

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 8
(1,004 Views)

Hi Paul,

 

Many thanks for replying. I only have LV2017, please could you convert your vim.

 

Thanks

Dave

 

0 Kudos
Message 4 of 8
(991 Views)

In this particular case, if you change from a shift register to an array of errors on the output, you can just check each array element for errors and match those with the array indexes of the input array.

 

Also, remember that errors are just clusters.  You can edit them as-wanted to add extra information.  Just check for an error coming out of the subVI, and if there is one, edit the error text to include the loop iteration number or some other information contained on the object wire that allows you to see which object it was.

Message 5 of 8
(964 Views)

@DavidU wrote:

Hi Paul,

 

Many thanks for replying. I only have LV2017, please could you convert your vim.

 

Thanks

Dave

 



Here.

"If you weren't supposed to push it, it wouldn't be a button."
Message 6 of 8
(927 Views)

It seems to me that there are "multiple" problems here.  One is stated in the Title -- how to determine which instance of a class caused the Error.  As noted, you could generate a User Error with a message that includes the Class Instance.

 

However, another question/issue is the behavior of the Merge Error function, which (if there are multiple errors) only returns the first error.  When you have a single error, there is no issue -- handle the Error.  When you have multiple Error Lines and need to handle the possibility of more than one Error coming in, you can at least acknowledge them all by combining them with "Build Array" and write a VI "Handle Multiple Errors" that consists of a For Loop that processes each Error Line in sequence (especially if you write to an Error Log without otherwise stopping your program, though you could have an Exit condition "Fatal/Non-Fatal" to govern whether or not you continue).  This probably takes (a little) more time than processing a Merge Errors, but you don't "lose" information about simultaneous asynchronous Errors.

 

I vaguely think I wrote such a thing once (probably didn't know any better ...).

 

Bob Schor

Message 7 of 8
(915 Views)

Thanks all,

 

I went with generating a unique ID for each instance (using an FG incrementing a counter) and custom error codes that included the unique ID and other useful infomation in the source.

 

0 Kudos
Message 8 of 8
(893 Views)