LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize data from two serial ports at different sample rates?

Solved!
Go to solution

@jdeters79 wrote:

Lynn,

 

Disregard my last message.  Should've actually put some effort into figuring it out before posting.  I figured out how to make it work using a local variable.  

 

Again, thanks for your help with the parallel loop issue!

 

Jordan


This is a great opportunity to learn about queues.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 21 of 24
(704 Views)

Jordan,

 

Bill is right.  A queue is a better choice than a local variable.

 

Lynn

0 Kudos
Message 22 of 24
(696 Views)

From what I've read, it seems that the queue is a more reliable way to pass a variable when rates are high.  In my case, the data I'm sampling is 5Hz/6Hz, thus is it really necessary?  Are your recommendations strictly "best practices"?  

 

One thing that is somewhat confusing, I was looking at the 'Queue Basics.vi' example and see that they pass the elements from the queue in one loop to another loop using a local variable?  Where or what is the benefit to the queue?  I've obviously demonstrated my LabView experience level in the previous posts, but the example does not really explain the benefit of the queue.

 

Thanks,
Jordan

0 Kudos
Message 23 of 24
(683 Views)

Jordan,

 

You are right. That example does a poor job of explaining what it is doing. The side by side top loops demonstrate how the queues work.  Notice that when the Dqueue Speed is slower than the Enqueue Speed, the Elements in Queue indicator will fill up and then the Inserted and Removed charts no longer show the same data.

 

Stopping the upper loops on error is easy but may result in loss of data. If you run the VI at the higher speed and look closely after stopping you will see that the last element Inserted often does not show up on the Removed chart.

 

The bottom loop is a "monitor" to show what is going on in the queue loops. One of the major problems with local variables is the possibility of race conditions.  It is possible that the local variables in the bottom loop are read the first time before any data has been written to the indicators in the upper loops.

 

So, yes, in a way this is a best practices issue.  But it is important to remember that the data is not held in the controls and indicators; it is in the wires. The (poorly named) local variable is a copy of the data in the indicator and not a pointer to the data in the wire.

 

About the only recommended use for local variables is setting controls programmatically, at startup for example.

 

Lynn

0 Kudos
Message 24 of 24
(677 Views)