09-27-2012 03:42 PM
The state pattern is a behavioral design pattern that “allow
an object to alter its behavior when its internal state changes. The object will appear to change its class.” Use this pattern if an object must change its behavior based on its internal state (i.e. if the class has two or more modes of operation such that the mode change alters the behavior of most of the class methods). This pattern lets you avoid adding case structures that test for mode to all of your VIs, generally making for more maintainable code. This package demonstrates a straightforward way to create a family of actors that together implement the state pattern. We refer to this collection of actors as a State Pattern Actor.
This package adds a new actor, called State Actor, to your user.lib folder. It also adds the State Pattern Actor project to your list of available sample projects.
This is an EXPERIMENTAL_FORK compatible with AF 4.1.
 Gamma, Helm, Johnson, and Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, 1994, p. 305
Message was edited by: niACS, to add the latest version (188.8.131.52)
Message was edited by: niACS to add version 1.1 (LabVIEW 2013 or later). There are two changes to State Actor.lvclass. The Entry and Exit methods are no longer required overrides, and Actor Core now invokes the Exit method just before it returns.
11-02-2012 03:50 AM
I spent some time to analyze the behavior of this package. This is very interesting, bu I'm still wondering how the life time of the "Running State" is Managed.
I don't understand or identify what trig the "Exit" Method of the "Running" State. Could you precise this?
Thanks for your answer.
11-02-2012 10:38 AM
The Running state automatically transitions to Idle when it has completed its work. Take a look at Running.lvclass:Update from Process.vi. This is the method that gets called when Process Actor passes a new value to the state machine.
Notice that after I increment the count, I pass the value to a case structure. If the count is 3 or more, I invoke Process.lvclass:Go to Idle.vi. This triggers the transition from Running to Idle.
11-02-2012 11:13 AM
This is clear now. Previously, I missed the last "case structure" on the "Update from Process".
Thanks for your answer.
01-07-2013 07:43 AM
I m implementing an application with the state pattern.
I started from the example and modified it as described in the documentation.
When I start adding more code i' running into the following error message.
Error 1448 occurred at To More Specific Class in DNV.lvlib:TDS.lvlib:Controller.lvlib:Go to Error Msg.lvclass:Do.vi:1->Actor Framework.lvlib:Actor.lvclass:Actor Core.vi:1->State Actor.lvclass:Actor Core.vi:1->DNV.lvlib:TDS.lvlib:Controller.lvlib:Base Class.lvclass:Actor Core.vi:1->Actor Framework.lvlib:Actor.lvclass:Actor.vi:16->Actor Framework.lvlib:Actor.lvclass:Actor.vi.ACBRProxyCaller.A5C0000B
LabVIEW: Bad type cast. LabVIEW cannot treat the run-time value of this LabVIEW class as an instance of the given LabVIEW class.
Inheritance is ok
Any idea how to debug this?
01-07-2013 08:23 AM
This happens when you send a message to an actor that doesn't know how to handle the mesage.
In general you will want the message to go to the parent type of the State Actor. If a method is dynamic dispatch one of the child type actors can implement its own method override.
So, to me it looks like the message may have been for a child class and you are not in that state.
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!
03-21-2013 02:34 PM
I can't find the example for the state pattern. Could someone tell me where it is?
03-21-2013 04:26 PM
In LabVIEW 2012, sample projects...
03-22-2013 11:41 AM
I got it, thanks.
When I generate the project and open it, there is a missing vi called Substitute Actor.vi
So, there is no way I can run it and see how it works.
03-22-2013 11:48 AM
You need AF 4.1 installed. I thought I had made that a prerequisite in the .vip file. I willd double-check that.