简体   繁体   English

通过Excel VBA通​​过GPIB发送命令

[英]Sending commands through GPIB via Excel VBA

I have this network analyzer and need to send commands to it via Excel VBA and GPIB. 我有这个网络分析仪,需要通过Excel VBA和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. 我已经将GPIB和其他硬件设置得很好,但是我不知道如何简单地通过GPIB将命令发送到分析仪。 I have considerable programming experience but I am brand new to VBA. 我有丰富的编程经验,但是我是VBA的新手。 After hours searching through hardware documentation and VBA tutorials my spirit is slowly dying. 在经过数小时的硬件文档和VBA教程搜索之后,我的精神逐渐消亡。 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. 我相信我需要在VBA中添加正确的引用(工具->引用),但是当我尝试运行文档给出的示例代码(“调用viOpenDefaultRM(defrm)”)时,出现错误,未定义Sub或函数。

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). 好像您正在使用VISA库(在打开GPIB资源时将委派给GPIB库)。 So, you should have a VISA32.bas from your VISA vendor that you can at least copy portions of into your VBA project. 因此,您应该从VISA供应商处获得一个VISA32.bas,您至少可以将其中的一部分复制到VBA项目中。

Or use VISA-COM if your VISA vendor provides it and use Tools -> References for it. 或者,如果您的VISA供应商提供了VISA-COM,并使用工具->引用,则使用VISA-COM。

To reference functions in an external DLL, you need to Declare them in a module in the Excel file. 要在外部DLL中引用函数,您需要在Excel文件的模块中Declare它们。 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: 在您的特定情况下, Declare可能看起来像:

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 . 您需要在%PATH%系统变量中包含库文件“ gpib_functions.dll”的路径,或者在Declare明确列出完整路径。

See ' Calling DLL Functions and Commands from VBA ' for more info. 有关更多信息,请参见“ 从VBA调用DLL函数和命令 ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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