From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

visa serial port and while loop

Solved!
Go to solution

I see.  I guess we're going off topic now.  Sorry about that.

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 31 of 55
(1,734 Views)

No problem. I hope this helps others. Soffi hasn't replied, so we don't know if he read this or if he resolved his issue. I think the shift registers on his While loop was the solution he was looking for, but I'm not positive.

0 Kudos
Message 32 of 55
(1,731 Views)

@Edjsch wrote:

What you need to do is to add a shift register for the VISA resource name and error. See the attached a screen shot.

 


Ed


Actually, putting a shift register on the error is generally a bad idea.  Unless you probably handle the error, (detect there is one, do something about it, and clear it), which hardly anyone does, you are going to have problems.

 

If you have a random timeout error, something that may cause a hiccup in the program, but otherwise doesn't cause a lasting problem, having the shift register will cause the error to effectively last forever.  It will iterate to the next loop, the functions won't run because of the error, and it will perpetuate to the next loop iteration after that.  The error will live forever in the shift register until you stop and restart the program.

 

One stray error you might otherwise be able to ride through will cause your VI to stop functioning properly.

0 Kudos
Message 33 of 55
(1,711 Views)

RavensFan wrote:

One stray error you might otherwise be able to ride through will cause your VI to stop functioning properly.


Which is why it is common to just stop the loop on an error.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 34 of 55
(1,693 Views)

I put the shift register on the error cluster because that's what NI Tech Support recommended way back. But as I said, I handle errors myself so I clear any errors. The timeout is the only one I've ever seen, and is caused by no data received, which I handle preventing the timeout from occuring. If an un-handled error happens in the run-time exe, the program crashes if un-handled. Here's the beloved "screen shot" of what I do at the right side of the loop, before the shift register (not shown), so errors don't propagate. The Simple Error Handler is for debugging. (BTW, that's not in my example vi I posted.)

 

Error Handler.png

Ed

 

0 Kudos
Message 35 of 55
(1,673 Views)

@Edjsch wrote:

I put the shift register on the error cluster because that's what NI Tech Support recommended way back. But as I said, I handle errors myself so I clear any errors. The timeout is the only one I've ever seen, and is caused by no data received, which I handle preventing the timeout from occuring. If an un-handled error happens in the run-time exe, the program crashes if un-handled. Here's the beloved "screen shot" of what I do at the right side of the loop, before the shift register (not shown), so errors don't propagate. The Simple Error Handler is for debugging. (BTW, that's not in my example vi I posted.)

 

Error Handler.png

Ed

 


Actually, I'd say this is swallowing the error, not handling it.  You'd never know you had an error.  This is the most brutal form of actual error handling.Capture.PNG

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 36 of 55
(1,656 Views)

I handle the error elsewhere, which only happens when no data is received. Then I put up a dialog with information about the error and possible solutions in my application, rather than letting the Simple Error Handler vi give some generic, unhelpful information. I know no data is received when Bytes at Port == 0. So, yes, I want to swallow the (timeout) error in the code I showed, as you put it, because I never let the timeout occur, and I don't want my exe to crash. I've never seen any error other than a timeout. Even if a USB VCP is disconnected while querying the instrument, the error gotten is no data received.

 

Of course, we are way off topic now, but it's important for robust code. Again, it doesn't look like the OP has even seen this, but it may help others.

0 Kudos
Message 37 of 55
(1,650 Views)

@Edjsch wrote:

I handle the error elsewhere, which only happens when no data is received. Then I put up a dialog with information about the error and possible solutions in my application. I know no data is received when Bytes at Port == 0. So, yes, I want to swallow the (timeout) error in the code I showed, as you put it, because I never let the timeout occur. And I've never seen any other error. Even if a USB VCP is disconnected while querying the instrument, the error gotten is no data received.

 

Of course, we are way off topic now, but it's important for robust code. Again, it doesn't look like the OP has even seen this, but it may help others.


Another old saying of mine:

It's the error you are NOT expecting will be the one that gets you.

 

Don't assume you know allt the errors that will ever occur.  In your case, handle that timeout error immediately, clear the error, then have what I posted as the last ditch effort to handle an unexpected error.  (Ideally it would also report the error and handle it in a more graceful manner.)

 

I guess what I saw wrong was that it ALWAYS clears ANY errors.  You want to use the output of that simple error handler and wire it to a case structure that only clears the error on a timeout error.

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 38 of 55
(1,640 Views)

You said, "In your case, handle that timeout error immediately..."

 

You're not getting what I said. That error CAN NEVER OCCUR in my application. And I believe that's the only error possible. Tell me another one, please. But just in case something unforeseen does happen, I clear it so my app doesn't crash. What else can I do for something unforeseen? This is the big, unresolved dilemma with unknown error handling, when there's nothing you can do about it anyway, so sometimes you have to just swallow it.

0 Kudos
Message 39 of 55
(1,634 Views)

@Edjsch wrote:

You said, "In your case, handle that timeout error immediately..."

 

You're not getting what I said. That error CAN NEVER OCCUR in my application. And I believe that's the only error possible. Tell me another one, please. But just in case something unforeseen does happen, I clear it so my app doesn't crash. What else can I do for something unforeseen? This is the big, unresolved dilemma with unknown error handling, when there's nothing you can do about it anyway, so sometimes you have to just swallow it.


NOOOooo.  You ALWAYS act on an error.  Ehhh, you'll get bit eventually.  Hoepfully you don't fry a $100k unit while learning that lesson.  That's a classic beginner's mistake - being sure they know evey error that will occur.

 

How about an error setting up your com port like it's missing?

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 40 of 55
(1,629 Views)