02-19-2010 08:53 AM
LabVIEW 8.6.1f1, Win Vista
I have a once-in-a-blue-moon error in my program, that I need to track down.
I have boiled it down to a simple test case, where the error occurs more frequently (but still relatively rarely).
I have a program called TCM, which is separate from my main code HDT.
TCM might run on a separate machine, but for this test it's on the same machine, running under LV development system.
This test simply opens a TCP connection to the TCM, asks for a "signature", receives it, and shuts down the connection.
The part that opens the connection also starts the TCM RECEIVER running, and killing the connection shuts down that receiver.
Here's the main test code, and you can see I'm getting an error apparently because I get no response within 2000 mSec:
---------
The GET TCM SIGNATURE code is here: What it does is send out a request for the signature and then waits for either a SIGNATURE RECEIVED event from the RECEIVER, or a timeout of 2000 mSec.
The error I get (-100005) comes from here. If the TCM was actually failing to respond, it would look just like this. Indeed, that is why the timeouot trap is here.
-----------
However, here is the receiver code and panel, immediately after a failure.
The ARRAY clearly shows that it DID receive the TCM SIGNATURE from the TCM.
The fact that there are NOTHING commands in the array says that the receiver was still running for 2000 mSec (4x500 mSec) after receiving the command.
When it receives a SIGNATURE, the code says to trigger an event. No errors are reported here.
So what is going on? It looks like the event should be triggered, but it's not being received ( Event #0 in pic #2 reacts to the event and returns the signature word, without error).
It doesn't happen all the time - this case failed on loop # 211 - that number is between 20 and 2000.
Having all these windows open makes it fail more often: without them it still fails, but takes several thousand loops to do so.
So maybe it's related to CPU busy-ness.
I have verified that there is no error with the REGISTER EVENTS function, even when it fails.
I keep coming back to the fact that the ARRAY in pic#3 says that the signature was received, but it looks like the EVENT didn't get generated or received.
What can cause that?
Is it possible that, since the receiver is dynamically loaded and run, that things aren't really set up and ready when it says they are?
Blog for (mostly LabVIEW) programmers: Tips And Tricks
Solved! Go to Solution.
02-19-2010 09:04 AM
Re: Dynamic as a possiblity...
Mike Porter recently told me about an issue where he was open a Vi dynamically and then checking for all VI's in memory and was suprised to find that the VI he just opened did not show up in the list. In his case he (?) added a seq structure after the Open and that cleared up what appeared to be a race condition where the open node was actually returning before the VI was completely loaded.
So based on that story and your suspicions, I think you may be onto something with suspecting the dynamic load playing a part in this.
Question to anyone:
Does the Time Out of an Event structure start when the VI starts, or when the Event is first executed?
If I look at the fact that Static Events will fire before the Event struture executes and I view the TO as a static Event then maybe the TO is too short for the first start condition. If so, you may want to use a SR to set the TO to be intitally large buta after the first TO, set it back to 2 seconds.
Not caliming to know what's up but always curious about the unexplained,
Ben
02-19-2010 09:35 AM
In his case he (?) added a seq structure after the Open and that cleared up what appeared to be a race condition where the open node was actually returning before the VI was completely loaded.
--- I forgot to mention it, but I tried that.
I tried it again just now: after the RUN VI, I attached a wait of 1000 mSec, to let the RECEIVER actually get started up and running.
It failed after only 4 loops with the same symptoms: the SIGNATURE was actually received, there's no way that can happen without triggering the event, but the event does not get seen by the EVENT loop.
And now that I think about it, that wouldn't explain what I see: The dynamic VI is the receiver, and that part has done it's job: it reports the command being received.
It's more like the EVENT mechanism hasn't been set up yet.
Maybe that's my problem!
In picture #2, I REQUEST the signature, and THEN I register for the event. The request gets sent, that probably wakes up the TCM code, it sends its response, which wakes up the receiver, it receives the code and triggers the event, but the REGISTRATION process hasn't completed yet.
Back in a few minutes.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
02-19-2010 09:41 AM
Does the Time Out of an Event structure start when the VI starts, or when the Event is first executed?
That HAS to be when the event executes. Consider the case where it's in a loop: the TIMEOUT timer has to start every time.
When I first played with event loops way back when, I was surprised by that, but it makes sense.
If you have 1000 mSec timeout and you hit ANOTHER event at T = 999, the TIMEOUT doesn't happen until T = 1999.
IOW, it got reset when the event executed - the other event pre-empted it.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
02-19-2010 09:55 AM
OK, that seems to have fixed it. - it's run 5000 loops, with the windows open and no failure.
How completely obvious it sounds, when I put it into words:
Do not ask a question until you're ready to hear the answer.
The revised version registers for events and THEN asks for the signature.
That way, when the answer comes, even if it's immediately, you're ready.
Do not ask a question until you're ready to hear the answer.
Do not ask a question until you're ready to hear the answer.
Do not ask a question until you're ready to hear the answer.
Do not ask a question until you're ready to hear the answer.
Do not ask a question until you're ready to hear the answer.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
02-19-2010 10:16 AM
Blog for (mostly LabVIEW) programmers: Tips And Tricks
02-19-2010 10:25 AM
So the dumbed down version of your answer is
"Put on your cather's mitt before you tell the pitcher to throw the ball."
?
Ben
02-19-2010 10:30 AM
"Put on your catcher's mitt before you tell the pitcher to throw the ball."
Blog for (mostly LabVIEW) programmers: Tips And Tricks