简体   繁体   中英

Sending commands through GPIB via Excel VBA

I have this network analyzer and need to send commands to it via Excel VBA and GPIB. I have the GPIB and other hardware set up just fine, but I do not know how to simply send commands through the GPIB to the analyzer. I have considerable programming experience but I am brand new to VBA. After hours searching through hardware documentation and VBA tutorials my spirit is slowly dying. I believe I need to add the correct References in VBA (Tools -> References) but when I try to run sample code given by the documentation ("Call viOpenDefaultRM(defrm)") I get an error that the Sub or function is not defined.

Any help is very much appreciated. I am working as an engineer and somehow get thrown into tasks that require lots of coding.

It looks like you are using a VISA library (which would delegate to a GPIB library when you open a GPIB resource). So, you should have a VISA32.bas from your VISA vendor that you can at least copy portions of into your VBA project.

Or use VISA-COM if your VISA vendor provides it and use Tools -> References for it.

To reference functions in an external DLL, you need to Declare them in a module in the Excel file. The declaration identifies the path to the external library, the entry point, the external function's parameters and return value types.

In your specific case, the Declare might look something like:

Public Declare Sub viOpenDefaultRM Lib "gpib_functions.dll" (defrm as String)

You'd need to include the path to the library file "gpib_functions.dll" in your %PATH% system variable, or else explicitly list the full path in the Declare .

See ' Calling DLL Functions and Commands from VBA ' for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM