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: 

Complex architecture - design pattern?

I am trying to determine which architecture, or combination woudl best suite my application: 

 

The core aspect is a client receiving data from a network at variable speeds - I have this working using a producer consumer loop (data) design pattern, that starts and stops by placing it inside a case structure with start button. I'd now like to combine this with an event driven user interface, which also uses the serial port to talk to external hardware every now and then. I have that working seperately with a producer consumer (event) design pattern. I'd like to combine them and include regular events (handshaking with the external hardware) to take place whilst the producer-consumer (data) reads from the network.  

 

How can I mix the two design patterns?! I'm struggling to get my head 'round this.

 

Thanks

 

 

 

Message 1 of 16
(3,223 Views)

Put both architectures in the same vi, running in parallel.  You can use a queue to send messages between the two.

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 16
(3,208 Views)

Thanks tbob, could you show me what that structure would look like with an example from the templates please? I'm not too sure about that. I've just put the whole producer/consumer (data) structure inside a consumer (event) but haven't thought through the handshaking yet.  

0 Kudos
Message 3 of 16
(3,192 Views)

Here is an example of two Producer-Consumers in one vi.  Notice the two queues.  One is for commands to the event loops.  The other is for the serial data loops.  When certain data is received, you can send commands to the event loop (actually to Consumer loop, 2nd from top) to cause some action.  So the user can initiate some action via event structure, and received data can also initiate some action.

 

This is complex and it might not do all you want.  But its a start.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 16
(3,181 Views)

I think I have four parallel loops:

 

1. A user event structure to direct the code from the user

2. A real-time data collection loop (to read from the network and do some heavy going calculations)

3. A device comms, loop (via RS232) to send result of calculations to my external hardware (has a manual step-by-step mode, and auto mode to take data automatically from 2. to 3.)

4. A handshaking loop to keep talking to my device and take action if a comms. failure occurs

 

 

2. is currently a seperate producer/consumer (data).vi

1. and 3 are currently in a producer/consumer (event).vi with a badly working effort to include 4.

 

I've only ever used two loops as per the templates, so I'll experiment with parallel loops tomorrow.

 

 

 

 

 

 

 

0 Kudos
Message 5 of 16
(3,180 Views)

Ah! you beat me to it. That looks very useful, it's getting late but have something to play with tomorrow. Thank you.

 

 

0 Kudos
Message 6 of 16
(3,179 Views)

Could someone explain why this doesn't work?! .. and if it's possible to address specific consumers?

 

 

0 Kudos
Message 7 of 16
(3,125 Views)

Each queue can be thought of as pile of things.

 

There is a pile of things created everytime you create a queue. one create one pile.

 

The remove from queue takes something out of the pile.

 

If you put one thing in and have many critters each trying to take something out, only the first one attempt it will get it.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 16
(3,122 Views)

Ok, so can I create three queues, write the same value to each queue and read from one of the queues? Like this ..

0 Kudos
Message 9 of 16
(3,117 Views)

 


@grahamwebb wrote:

Could someone explain why this doesn't work?! .. and if it's possible to address specific consumers?

 

 


There a a couple way to get the operation you want.  I've posted a minor modification that sets the queue to 1 element and uses the lossy enqueue function and replaced the dequeue functions with Preview.  Note: since no comsumer is actually dequeueing an element the queue allways contains the last element enqueued so the consumer loops were throttled back to iterate only 10 times a second. 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 16
(3,115 Views)