VadimB Posted March 24, 2021 Report Share Posted March 24, 2021 Hello. What is the best practice to share one class instance (object) between two, or more, loops? New to lvoop, I suspect a correct answer is reference. Quote Link to comment
thols Posted March 24, 2021 Report Share Posted March 24, 2021 Are you sure you really want to share the class instance? Often, really what you want to do is send messages between the loops with info of change. Quote Link to comment
drjdpowell Posted March 24, 2021 Report Share Posted March 24, 2021 As thols says, the best practice is to NOT share things between loops, but if you do, I'd suggest a DVR. Quote Link to comment
VadimB Posted March 24, 2021 Author Report Share Posted March 24, 2021 Mmmm... I have a hardware (power source) to continiously collect data from in one operation and perform user controlled events in another one. Class is defined for hardwear. The only data they share is COM-port. To avoid conflicts in COM-port usage I'm going to create a property that will point to "port is busy right now". Is there a better solution? Maybe the core concepts is weak? Quote Link to comment
crossrulz Posted March 24, 2021 Report Share Posted March 24, 2021 What I typically do in this situation is use a QMH that manages the hardware. The control loop can send a message to the device loop using a queue. The device loop then does whatever needs done and sends a reply back to the control loop. If no messages are coming in (the queue has a time out), then the device loop can collect data. What this does is isolate the device to a single loop and only it needs the object. The alternative is to use a Data Value Reference (DVR) to store the object. The In Place Element Structure that acts as the boundary so two operations cannot happen at the same time. Quote Link to comment
ensegre Posted March 24, 2021 Report Share Posted March 24, 2021 or simply implement your serial queries of both kinds via a single non-reentrant VI, so that only one loop at a time uses the serial resource? (more sophisticated, use a VISA lock) Quote Link to comment
VadimB Posted March 25, 2021 Author Report Share Posted March 25, 2021 21 hours ago, crossrulz said: What I typically do in this situation is use a QMH that manages the hardware. The control loop can send a message to the device loop using a queue. The device loop then does whatever needs done and sends a reply back to the control loop. If no messages are coming in (the queue has a time out), then the device loop can collect data. What this does is isolate the device to a single loop and only it needs the object. The alternative is to use a Data Value Reference (DVR) to store the object. The In Place Element Structure that acts as the boundary so two operations cannot happen at the same time. what if I would like to use dynamic events instead queues as a pattern Event-driven message handler instead QMH? Is there any underwater rocks I should keep in minds? Should I mention I buid RT application? Quote Link to comment
crossrulz Posted March 25, 2021 Report Share Posted March 25, 2021 The Delacor Queued Message Handler (DQMH) is based on using events. You might want to give it a good look. Quote Link to comment
drjdpowell Posted March 25, 2021 Report Share Posted March 25, 2021 A "queue" is a first-in-first-out mechanism. Don't be confused by specific implementations; the LabVIEW Event system is just as much a queue** as the LabVIEW "Queue". **Specifically, the "event registration refnum" is an event queue. Quote Link to comment
VadimB Posted April 13, 2021 Author Report Share Posted April 13, 2021 finally, I suppose, the best solution is to use DVR in junction with single element queue or notifier. And there is a classic OOP pattern to solve this problem - Singleton Pattern. Found it's description and example here. Quote Link to comment
thols Posted April 13, 2021 Report Share Posted April 13, 2021 42 minutes ago, VadimB said: finally, I suppose, the best solution is to use DVR in junction with single element queue or notifier. And there is a classic OOP pattern to solve this problem - Singleton Pattern. Found it's description and example here. If you will be using a singleton, please have a look at this: https://forums.ni.com/t5/Bay-Area-LabVIEW-User-Group/LabVIEW-Design-Patterns-Mini-Series-Singleton-by-Dmitry/td-p/3527270 The NI implementation is not very good. In the zip-file in the link above, you will find some others and a ppt for a presentation that goes through some others and points out the best one. Quote Link to comment
VadimB Posted April 20, 2021 Author Report Share Posted April 20, 2021 Thank you for this! Quote Link to comment
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.