LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Twin VIs run differently depending on which starts first

I'm fairly new to LabView and I'm experimenting with parallel loops in a server/client configuration. I've written a VI that counts the number of seconds since the VI started and sends that count over TCP to a twin VI which receives the packet and sends its own second counter. The VIs are quite literally twins with the only difference being swapped listen/send ports. 

 

When I run the VIs I get some strange behavior... which ever one starts first runs perfectly fine. It counts seconds and sends that count over TCP and the main receive loop runs normally as well. The VI that is started after the first, however, does not run correctly. It receives packets from the other VI but it does not count/send seconds. I cannot seem to figure out why this is happening... the two VIs are identical and should behave the same what should it matter which one was started first.  Does anyone know what is happening and if so can you please tell me.

 

I've attached the two VIs as a reference in hopes that someone can help me resolve this issue.  

 

Any help would be much appreciated,

 

 

~meanmon13

Download All
0 Kudos
Message 1 of 14
(3,084 Views)

Don't quote me on this, and I can't open your VIs so I'm just guessing, but are you trying to listen on the same port with both VIs? You can't have two listeners on the same port (I don't believe). Try setting up listeners on each end on different ports and see if that works. The order matters because whichever VI starts first will set up a listener on that port, the other one wont be able to. Therefore you won't get the data sent to it. Run with highlight execution on and I bet you will see an error when you try to create a listener in the second VI you start.

0 Kudos
Message 2 of 14
(3,076 Views)

Here are some screenshots since you cannot open it. I do have swapped listen and read ports on the two VIs so only 1 listener per port. I have run it with the highlight execution and that just confirmed the behavior I described in my opening post. 


The only error I get is 56 - Timeout which I expect and a few times I got 63 - Connection Refused (haven't gotten it at all in the most recent version of my VI). 

 

~meanmon13

Download All
Message 3 of 14
(3,057 Views)

You have some fundamental errors in your code. First, you can't guarantee those local variables will be set to 0 BEFORE your loop starts. Next, why are you using a local variable for a counter? Just use the "i" terminal.

 

Next, why are you opening and closing your connection every time your loop spins? Put the open connection outside the loop, and put the close connection outside the loop on the other side. Use error wires to enforce the data flow.

 

Also, in the "left" loop, you are closing your tcp connection once data is received one time. This is making the connection invalid. Then you wait again because the connection in your "right" loop was closed then reopened. This is all unnecessary.

 

Look at some of the tcp/ip examples in the labview help. That should get you started.

 

0 Kudos
Message 4 of 14
(3,043 Views)

I only want to receive the packet and then close the connection. Same for sending the data... I want to close the connection immediately after sending the data... I want to use this VI as a base for a TCP Server that can handle multiple clients and many packets a second. If I don't close the connections the VI slows down overtime and essentially stops working. 

 

So, If i put the close connection outside the loops then it won't close the connections until the loops stop and the VI shutsdown.

 

Oh and thanks for the tip on the "i" terminal 🙂 

 

Also, HOW can I guarantee that a section runs only once and before anything else ( to initialize variables and such) 

 

~Josiah s. Yeagley

0 Kudos
Message 5 of 14
(3,032 Views)

There is a "tcp multiple connections" example in LabVIEW help. Use that. It has examples of how to do everything you are asking.

0 Kudos
Message 6 of 14
(3,027 Views)

Thank you for pointing me to a good example.... I think in my version its called "TCP Communicator - Passive" as I could not find a "TCP Multiple Connections". How can I take that and add a 1 second timed loop to it that would run in parallel to the rest of the VI?

0 Kudos
Message 7 of 14
(3,020 Views)

I have made some changes after examining the example and reading your posts but now the first VI that starts up only counts seconds and I get spammed with the following error "Error 1 occurred at TCP Close Connection in TCPServer2.vi:  An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @." at a frequency so great that I cannot stop the VI and have to go into the task manager to end it.  The second VI to start only errors out and does not even count seconds....

0 Kudos
Message 8 of 14
(3,003 Views)

 


@meanmon13 wrote:

I have made some changes...


 

 

Please attach your actual code.

 

(Also, for something like this, you might actually want to use UDP, depending on how deterministic things should behave.)

0 Kudos
Message 9 of 14
(2,991 Views)

Here is the code with the changes that error out every time... I can't seem to fix it so I've gone back to my old code to try and fix that... not really getting anywhere. As for UDP I'm going to have to communicate with a client I didn't make and don't have the source to so I cannot change it to UDP so i'm stuck with TCP for now. 

Download All
0 Kudos
Message 10 of 14
(2,986 Views)