2022年LabVIEW同步技术 .pdf
《2022年LabVIEW同步技术 .pdf》由会员分享,可在线阅读,更多相关《2022年LabVIEW同步技术 .pdf(42页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、1Advanced LabVIEWTMSynchronization TechniquesPresented by: Michael AivaliotismmWave Integrated Solutions Inc.For: LabVIEWTMUser Group MeetingThis presentation assumes that you have a basic knowledge of LabVIEW and have developed several simple applications using LabVIEW.Also, knowledge of while loop
2、s, parallel loops and dynamic VI calls will only be briefly explained. For more information on these topics please read the LabVIEW documentation.名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 42 页 - - - - - - - - - 2Presented by: Michael AivaliotisAgendazWhy S
3、ynchronize?zSynchronization Methods with examples:GlobalsOccurrencesDAQ occurrencesNotifiersQueuesSemaphoresRendezvouszManaging refnumszApplication integrationzApplication Example using Queues & NotifiersWe will start off with a look at why we need to synchronize.Next we will go through he main func
4、tions and techniques used insynchronization. We will stop at each type and show examples and elaborate on certain areas to watch for with each example.We will discuss refnums in specific and see how they are handle properly.A discussion of integrating synchronization in an application will be presen
5、ted concluding with an actual Application that uses queues and notifiers.名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 42 页 - - - - - - - - - 3Presented by: Michael AivaliotisWhy Synchronize?zTasks executing in parallelParallel loopsDynamic VIs using VI server
6、zData passing between parallel taskszControlled executionzAvoiding race conditions with globalszOptimize CPU usage (reduce polling)Whenever you have parallel tasks you need to pass data between these tasks and synchronize them. A task can be a separate loop or a VI running dynamically or in parallel
7、. When tasks are running in parallel, more work must be done to synchronize them. Also, synchronization of parallel tasks is necessary if one taskshould wait until some other task causes it to continue. For example, you may onlywant to read from an instrument after it has first been properly initial
8、ized. Usually sequential synchronization is accomplished by data flow dependency, that isa VI or structure will wait until all its outputs have data on them (I.e. all nodes “ahead” have finished executing).You can avoid race conditions by using semaphores described later. This allows only one proces
9、s to access a shared resource at a time (example globals or instrument)Using the techniques described here we can optimize CPU usage bynot having to poll events. Occurrences and notifiers wake up and perform task thus reducing CPU burden.名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整
10、理 - - - - - - - 第 3 页,共 42 页 - - - - - - - - - 4Presented by: Michael AivaliotisGlobalszInitialize globalzWait until value changeszToggle new data globalzLoop checks until value of global has changedzIf changed, read dataUsing globals for synchronization is easy but almost always inefficient.It usua
11、lly involves polling, where the waiting task sits in a loop and checks the value of a global variable until the value changes to indicate that it can proceed.Example, In this example, one loop acquires a waveform and a second loop displays the waveform on a graph. The second loop only does it when a
12、 new waveform has been acquired. The second loop can also do computationally intensive routines, printing or saving, which may take time. This frees up the main acquisition loop to acquire without a hitch.The top loop acquires a waveform, and when it is finished, it sets the global new data to TRUE.
13、 In the meantime, the bottom loop executes a polling loop which checks every 100ms whether new data is TRUE. When it becomes TRUE, it resets the global to FALSE, and displays the data onto a graph.A race condition here can occur if new data is read by the second loop and new data is set again by the
14、 acquisition loop before new data is reset by the second loop. This will cause the second loop to reset the global and the new data set will be ignored.名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 42 页 - - - - - - - - - 5Presented by: Michael AivaliotisGlobal
15、szView global sync Demo名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 42 页 - - - - - - - - - 6Presented by: Michael AivaliotisGlobalszAdvantagesEasy to useEasy to implement?zDisadvantagesInefficient pollingMemory usage (data copying from multiple reads)No queui
16、ng capabilities (old data can be overwritten by new data)If you use global variables for synchronization, make sure that you have a delay in the polling loop (Wait milliseconds) in order not to take away too many CPU cycles from the task on which you are waiting.Also, when you use globals, make sure
17、 that you are very careful about race conditions. For example, if you use a Boolean global called continue to signal that the first task is finished and the second task can start, make sure that at the beginning of you program the global is initialized to FALSE , and that once it has been read by th
18、e waiting task as TRUE , it is re-initialized to its default value, FALSE .名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 42 页 - - - - - - - - - 7Presented by: Michael AivaliotisOccurrenceszAllows part of your diagram to sleep until the occurrence is setzOptimi
19、zes your system by eliminating the need to poll a variable in a while loopzConsidered a software triggerzThree functions:Generate occurrenceWait on occurrenceOccurrences allow you to wait on other tasks without polling in a loop.When an occurrence is set multiple times, the Wait On Occurrencewill on
20、ly know about the last one.ExampleIn this example, one loop acquires a waveform and a second loop displays the waveform on a graph. The second loop only does it when a new waveform has been acquired. The second loop can also do computationally intensive routines, printing or saving, which may take t
21、ime. This frees up the main acquisition loop to acquire without a hitch.The top loop acquires a waveform, and when it is finished, it sets an occurrence. In the meantime, the bottom loop waits on the occurrence. Unlike polling a global variable in a loop, waiting on an occurrence does not waste CPU
22、cycles. When the occurrence is set, the bottom loop “wakes up ”, and displays the acquired waveform.名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 42 页 - - - - - - - - - 8Presented by: Michael AivaliotisOccurrenceszIf no timeout is specified then waiting loop w
23、aits forever. Must set occurrence to stop.zIf timeout then code “wakes up ” then goes back to sleepzCannot break out of loop.zSet ignore previous to False to detect occurrences set before waiting began.ms timeout is the specified amount of time, in milliseconds, for the occurrence to occur. If the o
24、ccurrence does not occur within the specified ms timeout, the function returns a value of TRUE. If ms timeout is -1, the function does not time out. occurrence is the occurrence refnum that links Wait on Occurrence and Set Occurrence. ignore previousIf ignore previous is TRUE, and another node has s
25、et the occurrence before this function began executing, the function ignores the previous occurrence and waits for another one.If ignore previous is FALSE, this function sets immediately if the occurrence was set since the last time this function waited on the incoming occurrence. This function reme
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年LabVIEW同步技术 2022 LabVIEW 同步 技术
限制150内