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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Transferring a string in a while loop to an array of objects

The attached project is a simplified version of a project I am working on.

 

VI.vi is a dynamic VI that takes in MQTT messages from the ‘FromMainVI’ queue.

 

The first set of messages sent via the 'FromMainVI' queue gives a list of serial numbers. These are taken in by the “(A)_setSerialNumber” option in the ‘Queue messages’ case statement in the ‘(1)_Main_while_loop’. A ‘(B)_allSerialNumbersSent’ message is sent to enable the next step in the process to start (i.e. this ends the running of the ‘(2) Waits until the VI is ready to run the procedure’ while loop).

 

The ‘(3) Adds the serial number to the array’ while loop:

  • adds a DataClass object to the ‘Array of DataClass objects’, as well as;
  • copying a unique serial number saved in the ‘Serial numbers’ array.

(this loop (3) is deliberately empty to hopefully aid clarity).

 

When the objects have been set up the VI will then start running through a series of processes (e.g ProcessA, ProcessB, etc. shown at the bottom of Main.vi). These processes will be sending commands to the MQTT via another queue (not shown) and will need to wait for the response before continuing. These responses will come back via the ‘(C)_MQTTmessage’ option of the ‘Queue messages’ case statement in ‘(1)_Main_while_loop’. These responses will contain the serial number of the calling object and the requested message.

 

When this response has been received, I want to send it to all of the objects in ‘Array of DataClass objects’ using ‘setMessage.vi’. This function will compare the serial number in the incoming response with its own serial number:

  • if both are the same then it will save the message;
  • if they are not the same, then the message will be ignored.

 

The object that has made the request will poll Message in its cluster of private data. When it has received the message, it will then carry on to the next step.

 

I’m struggling to work out how to transfer the response over from ‘(C)_MQTTmessage in the ‘Queue message’ case statement to the DataClass objects. I would be grateful if anyone suggest how this might be achieved.

 

Thanks

 

RW

0 Kudos
Message 1 of 2
(2,184 Views)

Did you ever get this figured out?  The "1000-ft" level answer is that your DataClass objects probably need to be a running loop that can accept incoming messages (likely by queue). 

 

So, when you instantiate the objects, the loop is fired off and running in the background.  You can then send "setSerialNumber" and "sendMessage" messages to the objects using the queue reference and perform actions related to the receipt of those messages.  You'll have to build additional infrastructure to manage the loops (initialization, stopping, etc.).

 

The Actor Framework in LabVIEW does exactly this out of the box, but there is an initial learning curve; I updated some of your example code to help visualize how this might look, but it's definitely incomplete.  I would start here as a reference for using the framework.

 

You may want to use your own implementation, I'll leave that up to you, but hopefully this helps.

0 Kudos
Message 2 of 2
(2,101 Views)