DQMH Consortium Toolkits Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Receive Data in a State Machine (MHL)

Hi everyone,

I'm working on a test bench software where I acquire data in an Acquisition Module. This module sends data via Broadcast in the Timeout case of a Helper Loop.

Currently, two modules are successfully receiving this broadcast:

  • A UI Module that displays the data to the user.
  • A Controller Module that uses the data as the actual value for a PID controller.

fabianbrugger_0-1753359462242.png

 

So far, everything works fine.

 

Now, I have a third module that contains a state machine in the MHL (Message Handling Loop). Inside this state machine, I also need access to the data — specifically to check whether the values are within certain limits.

I tried the following approach:

  • I created a Request and Wait for Reply mechanism to fetch the data from the Acquisition Module.
  • Since I only need the data at a lower frequency than the broadcast, I thought this would be efficient.

fabianbrugger_1-1753359496422.png

 

However, this approach caused issues:

  • Every time the Request and Wait for Reply is triggered, it interrupts the Broadcast, which negatively affects the PID controller.
  • The overall software performance also seems to degrade with this implementation.

My question: Is there a better way to receive data inside a state machine in an MHL without interfering with the broadcast mechanism?
Would it be a good idea to register for the Broadcast directly inside the state machine? Or is there a more robust pattern for this kind of scenario?

Any suggestions or best practices would be greatly appreciated!

Thanks in advance!

0 Kudos
Message 1 of 5
(298 Views)

I think that the broadcast is the best way to share your data from the acquisition module. There is no need to put additional methods for the same task.

 

My advice is to receive the broadcast inside the EHL of the state machine module and pass it directly to a notifier. Inside the state machine you can get the latest data from the notifier at the moment you need it as it is cyclically updated in the EHL.

Message 2 of 5
(272 Views)

Hi Fabian,

The way I get the latest broadcasted data in a state machine is to have the SM in the timeout case of a helper loop and register for the particular data broadcasts that the SM logic needs. The latest data is then passed around the HL in a data cluster which can be unbundled and used in the SM. I've not run into problems with the data broadcast being at a higher rate than the Timeout, but then again, I've also been using the Wovalabs HL utility to handle the timeout value. 

 

 

 

0 Kudos
Message 3 of 5
(261 Views)

Thanks everyone for your ideas and support!

 

Some comments regarding SC_boy's suggestion:
I initially tried that approach, but ran into an issue. When I'm inside the state machine (SM) within the event structure, I don't receive any data because I'm already handling the timeout case in the SM. So receiving data during the SM procedure wasn't feasible in my setup.

 

Instead, I followed the method described by Ludwig72 with one modification:
I receive the broadcast outside the Event Handling Loop (EHL) of the module. I created a dedicated SM-Sub-VI and then passed the data to the SM using a notifier inside the Sub-VI. This setup works well so far, and I hope it remains stable without causing issues down the line.

Here's a screenshot of the implementation:

fabianbrugger_0-1753431810218.png

 

 

Thanks for your comments. 

Message 4 of 5
(226 Views)

All sound advice here.

 

Personally, I don't like having the state machine inside the MHL. Instead, here at HSE, we have our open-source State Machine module template which implements the state machine in a helper loop.




DSH Pragmatic Software Development Workshops (Fab, Steve, Brian and me)
Release Automation Tools for LabVIEW (CI/CD integration with LabVIEW)
HSE Discord Server (Discuss our free and commercial tools and services)
DQMH® (Developer Experience that makes you smile )


Message 5 of 5
(186 Views)