通过 VISA 的接口(GPIB / TCP)向某器材/设备发送命令/请求。
#include <Visa.au3>
_viExecCommand($h_session, $s_command, $i_timeout_ms = -1)
参数
| $h_session | VISA 描述符(字符串)或者 VISA session 句柄(整数)。
这个参数既可以是字符串也可以是个整数(句柄): * 字符串 -> VISA 描述符就是一个字符串,用以指定要建立通讯段的资源。 例如: "GPIB::20::0"。 本函数支持所有合法的 VISA 描述符,包括 GPIB, TCP, VXI 和串口设备(ASRL)。 关于 VISA 描述符,在下面的注意部分有详细的解释。 作为更快捷的方式,您可以使用一个包含 GPIB 设备的地址数字的字符串(比如"20") 来代替完整描述符(比如"GPIB::20::0")。 * 整数 -> VISA session 句柄,由 _viOpen 函数返回。 如果您打算经常性地和某个设备或装置通信,我们推荐您使用 _viOpen 和 VISA session 句柄 来代替描述符,否则每次要和设备联系都必须打开然后关闭通讯连接。 在完成了所有操作后切记要使用 _viClose 来关闭连接。 |
| $s_command | 要执行的命令/请求(例如,"*IDN?" 或 "SOURCE:POWER -20 dBM") 请求必须含有问号(?) 如果是请求则本函数将自动等待设备响应结果(或者等到操作超时为止)。 |
| $i_timeout_ms | 可选:以毫秒为单位的 VISA 操作超时时间。 |
返回值
具体的返回值取决于命令是否请求以及操作是否成功。
注意
* The VISA queries only return the 1st line of the device answer
相关
_viFindGpib, _viOpen, _viClose, _viSetTimeout, _viGTL, _viGpibBusReset
示例
;- 这个脚本假定您已经把 GPIB 的地址设为 1
; 本脚本演示了如何单独使用 _viExecCommand 函数以及结合
; _viOpen 和 _viClose 函数使用的方法。
; 另外还演示了 _viGTL 函数
#include <Visa.au3>
Dim $h_session = 0
; 请求设备的 GPIB 地址3 的 ID
MsgBox(0,"Step 1","Open the instrument connection with _viOpen")
Dim $h_instr = _viOpen("GPIB::3::0")
MsgBox(0,"Instrument Handle obtained", "$h_instr = " & $h_instr) ; 显示 Session 句柄
; 请求设备响应
MsgBox(0,"Step 2","Query the instrument using the VISA instrument handle")
$s_answer = _viExecCommand($h_instr,"*IDN?") ; 注意,$h_instr 现在已不再是字符串了!
MsgBox(0,"GPIB QUERY result",$s_answer) ; 显示结果
; 再次请求。这时不需要再次打开连接了
MsgBox(0,"Step 3","Query again. There is no need to OPEN the link again")
$s_answer = _viExecCommand($h_instr,"*IDN?")
MsgBox(0,"GPIB QUERY result",$s_answer) ; 显示结果
MsgBox(0,"Step 4","Close the instrument connection using _viClose")
_viClose($h_instr) ; 关闭设备连接
MsgBox(0,"Step 5","Open the Instrument connection using only the address number")
Dim $h_instr = _viOpen(3)
MsgBox(0,"Instrument Handle obtained", "$h_instr = " & $h_instr) ; 显示 Session 句柄
; 请求设备响应
MsgBox(0,"Step 6","Query the instrument using the VISA instrument handle")
$s_answer = _viExecCommand($h_instr,"*IDN?") ; 注意,$h_instr 现在已不再是字符串了!
MsgBox(0,"GPIB QUERY result",$s_answer) ; 显示结果
; 再次请求。这时不需要再次打开连接了
MsgBox(0,"Step 7","Query again. There is no need to OPEN the link again")
$s_answer = _viExecCommand($h_instr,"*IDN?")
MsgBox(0,"GPIB QUERY result",$s_answer) ; 显示结果
MsgBox(0,"Step 8","Close the instrument connection using _viClose")
_viClose($h_instr) ; 关闭设备连接