Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

EXCEl VBA USB and LAN

Hello,

I have been using EXCEL VBA to communicate and collect data from my test instruments using EXCEl VBA macros on GPIB bus. I have two modules from NI installed in my Excel VBA ( NI-488 DLL entry function declarations and This module contains the variable declarations,
' constant definitions, and type information that
' is recognized by the entire application.). This is working fine.

Now I am connecting many of my new instruments by LAN and USB. I want  to use excel VBA to talk to these instruments on LAN and  USB and collect data. Please help me on this. Is there any  excel vba modules I can download (Similar to GPIB modules I mentioned earlier) from NI  fo this LAN and USB communication?

Appreciate your help.

Thanks,

Leyo Joseph

0 Kudos
Message 1 of 11
(19,940 Views)

Hi Leyo,

 

If you want to try to connect to instruments over USB and LAN, you will need to use the VISA driver. You can find out how to connect to USB using the VISA driver here, and how to connect over LAN here. It should be roughly the same as with GPIB, but you're just leveraging a different driver than the NI-488.2 driver.

Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 11
(19,925 Views)

Thanks...I could make it work with the links you have given. The below code works good for a Keysight N1912A  connected on the USB bus.

Sub again()

Dim ioMgr As VisaComLib.ResourceManager
Dim Equip As VisaComLib.FormattedIO488
Set ioMgr = New VisaComLib.ResourceManager
Set Equip = New VisaComLib.FormattedIO488

Set Equip.IO = ioMgr.Open("USB0::0x0957::0x1302::MY50000834::INSTR")


Equip.WriteString "*RST"

End Sub

I have a Rhode%Schwarz Power meter connected to USB. NI-MAX shows its RSNRP::0x0023::101926::INSTR

When I change the above code to use this vias resource(Set Equip.IO = ioMgr.Open("RSNRP::0x0023::101926::INSTR"), not working (Run time error -2147221164). Please help me figure this out.

This power meter is shwon under "Miscellaneous Visa Reource " in NI_MAX. I am able to communicate with this usining Open VISA Test Panel.

Thanks,

Leyo Joseph

 

0 Kudos
Message 3 of 11
(19,919 Views)

Hello,

AFter discussing with R&S, tried following and getting same error.

Set Equip.IO = ioMgr.Open("USB0::0x0aad::0x0023::101926::INSTR")

Set Equip.IO = ioMgr.Open("USB0::0x0aad::0x0023::101926")

As shown in the attached file, NI-MAX window shows lots of red items. Not sure why??

0 Kudos
Message 4 of 11
(19,893 Views)

Hi Leyo, one reason those errors might be showing up is that while trying to retrieve those attributes, the request times out. However, I think it's more likely that the hardware simply does not support those attributes in general. For example, it makes sense the GPIB Primary Address is invalid because it is not connected to GPIB.

 

In regard to the error you have been receiving, have you made the USB power meter into a VISA device through this process? Or does it show up in MAX on its own? I might try using an alias for the device which you can set in MAX under the General tab for the device.

Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 5 of 11
(19,877 Views)

Thanks. I tried the visa driver wizard as you mentioned. I could see my power sensor with USB manufactureID (0X0AAD) and USB model code(0X0023). Manufacturer name  Rhode & Schwarz and Model name NRP-Z81. Getting the below error message==>

 

The following errors were found when testing the devices compatibility with VIsa. [Device Id:USB\VID_aad&PID_23] Error-1073807178; Device descriptor error- incompatible bcdUSB value (expected 0X110 or greater).

0 Kudos
Message 6 of 11
(19,868 Views)

That error occurs when the USB version of the device is USB 1.0, which is not compatible with drivers made through the VISA driver wizard. Assuming that it is an USB Test & Measurement Class device because it's still showing up in MAX without a driver being created, I have to ask if you can run any kind of example for the device in LabVIEW or LabWindows/CVI. Can you make the device do what you're wanting in a program that isn't written in Visual Basic?

 

Also have you installed the toolkit for this specific power sensor from R&S?

Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 11
(19,853 Views)

Thanks..

With Matlab, I am able to communicate as shwon below==>

vu = visa('ni','RSNRP::0x0023::101926::INSTR');
fopen (vu);

 

This power head appears as RSNRP::0x0023::101926::INSTR in NI-MAX.  I added an alias "PM1" and the following Matlab code works well.

vu=visa('ni','PM1')

fopen(vu).

 

But with Excel VBA, always getting the  below error==>

Run-Time error 2147221487(80040011) HRESULT = 80040011. 

ANy ideas??

0 Kudos
Message 8 of 11
(19,846 Views)

I don't have any ideas about why communication will work with a device in one language and not another - especially because that language works fine with other devices. It seems to be just an incompatibility between VB and the PM. I haven't been able to track down any reason that this might be - Excel VBA is not a common enough tool for this to have been seen before. I would confirm driver versions to ensure it supports this device.

 

Can you tell me if you are trying to set Equip.IO for both instruments or are these two seperate programs?

Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 9 of 11
(19,829 Views)

Good mroning,

I am able to communicate other instruments on USB with excel vba. Only this NRP series power heads giving problems. Please have a look at the below link. Somebody else also have the same issue and he concluded that the driver for NRP power heads doesn't support visa.comm

http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/NRP-NI-VISA-passport-NI-MAX-vs-VISA-C-vs-VISA...

Please give your comments.

 

0 Kudos
Message 10 of 11
(19,818 Views)