LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I merge the close in LIFA ?

Solved!
Go to solution

Hi, all

I have two while loops,that use same arduino INIT, splitting two different algorithm due to different sampling rate (please see the VI attached). How can I connect close node with two pink arduino lines?

Thank you

0 Kudos
Message 1 of 4
(4,274 Views)
Solution
Accepted by topic author JongKim

You only need to close one of them because they reference the same Arduino.  So, as long as you have an error cluster coming from each loop (merged and wired to the close VI like you have it) the close Close VI will not execute until both loops have finished.

0 Kudos
Message 2 of 4
(2,995 Views)

Thank you very much

0 Kudos
Message 3 of 4
(2,995 Views)

Jong,

You should really not split the reference wire and use it in two parallel loops as it introduces a race condition.

The problem is that the communication between LabVIEW and the Arduino is synchronous, meaning you send a command, there is a delay, you get a response...repeat.  When you branch the wire and run parallel loops with Ardiuno VIs you introduce the potential to send a command, and then send another command before the first one returns.  In this case data can get out of sync (the response to the first command might go to the second, etc) and cause one or both of the loops to return errors.

The worst part of this is that race conditions are very hard to reproduce and debug.  The race condition may happen once every 5 minuts or once every 5 years and won't occure at a fixed rate.  It may seem to be working fine in your case, but you should really consider rewriting your code to remove the race condition.

You should use a state machine to operate the two tasks at potentially different rates.

-Sam K

LIFA Developer

(Nathan is correct about the reference being the same and only having to close it once...but splitting it is a bad idea).

Message 4 of 4
(2,995 Views)