Measurement Studio for .NET Languages

キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

SerialSession

Sometimes when opening a SerialSession I get a NationalInstruments.VisaNS.VisaException: Specified type of lock cannot be obtained, or specified operation cannot be performed, because the resource is locked.  VISA error code 0xBFFF000F, ErrorResourceLocked. 
 
Usually this occurs while debugging, e.g. after killing the process that owns this dll and restarting it.  The strange thing is that both in hyperterminal and the measurement and automation explorer, I can open the port and communicate without problem.  Restarting the computer will fix the problem but that is a little drastic.
 
Any ideas?
 
Thanks,
 
Jeff
0 件の賞賛
メッセージ1/13
5,841件の閲覧回数
Hey Jeff,

That error code usually means that the resource you're trying to access has been locked by another process. In this case, you probably didn't use a VISA close to close the previous VISA session. If that's the case, then you don't need to reopen that session. You should just be able to do reads and writes to the current session. If you want to reopen the session, then just make sure to end the process by using a VISA close when you're done with it elsewhere in the code.

Hope this helps!

Jason W
Application Engineer
National Instruments
メッセージ2/13
5,808件の閲覧回数

Hello Jason,

I figured something like that; normally I will close the session but when things crash or processes are killed I don't have the opportunity.  Before I didn't see how I could get the session pointer without creating a new one but I'll look at the NI API more thoroughly now.

Thanks,

Jeff

0 件の賞賛
メッセージ3/13
5,800件の閲覧回数

No luck in figuring out how to get the SerialSession pointer without calling new (which gives the exception).  Any idea on how to do this?

Thanks,

Jeff

0 件の賞賛
メッセージ4/13
5,781件の閲覧回数

Hey Jeff,

If I understand what you are asking correctly, I believe this knowledge base will answer your question.  Make sure you take a look at the attached pictures.

Hope this helps!

Regards,

Jason W
Applications Engineer
National Instruments

 
メッセージ5/13
5,775件の閲覧回数

Hello Jason,

Sorry I didn't see any relevant information in the knowledge base article because

1) I can't close the session programmatically if the module crashes.

2) Unlike the article the port really isn't in use since I can, subsequent to the exception, open it in Hyperterminal or NI's Explorer.

3) Maybe what the picture shows is some way to enumerate all the in-use Visa port sessions.  If so I need to know what API to call to do this in C# (preferably) or C/C++.

Another way to phrase the question is how and why NI's explorer can open the port and my C# code can't?  Maybe this is due to a limitation in Visa's C# implementation and I need to call some Visa C API?

This is very important for my project because the alternative of restarting the OS will reset all the USB devices which is highly undesirable.

Thanks,

Jeff

0 件の賞賛
メッセージ6/13
5,771件の閲覧回数
Hey Jeff,

What version of VISA are you using?

Thanks,

Jason W
Applications Engineer
National Instruments
メッセージ7/13
5,730件の閲覧回数

Hello Jason,

The VisaNS dll is version 8.0.20.177
NI-Visa 3.6
visa32.dll 3.6.0.49153
nivisaserver.exe 3.6.0.49152
nivisaic.exe 3.6.0.49152

HTH,

Jeff

0 件の賞賛
メッセージ8/13
5,723件の閲覧回数
 

Hey Jeff,

 

Something I would recommend is updating your VISA driver from 3.6 to 4.0. You can download the latest driver here.

The new driver may have improved coding to deal with crashes in the middle of a program by a crash, or an abort.

Are you able to replicate this with a simple program? I opened an example program in labVIEW and did an abort in the middle of a serial write session, and then as long as I ran it again, and made sure to close the VISA session everything was fine. I know you're programming in C++, but the driver function calls should be the same. I am using VISA 4.0, so it may be as simple as a driver upgrade that will solve this problem.

Can you let me know if that helped?

Good luck!

Nick D.

0 件の賞賛
メッセージ9/13
5,686件の閲覧回数

Hello Nick,

I'll try updating to VISA version 4 this afternoon and see if it works. 

One problem I have is how can I close the Visa session when rerunning my module as you are doing in LabVIEW?  Normally I need a pointer (actually reference) to the session in order to call the close function.  I suspect there must be some low level close function, probably in C, that I can call to close.

Another possibility is that this is a C# bug, and that the Visa session is really closed but some NI module has a variable that says it wasn't closed.  This would explain why I can still open the port using NI's Explorer or Hyperterminal.

Jeff

0 件の賞賛
メッセージ10/13
5,683件の閲覧回数