From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize two while loop's start

Solved!
Go to solution

I have two sensors sending data at different speeds:

 

- The first sensor, A, is what I based my VI from. It is a while loop that uses event and case structure to toggle between: idle, start communication, start measurement, stop measurement, stop communication. 

- The second sensor, B, is an serial communication running in a while loop. (It is at the bottom of the VI attached)

 

I need to have both loops running at the same time but I need the second sensor B to start when the first sensor's event toggles to "START MEASUREMENT". Both have to receive message at the same time, as the time stamp is crucial.

 

I have attempted to 1) place them both in a while loop but the time difference created a loss in packets. 2) local variables, but "boolean latch is incompatible with local variables", 3) have a wire direct from the event of sensor A to a event of sensor B but it did not start the second loop.

 

I have looked at notifiers, queues, consumer/producer --- without any result. 

Any guidance would be great!

 

 

VI Screenshot.png

Download All
0 Kudos
Message 1 of 2
(2,189 Views)
Solution
Accepted by topic author Joaquinh

 


@Joaquinh

 


I have looked at notifiers, queues, consumer/producer --- without any result. 

Well, then you probably better look harder.  That's where the solution's gonna be.

 

Your serial comm loop needs to be off on its own because you can't force timing sync with a serial-connected device.  The best you can do is to associate a timestamp with the data it produces.

 

Notifiers and queues (plus user-defined events and the more recently introduced Channels) represent the accepted best practice methods to send signaling (trigger-like) and data between parallel loops.

 

You can't really force both measurements to occur at the same time.  You can kinda make sure you send the query string via Serial Write a.s.a.p., but you have no control over how quickly your instrument will respond.  Even when it does, you may not be able to know what point in time that piece of data will represent.  Does the query initiate a new measurement?  Or is the instrument reporting the most recent old measurement it happened to take?  Either way, there'll be some notable uncertainty in your ability to tag the data with an accurate timestamp.

 

I can't quite tell what's going on with sensor A, but it kinda looks like it might also involve communication that can't be controlled in time (USB and Ethernet?).  If so, you'll just have to try to associate a *separate* timestamp for the data you get there.  Some of the same issues would likely apply -- the best timestamp you can come up with will still have some uncertainty error.

 

Since you're writing to TDMS, I'd write these timestamps as channel data with names like time_A and time_B.  Each channel of sensor data gets its own associated channel of timestamp data.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 2 of 2
(2,171 Views)