Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I free a lock made with viLock if my debug session quits before the viClose?

If I lock an instrument session (viLock) and the session is not unlocked when the debug session is closed, the next time I run the code VISA tells me that the device is locked. Is there any way to free up locks that were never cleared like this (apart from rebooting the PC?).

 

Thanks,

 

Ronnie

TestStand 4.2.1, LabVIEW 2009, LabWindows/CVI 2009
0 Kudos
Message 1 of 10
(4,486 Views)

Sorry - my fault - I was trying to lock the device twice by mistake.

I guess the lock is freed when the debug session quits anyway.

TestStand 4.2.1, LabVIEW 2009, LabWindows/CVI 2009
0 Kudos
Message 2 of 10
(4,479 Views)

Hey Ronnie,

 

Glad to hear you found a solution to the issue, and thanks for posting it!

Justin E
National Instruments R&D
0 Kudos
Message 3 of 10
(4,448 Views)

Hello,

I'm actually work for a company in Germany and need to automate test cases with high end spectrum analyzers.

All stuff is working.

 

But I got the same effect as you:

after closing a debug-session, the VISA session of the device is still locked!

 

And I have to reboot the device to relock it again.

 

I do normal cases:

  1. viOpenDefaultRM
  2. viOpen
  3. viLock
  4. ... read, write, clear, ... stuff
  5. viUnlock
  6. viClose

But if I close the debug-session after step 3. or 4. the unlock and close can not be run.

 

How can I relock the old VISA session on next connection?

 

Best regards,

VikingGod

 

 

0 Kudos
Message 4 of 10
(3,851 Views)

Hey VikingGod,

 

If you are using LabVIEW you can refer to this KnowledgeBase on using the Visa Resource Monitor 

http://digital.ni.com/public.nsf/allkb/6A9B4BA95EFA6C22862575080064D98F?OpenDocument

 

If you go to Programs » National Instruments » NI-VISA » Examples »  C » General » Locking_MSVC_VS2005.vcproj, this example goes over locking VISA resources for use, it also shows how you can safely exit a program to ensure that your VISA resources are released when your program terminates. 

Hope this helps.

BeauH
Applications Engineer
National Instruments
0 Kudos
Message 5 of 10
(3,830 Views)

Hi BeauH,

thank you for the fast reply.

I checked the example, but we make the same stuff.

 

If I close our program with the "close button" than everything is going right.

But if I stop the process by clicking "STOP" from inside the Visual Studio debugger;

my code (=destructor) to send viunlock and viclose will not be run. The programm is hard terminated by the VS debugger.

 

In this case, I have no chance to run last code steps to unlock the VISA session.

 

Do you know what I mean?

 

It is not a normal programm termination by closing via close button, or exit.

The programm is running by VS debugger and is closed/terminated by VS and not by normal close process.

0 Kudos
Message 6 of 10
(3,817 Views)

Hey VikingGod,

When you stop your program(terminate execution) and if you were to just "run" the program again without rebooting the device, do you get an error message or Run-time error, and even after those errors the VISA resources are still locked? If you do could you post a screenshot of the error?

Thanks

BeauH
Applications Engineer
National Instruments
0 Kudos
Message 7 of 10
(3,793 Views)

Hi BeauH,

after stop programm by debugger, the unlock and close function could not be called.

On next start I got on open following error:

VI_ERROR_RSRC_LOCKED  /* BFFF000F, -1073807345 */

 

So my device is still locked.

 

How can I unlock it again, on the next start?

 

I just try to save the handle and unlock this handle on next start, but it is not working (still locked)

Only a reboot of the device is helping.

 

Hope you have a better solution for us 😉

 

Best regards and thanks for your support!

 

0 Kudos
Message 8 of 10
(3,787 Views)

Hey VikingGod

 

Would it be possible to get a I/O Trace screen capture of what calls are being made and resources being reserved and released, or not released as seems to be the case? If you are unfamiliar with NI I/O Trace here is a good walkthrough http://digital.ni.com/public.nsf/allkb/282C5D41E2BA04F2862574BA007803B9?OpenDocument

 

 

 

 

BeauH
Applications Engineer
National Instruments
0 Kudos
Message 9 of 10
(3,766 Views)

Was this ever resolved? I too am having a very similar issue to what you are describing.

0 Kudos
Message 10 of 10
(1,092 Views)