Jump to content

Best way to use this event structure


ASalcedo

Recommended Posts

Hello to all.

First of all thanks a lot for reading this post.

I have a while with event structure.

The event structure has the next two events:

· Timeout: each 25ms, this timeout reads variables from PLC.

· Button event: When user press this button, a dialog box appears to ask "yes or no" to user.

Well, here maybe there is a problem because if usser takes more than 25ms to enter an input in dialog box then timeout does not run in that iteration and It is critical for me.

Is there any way to do that program runs and it does not stop until usser put an input in dialog box?

Or the best way is to do another event structure in another while with button event?

Thanks a lot.

Link to comment
44 minutes ago, drjdpowell said:

You need some kind of parallel structure so your dialog can go on in parallel to your hardware handling.  I actually use a special version of dialogs that are asynchronous and send their results back as a message, but the more common way is to have a separate loop of some sort.

Could you tell me how I can use those can of asynchronous dialogs that you use?

thanks a lot

Link to comment

Here is an example of an asynchronous VI running, and having user events send data back.

https://forums.ni.com/t5/Example-Program-Drafts/Non-Blocking-Multibutton-Dialog-Box/ta-p/3509941

But I think a simpler design would be two while loops, that communicate to each other with a couple of queues.  In 2016 there is channel wires that could be useful too.  Then your one while loop can be dedicated to just doing PLC stuff, and the other is for UI updates, and interactions with the user.

Link to comment

As you have discovered, one of the limitations of the Event Structure is that it will only process one event at a time. A search of YouTube with 'labview producer consumer' returns a number of videos that discuss using multiple loops with the event structure. If you have access to the LabVIEW Core 2 material the producer-consumer design pattern is discussed there. Using multiple loops enables your program to keep processing events while performing other tasks (e.g. prompting the user for input). 

Link to comment
10 hours ago, ASalcedo said:

· Timeout: each 25ms, this timeout reads variables from PLC.

if usser takes more than 25ms to enter an input in dialog box then timeout does not run in that iteration and It is critical for me.

You should definitely use a separate loop if continuous execution of the loop is important to you. You should probably also be measuring the loop rate if its really that important, to verify that your plc communication code can execute in time.

Link to comment
On 2/17/2017 at 11:07 AM, drjdpowell said:

Personally I recommend against using NI’s “producer consumer” stuff as a guide.  Both your UI loop and your PLC loop need to both produce and consume information.  

@drjdpowell

Agreed, the Producer/Consumer does have limitations, but it is good starting point for LabVIEW developers. Out of curiosity, what architecture/design pattern would you suggest a new(ish) LabVIEW developer use in place of the Producer/Consumer? 

Link to comment

By "Producer/Consumer”, do you mean the simplest interpretation of  “you can have a loop that consumes elements from a queue that are enqueued elsewhere”**, or the application of that in many NI examples of a “Producer” loop that receives Events and send enqueues messages to a second “Consumer” loop (which also enqueues messages to itself), as in the “Queued Message Handler” or “Continuous Measurement and Logging”?  It’s the latter architectures I find poor^^.

 A better architecture is to have a “main” loop that is based on handling Events (the JKI “statemachine” template is a good example), with blocking operation like Dialogs handled in a small, simple, specialized parallel loop, that sends its results back to the main loop.

** A very important concept but not, by itself, enough to be an architecture.

^^ a pet peeve of mine; I’ve actually given talks on weaknesses in these examples (link)

Link to comment
8 hours ago, drjdpowell said:

By "Producer/Consumer”, do you mean the simplest interpretation of  “you can have a loop that consumes elements from a queue that are enqueued elsewhere”**, or the application of that in many NI examples of a “Producer” loop that receives Events and send enqueues messages to a second “Consumer” loop (which also enqueues messages to itself), as in the “Queued Message Handler” or “Continuous Measurement and Logging”?  It’s the latter architectures I find poor^^.

 A better architecture is to have a “main” loop that is based on handling Events (the JKI “statemachine” template is a good example), with blocking operation like Dialogs handled in a small, simple, specialized parallel loop, that sends its results back to the main loop.

** A very important concept but not, by itself, enough to be an architecture.

^^ a pet peeve of mine; I’ve actually given talks on weaknesses in these examples (link)

They aren't really architectures.

It's like saying a kitchen, bedroom or bathroom is a house. It is the composition of all the different room types that makes a house (analogous to software architecture) and the different rooms (Producer/Consumer, Pub/Sub, Actor, State Machines et.al) fulfil specific requirements within it. The problem is that people choose one room type and try to fit everything in it, ending up with a studio apartment where the mess, caused by trying to make everything fit, just spreads around tripping up the residents, making it hard to move around and almost impossible to redecorate.

Link to comment
23 minutes ago, drjdpowell said:

Yeah, but some of your room types are complimentary and some are not.  You’d have a kitchen and a bathroom in your house, but not a modern kitchen and a 19th-century kitchen.

Sure you would. The servants don't need a modern kitchen to cook their gruel :D

Link to comment
  • 2 weeks later...

Thanks for your input, and sorry for not responding sooner. For some reason LAVAG does not like to send me notifications, even when enabled. which means I have to manually check for responses.

It sounds like we are on the same page, in that there are different solutions for different problems. As someone who teaches LabVIEW Core 1 and 2 on a regular basis, I find the basic producer/consumer can be overwhelming to new developers. My feeling is the producer/consumer, and state machine, are a good foundations on which to start. As skills and application complexity increase the QMH is the next step, and so on. Hopefully all the loops have matching decor.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.