11.3-学习操作者文档

主要分四步

  • 操作者创建
  • 消息创建
  • 程序写入
  • 联合调试

继续学习操作者白皮书文档

  • 总的来说,操作者框架是基于通信的框架,是一种messaging frameworks
  • Considerations for Implementation
    • Debugging Actors
      • 运行的时候操作者无法退出的两种解决方案
      • The first quick workaround is to close your project and re-open it. You do not have to restart LabVIEW as long as you're working inside a project. Closing the project will abort all the running VIs in that project.
      • A better solution is to use the optional input on Launch <X> Actor.vi for Open Actor Core front panel? (F). Wiring True to this input will make the front panel pop open when the actor is launched, giving you access to that actor's own Abort button. Using this terminal in release code will return an error (for reasons explained in the online help), but while debugging, this can be a major headache saver.
      • LV程序调试及测试工具
      • please check out the Desktop Execution Trace Toolkit or the Real-Time Execution Trace Toolkit from National Instruments. This tool has deep knowledge of LabVIEW and its APIs, giving you insight into execution ordering, memory allocation and error propagation. If you do not have access to these toolkits, you may find these "timing probes" useful.
      • 程序运行计时工具
    • Actors in Libraries
      • Use libraries to manage and distribute your Actor classes. In addition to the child actor class, the library should contain most messages that target that actor and any additional tightly coupled classes, such a configuration object for the actor (refer to the Configuring Actors section, below), or the component objects of a composition.
      • You may opt to bundle a family of Actors in a single library, especially where that family shares a single set of messages.
    • Configuring Actors
      • Often, you want to configure an actor with data from elsewhere in the system, such as in a configuration file. Before calling Launch <X> Actor.vi, you can use the methods of the actor class to directly set values into the actor object. After calling Launch <X> Actor.vi, you can give data to the actor object through its message queues. Although you could create multiple messages to set individual fields of the actor, consider creating a single Configuration class that encapsulates the configuration information.
      •  You can set the configuration object through normal method calls, then pass a single configure message to the Actor. These "large blocks of data" messages should be reserved one-time initialization of the object, not for updating the object while your application is running. While running, you should use messages that update only the fields that have changed rather than rebroadcast the entire object.
    • 设计模式:操作者组合和操作者聚合
    • 组合和聚合的区别在于,组合的成员是固定的,聚合的成员只是抽象的存在,可能不存在,可能动态产生和销毁。也就是说,它们都是对象与对象之间的关联关系,但是组合比聚合模式下更加紧密。
    • Implementing Actors Composed of Multiple Actors(Composition)
      • There are two styles of caller actors: compositions(组合) and aggregations(聚合).
      • In compositions, the caller actor is responsible for creating and destroying its nested actors. The standard implementation is to create, configure and launch the nested actors in the Actor Core.vi, prior to starting any While Loops or invoking the Call Parent node. The caller actor stores the Message Enqueuer returned by Launch Nested Actor.vi for each component as part of its private data. You will need to either use the Auto-stop? feature or override Stop Core.vi in the caller to send stop messages to each callee so they all shut down together.
    • Avoid Get and Set Messages
      • 避免 Race Condition(竞争条件)
      • An actor runs a parallel task. If your Get/Set operation consists of two messages, then the Actor continues to run between your Get and Set messages. Another task could access and modify the same attribute concurrently causing a race condition.
      • It is appropriate, of course, for a caller to send a message requesting an update (or regular series of updates) from a nested actor. It is also appropriate for a caller to push an update to the nested actor. Issues only arise when you logically link the get and set operations; that is, when you get attributes for the purpose of modifying and returning them.
  • Benefits of the Actor Framework(相较其他设计模式的优点,没有看懂)
    • It is significantly more flexible and extensible than traditional state machine architectures, and is safer and more efficient than by-reference class hierarchies.
    • More Extensible and Reusable Code
      • A child Actor can reuse its parent's functionality in three ways:
      • To change a parent's behavior, use a child with an override method.
      • To add behavior to a parent, extend the parent by adding new methods to a child.
      • To give the parent's control logic additional control logic, decorate2 the Actor Core.vi with an added control loop.
    • Actors Objects Are Testable
    • 大部分操作者功能可以单独测试,不需要建立消息发送机制,如果一定需要消息发送机制,可以使用一个VI,初始化操作者队列(仅测试)
      • You can test many actors without launching the Actor Core. Any of the member VIs of the actor class can be run directly.
      • Those that do not attempt to send replies to other actors can be tested in isolation just like any other VI, without having to create the Self and Caller queues.
      • If a method does communicate with another actor, you will need to initialize to initialize the Self and Caller queues. You can use a VI found on disk called:<vilib>\ActorFramework\Actor\Init Actor Queues FOR TESTING ONLY.vi
      • 使用JKI VI TESTING FOR LABVIEW工具为Vi进行单元测试
    • 操作者框架的消息传递机制是优秀的
    • Guaranteed Delivery of Stop Message
      • A common problem in other messaging frameworks occurs during shutdown. One component sends the stop message to another component and then quits. Because a refnum in LabVIEW has the same lifetime as the VI that created it, many frameworks have a problem that the queue can be destroyed before the other component receives the message.
      • With the Actor Framework, each component creates its own receive queue, so that queue has the same lifetime as the receiver, not the sender. That means that any component – caller or callee – can send the stop message and then shut itself down without worrying about the message not being delivered.

学习Desktop Execution Trace ToolkitVI进行性能测试

学习VI Analyzer toolkitVI 进行单元测试,使用预定义的测试用例


猜你喜欢

转载自www.cnblogs.com/lizhensheng/p/11241960.html