通過(guò) VISA 的接口(GPIB / TCP)向某器材/設(shè)備發(fā)送命令/請(qǐng)求。
#include <Visa.au3>
_viExecCommand($h_session, $s_command, $i_timeout_ms = -1)
參數(shù)
$h_session | VISA 描述符(字符串)或者 VISA session 句柄(整數(shù))。
這個(gè)參數(shù)既可以是字符串也可以是個(gè)整數(shù)(句柄): * 字符串 -> VISA 描述符就是一個(gè)字符串,用以指定要建立通訊段的資源。 例如: "GPIB::20::0"。 本函數(shù)支持所有合法的 VISA 描述符,包括 GPIB, TCP, VXI 和串口設(shè)備(ASRL)。 關(guān)于 VISA 描述符,在下面的注意部分有詳細(xì)的解釋。 作為更快捷的方式,您可以使用一個(gè)包含 GPIB 設(shè)備的地址數(shù)字的字符串(比如"20") 來(lái)代替完整描述符(比如"GPIB::20::0")。 * 整數(shù) -> VISA session 句柄,由 _viOpen 函數(shù)返回。 如果您打算經(jīng)常性地和某個(gè)設(shè)備或裝置通信,我們推薦您使用 _viOpen 和 VISA session 句柄 來(lái)代替描述符,否則每次要和設(shè)備聯(lián)系都必須打開(kāi)然后關(guān)閉通訊連接。 在完成了所有操作后切記要使用 _viClose 來(lái)關(guān)閉連接。 |
$s_command | 要執(zhí)行的命令/請(qǐng)求(例如,"*IDN?" 或 "SOURCE:POWER -20 dBM") 請(qǐng)求必須含有問(wèn)號(hào)(?) 如果是請(qǐng)求則本函數(shù)將自動(dòng)等待設(shè)備響應(yīng)結(jié)果(或者等到操作超時(shí)為止)。 |
$i_timeout_ms | 可選:以毫秒為單位的 VISA 操作超時(shí)時(shí)間。 |
返回值
具體的返回值取決于命令是否請(qǐng)求以及操作是否成功。
注意
* The VISA queries only return the 1st line of the device answer
相關(guān)
_viFindGpib, _viOpen, _viClose, _viSetTimeout, _viGTL, _viGpibBusReset
示例
;- 這個(gè)腳本假定您已經(jīng)把 GPIB 的地址設(shè)為 1
; 本腳本演示了如何單獨(dú)使用 _viExecCommand 函數(shù)以及結(jié)合
; _viOpen 和 _viClose 函數(shù)使用的方法。
; 另外還演示了 _viGTL 函數(shù)
#include <Visa.au3>
Dim $h_session = 0
; 請(qǐng)求設(shè)備的 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 句柄
; 請(qǐng)求設(shè)備響應(yīng)
MsgBox(0,"Step 2","Query the instrument using the VISA instrument handle")
$s_answer = _viExecCommand($h_instr,"*IDN?") ; 注意,$h_instr 現(xiàn)在已不再是字符串了!
MsgBox(0,"GPIB QUERY result",$s_answer) ; 顯示結(jié)果
; 再次請(qǐng)求。這時(shí)不需要再次打開(kāi)連接了
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) ; 顯示結(jié)果
MsgBox(0,"Step 4","Close the instrument connection using _viClose")
_viClose($h_instr) ; 關(guān)閉設(shè)備連接
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 句柄
; 請(qǐng)求設(shè)備響應(yīng)
MsgBox(0,"Step 6","Query the instrument using the VISA instrument handle")
$s_answer = _viExecCommand($h_instr,"*IDN?") ; 注意,$h_instr 現(xiàn)在已不再是字符串了!
MsgBox(0,"GPIB QUERY result",$s_answer) ; 顯示結(jié)果
; 再次請(qǐng)求。這時(shí)不需要再次打開(kāi)連接了
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) ; 顯示結(jié)果
MsgBox(0,"Step 8","Close the instrument connection using _viClose")
_viClose($h_instr) ; 關(guān)閉設(shè)備連接