12-29-2011 07:52 AM - edited 12-29-2011 08:00 AM
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.
12-29-2011 07:54 AM
I use.net environment - c#/c++/cli..
12-30-2011 03:11 PM
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:
_________________
I hope this helps!
12-31-2011 02:43 AM
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.
12-31-2011 03:43 AM
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.
01-03-2012 12:18 PM
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!
01-03-2012 12:54 PM
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.