Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Asynchronous Communication fails

Hi,

I am using Visual Basic.NET 2003 and measurement studio together with National Instruments NI-VISA(TM) Software for Windows. Version 3.0.
Synchronous communication with GBIP instrument (ESG E4438C from Agilent) works fine but I have a problem with asynchronous I/O.
I always get an error like "Unable to queue the asynchronous operation (usually due to the I/O completion event not being enabled or insufficient space in the session's queue)."
What went wrong?

Here is my code:

Private Sub btGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btGo.Click
AxCWVisa.RsrcName = "visa://149.204.55.39:3537/GPIB0::19::INSTR"
AxCWVisa.Open()
AxCWVisa.WriteAsync("*idn?")
End Sub


Private Sub AxCWVisa_IOC
ompletion(ByVal sender As Object, ByVal e As AxCWVisaLib._DCWVisaEvents_IOCompletionEvent) Handles AxCWVisa.IOCompletion
MsgBox("IO completed")
End Sub


I have tried to Enable Events
AxCWVisa.EnableEvent(CWVisaEventTypes.cwvisaEventIOCompletion)

but all without success.

Thank you for your help,

Markus
0 Kudos
Message 1 of 5
(6,571 Views)
Markus:

While it *should* work, I noticed that you're using the old ComponentWorks controls. Measurement Studio now has a .NET native set of APIs, including a new one for VISA. You might want to try that instead.

But since you've got the old controls on your system, I'll give you some ideas that might help you. First, you must call the EnableEvent method on I/O completion *before* performing asynchronous I/O. Otherwise the error you are getting is expected.

Another thing to do is to use NI Spy to see if the intermediate APIs are making additional VISA calls that you might not be aware of. Sometimes the Measurement Studio layers make multiple VISA driver calls per single higher-level call.

If you still can't get asynchronous I/O to work properl
y, you might consider spawning your own threads inside .NET and letting them do synchronous I/O. That could provide the same overall effect.

Hope this helps,
Dan Mondrik
National Instruments
0 Kudos
Message 2 of 5
(6,570 Views)
Hi Dan!

Thank you for your answer.

I have tried again the EnableEvent method but this fails. Here is my code:

AxCWVisa.RsrcName = "visa://149.204.55.39:3537/GPIB0::19::INSTR"
AxCWVisa.Open()
AxCWVisa.EnableEvent(CWVisaEventTypes.cwvisaEventIOCompletion)

After calling the EnableEvent method I get an exception with the following message:
"Additional Information: Configuring Device
The specified mechanism is not supported for the given event type."

Since this is visaconnection across a network I have tried the asynchronous access at the local maschine - but with the same error message. So the network access should not be the problem.

Using NISpy I get the following Info:

1. viOpenDefaultRM (0x001AEC58)
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:12.838 Call Duration: 00:00:00.421
Status: 0 (VI_SUCCESS)
2. viParseRsrc (0x001AEC58,"visa://149.204.55.39:3537/G...",1 (0x1),0 (0x0))
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.259 Call Duration: 00:00:00.110
Status: 0 (VI_SUCCESS)
3. viClose (0x001AEC58)
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.369 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
4. viOpenDefaultRM (0x001AEC58)
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.369 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
5. viOpen (0x001AEC58,"visa://149.204.55.39:3537/G...",0 (0x0),0 (0x0),0x001DD1E0)
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.369 Call Duration: 00:00:00.219
Status: 0 (VI_SUCCESS)
6. viSetAttribute (0x001DD1E0,0x3FFF001A,2000 (0x7D0))
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.588 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
7. viSetAttribute (0x001DD1E0,0x3FFF0005,5000 (0x1388))
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.588 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
8. viSetAttribute (0x001DD1E0,0x3FFF0007,0 (0x0))
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.588 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
9. viSetAttribute (0x001DD1E0,0x3FFF0177,-1 (0xFFFF))
Process ID: 0x00000A40 Thread ID: 0x000009D8
Start Time: 09:54:13.588 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
> 10. viSetAttribute (0x001DD1E0,0x3FFF0021,9600 (0x2580))
> Process ID: 0x00000A40 Thread ID: 0x000009D8
> Start Time: 09:54:13.588 Call Duration: 00:00:00.000
> Status: 0xBFFF001D (VI_ERROR_NSUP_ATTR)
> 11. viSetAttribute (0x001DD1E0,0x3FFF00B3,2 (0x2))
> Process ID: 0x00000A40 Thread ID: 0x000009D8
> Start Time: 09:54:13.588 Call Duration: 00:00:00.015
> Status: 0xBFFF001D (VI_ERROR_NSUP_ATTR)
...


Any idea what went wrong?

Thank you for your help!

Markus
0 Kudos
Message 3 of 5
(6,570 Views)
Markus:

Well, the excerpt from NI Spy isn't enough to show the call to viEnableEvent, but I think I know what is happening anyway. The ComponentWorks VISA control call to EnableEvent does not work with NI-VISA >= 3.0. There was a change in the event architecture in NI-VISA 3.0 that seemed to be compatible with all clients and customers. In about a year since it's been released, it turns out that ComponentWorks has been the only exception. Sorry about that.

The ComponentWorks control has not been modified since NI-VISA 3.0, nor will it be revved again. This leaves you with a few options:
1) Downgrade to NI-VISA 2.6.1 (which predated the event rearchitecture)
2) Upgrade to Measurement Studio 7.0 for .NET (with a .NET native API that
is tested with NI-VISA >= 3.0)
3) Do not use any VISA events

I don't think there's much more I can offer technically on this topic, so if you need additional assistance, please contact NI technical support. I hope this helps, at least from a standpoint of knowing what's happening and what your options are.

Dan Mondrik
National Instruments
0 Kudos
Message 4 of 5
(6,570 Views)
Markus,

I am curious why you are using the Measurement Studio 6 ActiveX control with .NET? NI now offers Measurement Studio 7 with has a native .NET API for VISA. This also includes an Instrument I/O Assistant to parse returned data and automatically generate perfect VB.NET code for you. Please respond if you'd like additional information on how to use VISA with .NET. Also, check out www.ni.com/mstudio. Keep me posted
0 Kudos
Message 5 of 5
(6,570 Views)