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.

Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Pre-Launch Init

Solved!
Go to solution

I have been thinking about Pre-Launch Init lately.  I had been opening files, initilaizing serial ports, etc. here.  However, if there is an error then the actor doesn't get launched, the Handle Error.vi doesn't get called (so error logging that I have there doesn't occur).  So I have been moving all of this into a method that I call with a message.  I call a abstract parent method ("Initialize Component" for example) and then I have each component override the implementation.  What is best practice for things to include in a Pre-Launch Init method?  Is there a way to handle or log an error generated there?

Thanks,

Casey

Casey Lamers


Phoenix, LLC


casey.lamers@phoenixwi.com


CLA, LabVIEW Champion


Check Out the Software Engineering Processes, Architecture, and Design track at NIWeek. 2018 I guarantee you will learn things you can use daily! I will be presenting!

0 Kudos
Message 1 of 8
(7,012 Views)

I also started out by putting lots of init code there, mainly because I thought that was the official guideline. Now I don't use it at all and life is good... In all my use cases to date I have found that I don't actually "need" it and error handling and shutdown behaviour seem to be simplified by doing the init inside the actor itself...

(It's one of those things I would love to strip out of AF to make the whole thing a little simpler to digest. That and priority queues! )

0 Kudos
Message 2 of 8
(4,661 Views)

I only use that method for sanity checks that are supposed to prevent the actor from launching if they fail. Any errors thrown should come out of Launch Actor.vi, IIRC.

0 Kudos
Message 3 of 8
(4,661 Views)

I would highly suggest reading the following thread:

https://decibel.ni.com/content/message/32630#32630

CLA, CTA
Message 4 of 8
(4,661 Views)

https://decibel.ni.com/content/thread/12162?start=0&tstart=150 is an old post that talks about the three flavors of initialization - "My Actor Launch.vi", override Pre Launch Init.vi and override Actor Core.vi.

In any initialization, you have to decide whether to complete the launch if the initialization failed.  Even with an error in Pre Launch Init, the launching Actor gets the error message back and can log/act appropriately.  If Pre Launch Init needs to allocate a hardware resource and cannot, is the Actor any good without it?

FWIW, I use Pre Launch Init and actually rarely override Actor Core even for UIs.  For UIs, I have an additional 'messaging' based hierarchy structured similar to the Actor Framework hierarchy but using User Events (i.e. Create User Event primitive). In essence it is the Actor Framework based on User Events instead of Message Queues.  I also have a derived Actor that supports 0 to N of these User Event based 'actors'.  They can be simple helper loops (like a logger) or a fill fledged UI.  Since the derived Actor supports more than one, I can now have more than one UI for a given Actor to show its data in different ways (e.g. Graph, Table, Chart, etc.) or show a subset of the data that the Actor maintains (e.g. the current 'State').  The User Event 'actors' are set up as clients to the Actor with the data and gets updates through a User Event.

Perhaps it was overkill, but it was wicked fun to implement.

@LVB - your link beat me to it!

0 Kudos
Message 5 of 8
(4,661 Views)

Why in the world would you even *want* Handle Error.vi to be called from Pre-Launch Init.vi?!

(For the record, it is a protected scope VI and you're free to add a call to it in your override of Pre-Launch Init.vi if you want, but I wouldn't do that for the reasons described hereafter.)

When Handle Error.vi is called, you know you're in a running actor. That means you can fire off messages to your caller. Not all errors are going to be turned into your error logger -- some are going to be sent to the caller to deal with. Or they may be converted into messages for yourself (like "well, if that function returned an error then let me fire the Change Strategy message").  Or to your already-running nested actors.

If you have a global error logger, you're free to call that in Pre-Launch Init.vi. There's no reason why you can't do that. But all the rest of the code that goes into Handle Error.vi would be totally inappropriate at the time Pre Launch Init.vi is running. The actor doesn't yet exist to be messaged, which is one of the assumptions that Handle Error.vi is free to make. Saying that you don't use Pre-Launch Init.vi because it doesn't invoke Handle Error.vi is completely missing the point of Handle Error.vi.

0 Kudos
Message 6 of 8
(4,661 Views)
Solution
Accepted by topic author CaseyLamers1

To clarify, I don't want Handle Error in Prelaunch Init. I wanted to know what error I was getting and I wasn't using Handle Last Ack. So I would throw an error and not log it and the entire application would stop and I wouldn't know what happened.

This is mostly due to not knowing how to use Handle Last Ack.

This came about due to changes in Prelaunch Init from using static settings to using settings from a config file.

Thanks,

Casey

Casey Lamers


Phoenix, LLC


casey.lamers@phoenixwi.com


CLA, LabVIEW Champion


Check Out the Software Engineering Processes, Architecture, and Design track at NIWeek. 2018 I guarantee you will learn things you can use daily! I will be presenting!

0 Kudos
Message 7 of 8
(4,661 Views)

Ah. That makes more sense. 🙂

0 Kudos
Message 8 of 8
(4,661 Views)