There are two ways of launching a module:
Main.vi
. Start Module.vi
and Synchronize Module Events.vi
API functions. The following sections discuss aspects and ways of launching modules externally.
The DQMH Framework helps developers write reliable and robust code by taking care of various aspects like reference lifetime and synchronization of actions. When starting a module, the module itself creates all required resources like event references to own them and dictate their lifetime.
To ensure that the code starting the module receives any resources only after they've been created, and to make sure that the code only continues execution once the module is ready to receive requests, the DQMH Framework provides the process described in this section.
Start Module.vi
Start Module.vi
…
Main.vi
Wait on Module Sync.vi
, which waits until a second task arrives at the “Module Sync” rendezvous [A][A] Start Module.vi needs to wait until the broadcast event references have been created by the module.
Main.vi
Init Module.vi
, which creates both the module's broadcast event references and the request event referencesMain.vi
continues to start Event Handling Loop (EHL), Message Handling Loop (MHL), and any Helper Loops (HL; optional)Main.vi
enters the “Initialize” case of the MHL
Synchronize Caller Events.vi
Wait on Module Sync.vi
adds the second task to the “Module Sync” rendezvous
Start Module.vi
now continues executionWait on Event Sync.vi
waits until a second task arrives at the “Event Sync” rendezvous [B][B] The module needs to wait until the calling code has registered for the broadcast events.
Start Module.vi
returns the Broadcast event referencesSynchronize Module Events.vi
Wait on Event Sync.vi
adds the second task to the “Event Sync” rendezvous
Main.vi
's “Initialize” MHL case, Synchronize Caller Events.vi
now continues executionThe caller is now finished with starting the child module
Main.vi
, Synchronize Caller Events.vi
now returns and the rest of the code in that case is executed.Module Did Init.vi
broadcast is sent. The child module is now finished with starting
Any rendezvous functions mentioned above will wait for the module timeout defined in Module Timeout–constant.vi
(default = 5s) before returning an error.
It becomes apparent that 2. Continue to MHL in the schema shown above is the critical path. If any code is placed before the MHL starts (i.e. before Synchronize Caller Events.vi
inside the “Initialize” case) which takes longer to execute than the module timeout, the startup process of the module will fail.
Be careful when adding code outside of the EHL/MHL/HLs, especially code that needs to execute before entering the EHL/MHL/HLs and might therefore delay entering the “Initialize” MHL case. If it takes too long to reach the “Initialize” case, the module synchronisation will time out and fail, and the Start Module.vi will throw error 403683 (“Module was unable to synchronise events”).
Make sure to also browse our HSE Coding Conventions on Parent/Child Modules.
The concept of placing the code for starting modules inside EHL/MHL and having a request or Queue message trigger the starting of child modules gives control and flexibility over when and from where modules are actually (re)started. It does beg the question, though, of where and when to actually send the request or message triggering the start.
Our better practices section on Coding Conventions contains a page on DQMH®:
DQMH Coding Conventions