There is an annoying problem reported by our customers which is related to loosing an active SUB-20 handle. This may happen if during vi execution one presses the "Abort Execution" button or, for some reason, vi just stops working unexpectedly. In this case the vi doesn't have a chance to properly close the active SUB-20 handle. As the result the handle is "lost" and the only way to get SUB-20 back to work again is to reconnect the SUB-20 board. Sometimes, this is not an option, when for example, with remote debugging. The reason for such a problem is that the Labview doesn't call any method of the .NET component including the destructor when vi terminates unexpectedly. There is a workaround for this problem. The SUB-20 contains a pair of methods: GetHandle and CloseHandle. The idea is to save the SUB-20 handle in a local/global variable immediately after a successful "Open" call and zero-out this variable after the "Close" call. You can obtain the SUB-20 handle by calling the "GetHandle" method. Then, if script is stopping abnormally, for example one has pressed the red "Abort Execution" button, the saved handle is still valid and you can close it by using the "CloseHandle" method. Attached vi demonstrates this approach. I am not a Labview expert, I couldn't find a way to zero-out the variable when script terminates normally, I have multiplied the GetLastError result by 0. It works, but, I am sure, there is more intelligent way to do it.
SUB-20 RESET
The second method would require another SUB-20 ( or any other GPIO capable ) device. There is no reliable way to programmatically reset an USB device attached to a PC. The idea here is to RESET the on-board CPU, so the SUB-20 would get reconnected and as the result it will be accessible again from the software. There is a 6-pin J2 connector on the board. The connector is located on the corner, near the SW2 button. The pin#5 of the J2 is connected to the /RESET pin of the CPU. You can connect pin#5 of J2 to one of GPIOS of another SUB-20 or any other GPIO device. You can also use one of the GPIOs of the same board, however, as mentioned in the scenario above, the SUB-20 may become inaccessible, so we should use external GPIO. There is an 10k pull-up on pin#5. To reset the board you will need to configure selected GPIO pin as an output. The default value of GPIO is 0, so after switching the pin to output it will drive "0" and as the result will reset the board.
LabView: Abort Execution problem and SUB-20 RESET
Moderator: serg
LabView: Abort Execution problem and SUB-20 RESET
- Attachments
-
- handle_abort.zip
- handle_abort.vi
- (10.77 KiB) Downloaded 2178 times