04-02-2009 12:18 PM
GerdW wrote:Hi Tzench,
you should always check errors in loops to avoid endless iterations...
And I would advise to use shift registers with error wires!
Gerd,
Are you sure about this? I generally don't use shift registers on error wires. Suppose I am repeatedly reading a VISA in a while loop but I get a timeout error, perhaps a cable was accidentally unplugged. I want to try the read again on the next iteration. But the timeout error would be sent into the next iteration and would keep the VISA read from trying to read the port again.
04-02-2009 09:46 PM
There are few points about the code.
1. When the first loop doesnt get data it will be struck in the loop for ever which will stop your timer from ticking, the other operation scheduled for 250ms will not happen.
2. If the first loop ends with error and gets out of the loop, yes the second loop also will get the error as you said. But if first while loop successfully gets gets the data what is the probability that second loop will not generate and get struck within it.
3.If you are not interested with error handling at least make a timeout exit as shows in the picture which will force the loop to exit after specified time has elapsed.
04-03-2009 03:44 AM
GerdW wrote:Hi Tzench,
you should always check errors in loops to avoid endless iterations...
And I would advise to use shift registers with error wires!
Should the error wire be connected to a shift register? What would be the purpose of that?
04-03-2009 03:54 AM
2. If the first loop ends with error and gets out of the loop, yes the second loop also will get the error as you said. But if first while loop successfully gets gets the data what is the probability that second loop will not generate and get struck within it.
But if there is an error in first loop, there is no mechanism that will automaticaly skip the second loop is there? Therefore, there should be some kind of check if the first loop worked before starting the second. I could put the second loop in a case structure connected to the status boolean - there is hardly any point in trying to read again if it didn't work the first time.
04-03-2009 03:56 AM
Hi TZench,
without a shift register you would always use the state of error that enters the loop, changes of error state in the loop will be forgotten by next iteration...
I think it's a bad idea to forget changes of error state... It will definitely be better to incorporate some error checks in your code.
04-03-2009 03:57 AM - edited 04-03-2009 03:58 AM
04-03-2009 09:55 AM - edited 04-03-2009 09:58 AM
04-03-2009 10:01 AM - edited 04-03-2009 10:02 AM
That's weird, when I went to edit the previous post to insert the picture, it didn't give me the original text. And every time I pasted it back in (luckily I has a sense something was going to go wrong and I saved it to a text file before it got lost), it never actually submitted the text I pasted. I still think these forums have major problems with the editor that just didn't exist with the old editor months ago.
Ravens Fan wrote:
04-03-2009 10:04 AM - edited 04-03-2009 10:06 AM
IT DID IT AGAIN! I'll try again by completely logging out of the forums and closing IE and coming back in.
--------------------------------------------------------------------------------
Ravens Fan wrote:
Here is the mechanism to skip the second loop in the event of an error in the first loop.
Gerd,
I disagree that you would want to put a shift register on the error wire of a while loop.
Suppose you have a while loop where you continually write to a serial port then read from it. You've put in timeouts so that the loop doesn't get stuck waiting for bytes that might never come such as someone kicked a cable. They discover it and plug it back in. Wouldn't you want the loop to continue to try writing and reading again? I would. But if you carry your timeout error into the next iteration of the loop, the VISA write and read will be skipped.
In general, if you have errors at the end of a while loop, you should plan for them and handle them accordingly, whether it is to stop the loop, clear certain errors, flash a warning on the front panel, (rarely use pop up dialogs as they would stop the program, or give continuous popups each time you hit OK). Perhaps if you have a sort of state machine and you want to carry the error into the next iteration that executes an error case, handles the error, and clears it in that following iteration, then you would want a shift register. But I would never wrap just a VISA read as shown in the OP's code with just a shift register without handling the error in some special way.
04-06-2009 04:20 AM
About delay:
I have used the tick count since I need to synchronize two different events with different period time. Introducing some form of delay, and still keeping the tick count seems absurd, whouldn't I risk missing some event? should I not remove the tick count instead, and use some other timing device?