LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

improve my design pattern.

I would like to hear some comments about design pattern.

In most my works, I need to monitor some hardware in realtime before experiment.

After some setting, the data acquisition should be done.
And then the data will be transfered to other loop, loop3.

 

To realize this in my program, I have freqently used a producer-consumer pattern (queue and state operation).
In this case, I need to set up 3 queue functions in main loops.

I would like to know if this is suitable idea in using design pattern.

For example, when I sent the signal for re-initialize hardware and transfered the obtained data to loop3 from loop2,
two or three copied 'local' variables are enough for loop-loop communication.

 

Sometimes, I feel some difficuties in communication in reversal direction (ex. from loop3 to loop1).
In this case, I have to use the copied local variable or functional variable.
Do I need to use a user or dynamic event function to communication with UI loop instead of only one local variable?

 

In summary, I am trying not to use local variable in flowing of logic.
But, is it acceptable to you that many loop-communication functions can be used in my rough design?
 

labmaster.

0 Kudos
Message 1 of 11
(2,889 Views)

To comment on a Design Pattern (and suggest minor, or major, changes), it really helps to see the Design Pattern as implemented.  Please attach your VIs (no pictures, please, just LabVIEW VIs) and TypeDefs (if you use them).

 

Bob Schor

0 Kudos
Message 2 of 11
(2,847 Views)

First, this is about your design, not your design pattern. A design pattern is a design that's reused by the masses.

 

Producer\Consumer is a design pattern.

 

The way you use the Producer\Consumer, it leans more towards a Master\Slave design pattern. PC is usually: P producing data, C consuming it. MS is: M producing commands, S executing them. Of course if commands are data, this is more or less the same thing, but the philosophy is different...

 


@labmaster wrote:

In this case, I have to use the copied local variable or functional variable.
Do I need to use a user or dynamic event function to communication with UI loop instead of only one local variable?

 

In summary, I am trying not to use local variable in flowing of logic.


A third option is value signaling properties. Those will set the value, and signal the producer's event structure.

 

I'd start the DAQ loop in parallel (but not dynamically), and communicate with it with user events. Maybe the slave (or actor) will write stuff in a data bus (FGV), or send it's data with user events as well (or just a signal that data was updated.

 

If it will work well or not depends on the details. Implementation details and requirement details.

0 Kudos
Message 3 of 11
(2,801 Views)

@labmaster wrote:

For example, when I sent the signal for re-initialize hardware and transfered the obtained data to loop3 from loop2,
two or three copied 'local' variables are enough for loop-loop communication.

[...]

Do I need to use a user or dynamic event function to communication with UI loop instead of only one local variable?

[...]

But, is it acceptable to you that many loop-communication functions can be used in my rough design?


In general, the data should be queued together with command. That's why one of the most common designs is to use a Cluster with a String or Enum and a Variant as queue data with some variations. (Some prefer to flatten the data and use 2 strings, e.g. I prefer the Enum as Command as case structures becomes more 'automatic' and spelling isn't an issue).

That way it's easy to send both command and data in a generalized form to any consumer.

To return data you can use User events or a "Recieve-queue" with the same cluster idea.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 11
(2,797 Views)

Of course channel wires could make things easier, although they're 'just' layers around queues and other build-in functionality.

Message 5 of 11
(2,791 Views)

Yamaeda,

Thank you for the comment.

 

I use the enum as the command, too.

I would like to see the detail or example of "a Recieve-queue with the same cluster idea" you mentioned as the way of transfering data to the event structure.

 

labmaster.

 

0 Kudos
Message 6 of 11
(2,772 Views)

@labmaster wrote:

I use the enum as the command, too.

I would like to see the detail or example of "a Recieve-queue with the same cluster idea" you mentioned as the way of transfering data to the event structure.


That's going to sound very complicated, but it's not that hard. There are multiple ways to do it. Here's my take on it.

 

When sending the command enum (in a cluster) over a queue, also send a newly create queue reference. The receiver can get the command, and use the queue reference to send it's answer. The Sender can wait for the answer (with or without a time out).

 

The above situation is a bit funny in this context. If you make two loops, so the first loop doesn't stall execution, waiting for the second loop defeats that purpose. If this is acceptable, why use two loops in the first place?

 

The 'send' and 'wait for answer' actions can be separated, but in an event structure that is tricky, as it waits for events, not queue elements. The receiver can send it's results in a user event, but that is another pattern (not a send and wait for result).

 

In general it is a useful pattern for decoupling the code of the processes. This leans towards actor framework...

0 Kudos
Message 7 of 11
(2,752 Views)

Thank you for all valuable comments.

 

I would like to introduce Mike's open posting to someone who looking for the typical example of user-event driven project.

You can download the codes in part2 using a download tool like HTTrack Website Copier.

 

part1:

https://www.notatamelion.com/2016/03/22/dynamic-udes-the-power-for-reentrant-processes/ 

part2: 

https://www.notatamelion.com/2016/04/12/implementing-dynamic-user-defined-events/

 

If you have or know a small example to enhance my design pattern using dynamic event function, please share the link or code here.

 

labmaster.

0 Kudos
Message 8 of 11
(2,687 Views)

@labmaster wrote:

 

If you have or know a small example to enhance my design pattern using dynamic event function, please share the link or code here..


Unless I completely missed it (and I looked pretty carefully), you have yet to show us "your" design pattern (nor any of the code you are talking about).  You seem to be "phishing" for suggestions to "improve your code", and have gotten several suggestions based on our "best guesses" as to what you are doing.

 

Since we can't see what you are trying to accomplish, and thus can't make specific suggestions, I'd like to suggest some material for you to study and "decide for yourself".

  • LabVIEW VI and Project Templates.  LabVIEW has Templates for the Producer-Consumer Design Pattern and the Master-Slave Design Pattern.  It also has Project Templates for the Simple State Machine and the Queued Message Handler.
  • The LabVIEW Tools Network (pointed to by VIPM).  There are several "systems" that have been widely adopted and praised, including the JKI State Machine and the Delacor Queued Message Handler (DQMH).
  • The LabVIEW Forum.  Try searching.
  • The World-Wide Web.

Bob Schor

0 Kudos
Message 9 of 11
(2,654 Views)

@Bob_Schor wrote:
  • The LabVIEW Tools Network (pointed to by VIPM).  There are several "systems" that have been widely adopted and praised, including the JKI State Machine and the Delacor Queued Message Handler (DQMH).

On this topic in particular, it might be helpful to know that currently (this month? so not much longer, but still) there is a free JKI online course about the JKI-SM. Usually this is fairly expensive...

 

Re the DQMH, Delacor have lots of online training materials that can be freely accessed (videos and blog posts etc) and there are quite a few NI Week presentation videos around covering the DQMH. I don't know if there's a freely available (now, or ever) course covering it, but I know several people (including Delacor) offer paid training.


GCentral
Message 10 of 11
(2,622 Views)