Jump to content

class instance sharing in multi loops


Recommended Posts

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.

Link to post

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?

Link to post

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.

Link to post

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)

Link to post
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?

Link to post

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.

Link to post
  • 3 weeks later...

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.

Link to post
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.

Link to post

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.