基于指針式電測(cè)儀表自動(dòng)化檢定系統(tǒng)設(shè)計(jì)
3.2 GPIB編程技術(shù)
數(shù)據(jù)通信是通過(guò)AX4810P型GPIB 接口卡進(jìn)行的,在通訊時(shí),這需要調(diào)用AX4810P.DLL 動(dòng)態(tài)鏈接庫(kù)中已聲明的功能函數(shù)。通訊前首先要對(duì)通訊接口初始化來(lái)打開(kāi)儀器、設(shè)置參數(shù),調(diào)用ibdev函數(shù)。
(1)發(fā)送命令子程序
通過(guò)GPIB函數(shù)ibwrt將命令發(fā)送給Fluke5520A。其中參數(shù)dmm為通訊初始化時(shí)返回值,MeasureCmd為軟件設(shè)定Fluke5520A需產(chǎn)生的信號(hào)值。
Public Sub SendToDevice (MeasureCmd As String)
Dim cmdstr As String
‘向Fluke5520A發(fā)送需要輸出的信號(hào)值
cmdstr = "OUT " MeasureCmd + "; *WAI"
ret = ibwrt(dmm, cmdstr, Len(cmdstr))
‘使Fluke5520A執(zhí)行命令
cmdstr = "OPER; *WAI"
ret = ibwrt(dmm, cmdstr, Len(cmdstr))
End Sub
(2)接收數(shù)據(jù)子程序
Fluke5520A向PC機(jī)返回的測(cè)量值存放在reading變量中,在調(diào)用此過(guò)程時(shí)所需要傳遞的參數(shù)count為PC機(jī)要從GPIB讀取數(shù)值的字節(jié)數(shù)。
Public Sub ReadFromDevice(count As Integer)
‘向儀器發(fā)送輸出數(shù)據(jù)命令
cmdstr = "OUT?"
ret = ibwrt(dmm, cmdstr, Len(cmdstr))
‘延遲10s
delay 1000
‘讀取數(shù)據(jù)
ret = ibrd(dmm, reading, count)
‘延遲20s
delay 2000
End Sub
評(píng)論