ASalcedo Posted February 17, 2017 Report Posted February 17, 2017 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. Quote
drjdpowell Posted February 17, 2017 Report Posted February 17, 2017 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. Quote
ASalcedo Posted February 17, 2017 Author Report Posted February 17, 2017 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 Quote
hooovahh Posted February 17, 2017 Report Posted February 17, 2017 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. Quote
drjdpowell Posted February 17, 2017 Report Posted February 17, 2017 (edited) 4 hours ago, ASalcedo said: Could you tell me how I can use those can of asynchronous dialogs that you use? Mine are built in to Messenger Library, the framework I use. A video on them. But separate UI and PLC loops might be a better option for you. Edited February 17, 2017 by drjdpowell Quote
austinman Posted February 17, 2017 Report Posted February 17, 2017 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). Quote
drjdpowell Posted February 17, 2017 Report Posted February 17, 2017 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. Quote
smithd Posted February 17, 2017 Report Posted February 17, 2017 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. Quote
ASalcedo Posted February 21, 2017 Author Report Posted February 21, 2017 Thanks to all. What I have finally used is two parallel loops. So like that it works fine. Quote
austinman Posted February 24, 2017 Report Posted February 24, 2017 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? Quote
drjdpowell Posted February 25, 2017 Report Posted February 25, 2017 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) Quote
ShaunR Posted February 25, 2017 Report Posted February 25, 2017 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. Quote
drjdpowell Posted February 26, 2017 Report Posted February 26, 2017 15 hours ago, ShaunR said: It's like saying a kitchen, bedroom or bathroom is a house. 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. Quote
ShaunR Posted February 26, 2017 Report Posted February 26, 2017 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 Quote
austinman Posted March 9, 2017 Report Posted March 9, 2017 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.