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-10-2021 08:39 AM
If I'm reading that right, your Event Reference isn't initialized/set before it's used.
Make sure that the event reference is correctly created using Create User Event, or handle the error 1 until it is created (it might be you know sometimes it will be used before initialized, in that case you must handle the error).
06-10-2021 08:42 AM
@mahalakshmi05 wrote:
Error will come only when "Message in" is not in the specified class, right?
Yes. No error when the message is of the tested class. But if you test against an array of classes, then most of them will be errors (more than one can succeed if you have inheritance between messages, but that's unusual with Actor Framework I think). Usually 0 or 1 will be not errors, and the rest will be errors.
06-10-2021 11:02 AM
To More Specific Class does NOT work for this purpose; you need to use Preserve Run-Time Class.
While it is true that you can bundle different class types into an array, the output wire's type is that of the closest common parent. When you are putting different messages into an array, the closest common parent's type is Message.lvclass.
To More Specific Class will try to cast your object to the type of the wire you connected to the Target Class input of To More Specific Class. That type is "Message.lvclass", so your cast will always be successful.
Preserve Run-Time Class, on the other hand, will try to cast your object to the type of the object on the wire that you connected to the Target Object input. Note the difference in input names: Target Class vs. Target Object. The target object is the actual message object at that position in the message array, which is what you want. You'll get an error out if the object types don't match, and no error if they do.
06-10-2021 11:22 AM
@justACS wrote:
To More Specific Class does NOT work for this purpose; you need to use Preserve Run-Time Class.
While it is true that you can bundle different class types into an array, the output wire's type is that of the closest common parent. When you are putting different messages into an array, the closest common parent's type is Message.lvclass.
Bother. Sorry, should have checked code rather than misposting.
Here's an image of some working code...
Hopefully I won't soon be told that this contains a bug too...
06-10-2021 11:23 AM
@justACS escreveu:
To More Specific Class does NOT work for this purpose; you need to use Preserve Run-Time Class.
While it is true that you can bundle different class types into an array, the output wire's type is that of the closest common parent. When you are putting different messages into an array, the closest common parent's type is Message.lvclass.
To More Specific Class will try to cast your object to the type of the wire you connected to the Target Class input of To More Specific Class. That type is "Message.lvclass", so your cast will always be successful.
Preserve Run-Time Class, on the other hand, will try to cast your object to the type of the object on the wire that you connected to the Target Object input. Note the difference in input names: Target Class vs. Target Object. The target object is the actual message object at that position in the message array, which is what you want. You'll get an error out if the object types don't match, and no error if they do.
I was about to write something like that, but the answer couldn't be more complete.
Comparing classes can be tricky.
06-10-2021 11:26 AM
@cbutcher wrote:
Here's an image of some working code...
Thanks for posting that. I didn't feel like getting my graphics game on this morning.
06-10-2021 11:31 AM
I had similar thoughts, but wasn't 100% confident without firing up LabVIEW to check. I figured either someone else like Allen would respond or it just simply wouldn't work, which would prompt another post.
06-11-2021 01:30 AM
Thanks a lot cbutcher, that helped to get more clarity. Sorry for troubling you with one more doubt. It goes like this...
If I am redirecting one of my messages which is originally sent to "Child 1" to the "Grandchild", should I have the same method and message created in the "Grandchild's prelaunch init" ?
I have String message to be redirected, so i should have the user event created in both Child1 and Grandchild ?
06-11-2021 02:26 AM
Thanks everyone for joining up in this discussion. It helped a lot.
One more issue I am facing is, Whenever I send a message that needs to be diverted, the actor to be which I intend to divert my msg gets stopped. Error 1556 occurs. It says reference is invalid or deleted. But I have properly created the user event in pre launch init, registered it in my actor core too. I have attached the project file also.
06-11-2021 04:51 AM
@mahalakshmi05 wrote:
Thanks a lot cbutcher, that helped to get more clarity. Sorry for troubling you with one more doubt. It goes like this...
If I am redirecting one of my messages which is originally sent to "Child 1" to the "Grandchild", should I have the same method and message created in the "Grandchild's prelaunch init" ?I have String message to be redirected, so i should have the user event created in both Child1 and Grandchild ?
If you redirect a message, then the (newly) receiving Actor needs to be able to handle it. More generally, any Actor receiving any Message should know how to handle that message, or should handle the error smoothly...
Usually this is handled by only sending messages to an Actor that you know it can handle.
This is true regardless of a class inheritance between the (newly) sending Actor and the receiving Actor (child and grandchild here).
However, if the message is designed for a class A, and class B inherits from A, then B should be able to handle the message too, because the cast (in "Some Msg.lvclass:Do.vi") will be to class A, and class B will succeed in that conversion. If the VI invoked in Do.vi is dynamic dispatch and overriden by B, you'll get the B implementation, but otherwise it will fall back on the A implementation.
However, you haven't implemented an inheritance hierarchy. You instead have only a Caller/Callee relationship between "Child" and "Grandchild" (a misleading naming in this case, because it suggests inheritance, at least to me).
This isn't inherently a problem, but it does mean that when B (grandchild 1) receives a message M (e.g. Child 1.lvlib:Msg Child Msg.lvclass) sent by A (child 1), it has no idea what to do with it (which causes an error).
You could solve this by one of (and probably more options...)
This was a fairly long post, but hopefully it gives you something to read and you can make some progress or gain some understanding. I'm sure someone will correct any errors that I missed or miswrote 🙂