LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP-IP connection ID doesn't work after being assigned to a global

Solved!
Go to solution

Can someone help me understand why the following does not work? A direct connection of the connection ID works fine.

 

diagram.png

 

The error is "TCP Read in tcpip test open and read combined using global.vi".

My goal was to open a telnet session and use the connection ID throughout my testing in various VIs called as TestStand steps, and finally close it once the testing is done.

0 Kudos
Message 1 of 25
(3,675 Views)

Classic case of a race condition!!!

 

The reading of the global variable has no data-flow dependency to the writing/setting of that global variable. LabVIEW will run everything it can in parallel hence the global variable is already read out at the beginning of your code - in parallel to the "TCP open connection", before a new value gets set.

 

Regards, Jens

Kudos are welcome...
0 Kudos
Message 2 of 25
(3,669 Views)

So what is the best strategy to adopt? Should I open and close a telnet session every time I want to send a telnet command?

0 Kudos
Message 3 of 25
(3,664 Views)

Should I open and close a telnet session every time I want to send a telnet command?

NO!!

So what is the best strategy to adopt?

Respect the dataflow-paradigm of LabVIEW and make sure, that the global variable gets read only after it was written.

For your screenshot, a flat sequence would solve the problem:

grafik.png

 

Regards, Jens

Kudos are welcome...
0 Kudos
Message 4 of 25
(3,650 Views)

Why are you using a global variable in the first place. Directly wire the TCP reference. I try to avoid using local or global variables as much as I can. Exceptions are what are called WORM (Write Once Read Many) variables. However, there is no reason that your code snippet above needs to use variables.

 

In fact, you don't really need to use the delay between the write and the read either. Simply incorporate the extra time in your read timeout value.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 25
(3,643 Views)

@Mark_Yedinak wrote:

Why are you using a global variable in the first place. Directly wire the TCP reference. I try to avoid using local or global variables as much as I can. Exceptions are what are called WORM (Write Once Read Many) variables. However, there is no reason that your code snippet above needs to use variables.

 

In fact, you don't really need to use the delay between the write and the read either. Simply incorporate the extra time in your read timeout value.


The zip file had the original in it that was directly wired.  I believe he is trying to scale this thing beyond this VI.

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 6 of 25
(3,637 Views)

@jg69 wrote:

Should I open and close a telnet session every time I want to send a telnet command?

NO!!

So what is the best strategy to adopt?

Respect the dataflow-paradigm of LabVIEW and make sure, that the global variable gets read only after it was written.

For your screenshot, a flat sequence would solve the problem:

grafik.png

 

Regards, Jens


Let's not teach bad habits - i.e., using sequence structures when they aren't really needed.  Provided that you aren't going to use this connection any more in this VI, there's nothing wrong with this:

Capture.PNG

IF, of course, this VI runs before any other VI which relies on that global.

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 7 of 25
(3,632 Views)

The reason a global was used is because I inherited it from older code. The global would be set in one TestStand step, and then a later step would use the global to continue the persistent telnet session.

0 Kudos
Message 8 of 25
(3,627 Views)

@billko wrote:

@Mark_Yedinak wrote:

Why are you using a global variable in the first place. Directly wire the TCP reference. I try to avoid using local or global variables as much as I can. Exceptions are what are called WORM (Write Once Read Many) variables. However, there is no reason that your code snippet above needs to use variables.

 

In fact, you don't really need to use the delay between the write and the read either. Simply incorporate the extra time in your read timeout value.


The zip file had the original in it that was directly wired.  I believe he is trying to scale this thing beyond this VI.


I would still look serious at variable usage. I rarely ever find a need to use them and I work on VERY large systems. Our current system uses over 125 packed project libraries with hundreds of classes. Variable usage is often a sign of a poor design.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 25
(3,622 Views)

I admit my example is bad LabVIEW coding. I just wanted to explain the race condition in more detail. Think of the sequence as a representation of different subVIs.

 

Regards, Jens

Kudos are welcome...
0 Kudos
Message 10 of 25
(3,614 Views)