LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pausing for loop while waiting for go ahead signal

Hello,

 

I am using two computers to do two separate things. Both computers run a VI that loops the same number N times. 

 

Computer 2 starts paused, waiting for a signal from computer 1. Computer 1 should complete loop n=1, then send a signal to computer 2 and pause while waiting for input from computer 2.

 

Then computer 2 will complete its loop n=1, send a signal back to computer 1, and pause. Then computer 1 moves to loop n=2, completes that loop, and sends a signal to computer 2 to go ahead with n=2, and pauses.

 

Computer 2 completes its loop n=2, sends a signal back to computer 1, and pauses. Computer 1 now continues with loop n=3, etc.

 

This continues until both computers complete n=N loops.

 

At this point I have successfully set up a TCP/IP connection between the two computers, and I am able to send a boolean between them (I convert boolean > string > boolean since I think TCP only allows to send strings). This will be the signal for the next computer to start its next loop.

 

What is the best way to accomplish pausing at the end of an iteration in a for loop while waiting for a signal to come in from another computer to continue the next iteration? Thanks for any help you can give!

0 Kudos
Message 1 of 4
(1,360 Views)

Instead of a FOR loop, you need a while loop and a state machine architecture. You can keep count of the of the number of "non-pause" executions in a shift register, for example.

 

We are graphical programmers and don't like long paragraphs of words. can you attach your code draft so we get a better picture.

0 Kudos
Message 2 of 4
(1,284 Views)

I completely agree (as usual!) with @altenbach.  In particular, I'm currently doing some LabVIEW Real-Time coding where you have one LabVIEW Project that has a "Target" system running a LabVIEW Real-Time OS and connected to the Host machine using TCP/IP.  Both the Host (the PC) and the Target (often a cRIO or something similar) are running State Machines, sending "Do this State next" to themselves or to the other system (Host ->Target or Target-> Host).

 

Suppose the Host has a State called "Ping", and the Target has a State called "Pong".  They exchange messages (I use Network Streams for this) using a Host-to-Target and Target-to-Host communication path.

 

Assume the Host is "in charge", and knows how many "Ping/Pong" sequences to run.  It runs (and counts) Ping, at the end of which it tells the Target to run "Pong", but doesn't give itself a message to run Ping again, but just waits.  The Target gets the message, runs "Pong", and sends the Host a message to run "Ping".

 

See where this is going?  The Host can now run a second "Ping/Pong" sequence.  At some point, the Host will enter Ping and realize it is finished, so instead of asking the Target to do "Pong", it sends the Target an "All Done" message, and goes to another Host state, itself (breaking both machines out of the Ping/Pong loop.

 

Bob Schor

0 Kudos
Message 3 of 4
(1,258 Views)

Hello all,

 

I have spent the past few days implementing your suggestions and I managed to get it to work. Thank you for pointing me in the right direction!

0 Kudos
Message 4 of 4
(1,205 Views)