Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Main thread and callback thread both communicate with the gpib device at the same time !!

Hello,

Can someone please advise,

 

I use the ibnotify function in order to get the asyn. notification mechanism. The problem with this approach is when callback is beign called, the main thread is already running in the background. So both of these threads may talk with the gpib device at the same time. The callback is being called when an error appears in the gpib device, so all I need is to read the error queue of the device (within the callback body). Is there a way to abort/cancle/suspend the main thread while executing the callback ? or maybe some way to configure the device to become attentive only for the current thread ?

 

Thanks, y.

0 Kudos
Message 1 of 7
(3,765 Views)

I use.net environment - c#/c++/cli..

0 Kudos
Message 2 of 7
(3,764 Views)

Hey yanyan,

 

I was looking at the ibnotify help for LabWindows/CVI. I realize you are using .NET and not C, but this gives me some insight into how to get around this:

 

http://zone.ni.com/reference/en-XX/help/370051T-01/cvi/libref/cviibnotify/#345e695c

 

Here is the snippet that looks most helpful:

________________

 

Because the callback is called in another thread, you must protect any data that is shared by the callback and your main program...

Asynchronous callbacks can be called at any time while your program is running. You do not have to allow the system to process events. Because the callback is called in another thread, you must protect any data that is shared by the callback and your main program. You must not call ibnotify or ibInstallCallback from the callback.

 

If you need to do perform operations that are not thread safe or perform operations that must be done in your main application thread, you can do the following:

  1. In your asynchronous callback,
    • Perform the time-critical operations
    • Call PostDeferredCall to schedule a synchronous callback.
  2. In the synchronous callback, perform the rest of the operations.

_________________

 

I hope this helps!

 

Peter E
Applications Engineer
National Instruments
0 Kudos
Message 3 of 7
(3,738 Views)

Hey Peter,

Thanks alot for your answer, it's very helpful.

 

Could you please elaborate on how do I Call PostDeferredCall to schedule a synchronous callback form the async. callback ?

Never heard about this ..

 

Thanks again, y.

0 Kudos
Message 4 of 7
(3,732 Views)

Hello again Peter,

 

I did some reading on the subject, so please disregard my my former post.

These suggestions you mentioned are very interesting, it's just that these methods are not available to me - PostDeferredCall and ibInstallCallback..

I use the NI 488.2 driver under the c++/cli .net environment.

Thanks, y. 

0 Kudos
Message 5 of 7
(3,730 Views)

Hey Y.

 

I see that you posted on the CVI forum as well. Was that for the same issue?

Luke gave you some good suggestions regarding locking the threads to synchronize the GPIB measurements. Did this work for you? Implementing this in C++ may be a bit different, but the idea is the same. 

 

This example from the Microsoft website shows how you can implement this in C++

 

Let me know if this helps!

Peter E
Applications Engineer
National Instruments
0 Kudos
Message 6 of 7
(3,705 Views)

Hey Peter, yes I did post over there because I wasn't sure it was the right place. Thanks alot for answering, you and Luke gave me really great ideas. Thanks alot for your time.

0 Kudos
Message 7 of 7
(3,702 Views)