|
通常在需要大量的連續(xù)試驗(yàn)數(shù)據(jù)采集時(shí),需要使用自動(dòng)化的可編程萬用表。其中HP/Agilent/Fluke/Keithley等多個(gè)廠家的儀表都支持用戶編程,并且支持 IEEE802.2 SCPI(標(biāo)準(zhǔn)儀器編程接口)命令編程。其中可用的接口可能是 GPIB/HPIB, 標(biāo)準(zhǔn)RS-232串口(含TTL規(guī)格接口),USB,PXI等,支持在多種開發(fā)環(huán)境下使用,支持多個(gè)儀器類型。這里以 Agilent 34405A 5 1/2 位數(shù)字萬用表為例做一介紹。如果將其編程接口形式改編,可以用于如HP34401/34410A等儀表中,實(shí)現(xiàn)同樣的目的。
'*****************************************************************************************************************
'
' Agilent 34405A 5 1/2位數(shù)字萬用表演示程序 for Excel
'
' 本程序由 Agilent 提供的例程改編。
'
' 應(yīng)用前提:
' 1. 在系統(tǒng)中已經(jīng)安裝了 IVISharedComponets 2.3.0 版(根據(jù)操作系統(tǒng)的差異,選擇32位或64位均可)。
' 2. 系統(tǒng)中已安裝 driver_ivi_matlab_Agilent_34405_1_1_1_0(34405A的驅(qū)動(dòng)程序,32位或64位,根據(jù)系統(tǒng)確定)。
' 3. IOLibSuite_17_1_20011, 基本操作庫。這些資料需要下載的話,需要在 www點(diǎn)agilent點(diǎn)com/find/34405a 頁面下載(驅(qū)動(dòng)),可能需要注冊。
' 4. 驗(yàn)證系統(tǒng)是否可用的前提是在設(shè)備管理器中可以看到 "USB Test and Measument Devices" --> "USB Test and Measurement Device (IVI)"
' 5. 在設(shè)備管理器中選中該設(shè)備,點(diǎn)擊右鍵,選擇屬性,選擇"詳細(xì)信息"-->"設(shè)備范例ID",可以得到"USB\VID_0957&PID_0618\TW48070141"的字符,記錄備用。
'
' Excel中應(yīng)用:
' 1. 在要記錄數(shù)據(jù)的Excel文檔中,創(chuàng)建新的宏模塊。
' 2. 點(diǎn)擊VB編輯器的"工具"-->"引用", 打開該文檔的工程引用窗口。
' 3. 在可引用的引用列表中,選擇"IVI Agilent34405 1.1 Type Library" 和 "IviDriver 1.0 Type Library",確定后關(guān)閉引用對話框。
' 4. 在要做測試的用戶模塊開頭,定義全局的 DMM 引用變量。 如"Dim myDmm as New Agilent34405" 為后續(xù)程序使用。
' 5. 使用前面在設(shè)備管理其中獲得的設(shè)備范例ID,作為要打開的設(shè)備名稱,操作設(shè)備。
' 6. 設(shè)備使用 Initialize 命令打開。使用結(jié)束后,使用Close命令關(guān)閉。
' 7. 設(shè)備Initialize 以后,設(shè)備面板上就會(huì)出現(xiàn)"Remote"的顯示,表示設(shè)備已經(jīng)處于遙控模式。
' 8. 使用 34405A 面板上的 Local 按鍵可以使設(shè)備脫落Remote模式,接收面板控制。
' 9. 這些設(shè)備可以直接使用類型庫的內(nèi)置函數(shù)操作,也可以通過 Agilent/HP 的 SCPI 腳本命令操作。兩者的功能相同。
'******************************************************************************************************************
'以下程序示例了設(shè)備的打開和具體功能測試。 使用的是 34405A的內(nèi)置類型庫進(jìn)行操作。
Sub TestAgilent34405()
'DMM 對象
Dim myDmm As New Agilent34405
Dim resourceDesc As String
Dim initOptions As String
Dim idquery As Boolean
Dim reset As Boolean
'中間過程變量
Dim msgStr As String
Dim errorCode As Long
Dim errorMsg As String
Dim myStr As String
Dim data As Double
'數(shù)據(jù)保存變量
Dim tstSht As Worksheet
Dim curRow As Integer
On Error GoTo ErrHandler
errorCode = -1
'*****************************************************************************************
'每次運(yùn)行時(shí),刪除已有的同名的數(shù)據(jù)表,然后再重新創(chuàng)建一個(gè)新的記錄表
'******************************************************************************************
For Each tstSht In ActiveWorkbook.Sheets
If tstSht.Name = "DMM_Agilent_34405A 操作演示" Then
tstSht.Delete
Exit For
End If
Next
Set tstSht = ActiveWorkbook.Sheets.Add
tstSht.Name = "DMM_Agilent_34405A 操作演示"
'*****************************************************************************************
'以下為測試過程的內(nèi)容
'*****************************************************************************************
tstSht.Cells(1, 1) = "Agilent 34405A 自動(dòng)操作演示程序 V1.0"
tstSht.Cells(2, 1) = "記錄時(shí)間:" & Format(Now(), "YYYY-mm-dd HH:MM:ss")
tstSht.Cells(4, 1) = "1. 設(shè)備信息查詢"
'設(shè)備初始化
ressourceDesc = "USB0::0x0957::0x0618::TW48070141::0::INSTR"
'ressourceDesc = "USB0::<manufacturer_ID>::<model_code>::<serial_number>::0::INSTR"
'此初始化過程對執(zhí)行結(jié)果進(jìn)行保存。 注意, Simulate 必須設(shè)置為 false, 否則會(huì)虛假運(yùn)行。
initOptions = "QueryInstrStatus=true, Simulate=false, DriverSetup= Model=, Trace=true, TraceName=c:\\temp\\traceOut"
idquery = True '查詢設(shè)備ID
reset = True '設(shè)備初始化
myDmm.Initialize ressourceDesc, idquery, reset, initOptions '儀器初始化
tstSht.Cells(5, 1) = "設(shè)備驅(qū)動(dòng)初始化正常。"
tstSht.Cells(6, 1) = "標(biāo)識符: "
tstSht.Cells(6, 2) = myDmm.Identity.Identifier
tstSht.Cells(7, 1) = "版本: "
tstSht.Cells(7, 2) = myDmm.Identity.Revision
tstSht.Cells(8, 1) = "制造商: "
tstSht.Cells(8, 2) = myDmm.Identity.Vendor
tstSht.Cells(9, 1) = "設(shè)備描述: "
tstSht.Cells(9, 2) = myDmm.Identity.Description
tstSht.Cells(10, 1) = "型號: "
tstSht.Cells(10, 2) = myDmm.Identity.InstrumentModel
tstSht.Cells(11, 1) = "固件版本:"
tstSht.Cells(11, 2) = myDmm.Identity.InstrumentFirmwareRevision
tstSht.Cells(12, 1) = "序列號#: "
tstSht.Cells(12, 2) = myDmm.System.SerialNumber
tstSht.Cells(13, 1) = "模擬支持:"
tstSht.Cells(13, 2) = myDmm.DriverOperation.Simulate
tstSht.Cells(14, 1) = "SCPI 版本:"
tstSht.Cells(14, 2) = myDmm.System.SCPIVersion
tstSht.Cells(15, 1) = "蜂鳴器狀態(tài):"
tstSht.Cells(15, 2) = myDmm.System.BeeperState
tstSht.Cells(16, 1) = "儀器當(dāng)前狀態(tài):"
tstSht.Cells(16, 2) = myDmm.DriverOperation.QueryInstrumentStatus
'*************************************************************************************************************************************************
'使用 SCPI 命令操作設(shè)備:通過 System2.WriteString 和 System2.ReadString 實(shí)現(xiàn) SCPI命令的輸出和結(jié)果輸出。
' 具體的 SCPI 操作命令請參考 Agilent 34405A 操作手冊。
'**************************************************************************************************************************************************
tstSht.Cells(17, 1) = "2. SCPI 命令的支持"
tstSht.Cells(18, 1) = "*IDN?"
myDmm.System2.WriteString "*IDN?" '& vbCrLf
'myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(18, 2) = myDmm.System2.ReadString()
tstSht.Cells(19, 1) = "SYST:ERR?"
myDmm.System2.WriteString "SYSTem:Err?" ' & vbCrLf
'myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(19, 2) = myDmm.System2.ReadString()
'**************************************************************************************************************
'以下通過內(nèi)置命令操作設(shè)備,將設(shè)備的全部功能都循環(huán)使用一次。
'**************************************************************************************************************
tstSht.Cells(22, 1) = "3. 常用操作命令演示"
myDmm.System.TimeoutMilliseconds = 15000 '系統(tǒng)響應(yīng)超時(shí)時(shí)間定義為 15s。
'DMM 復(fù)位
myDmm.Utility.reset
curRow = 22
curRow = curRow + 1
'設(shè)置 DMM 為即時(shí)觸發(fā)模式
myDmm.Trigger.TriggerSource = Agilent34405TriggerSourceEnum.Agilent34405TriggerSourceImmediate
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'---直流電壓測量 ----
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'量程 10V, 快速測量模式(較低分辨率)
myDmm.Voltage.DCVoltage.Configure 10, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast
'Display the Raw DC Volts Measurement
'MsgBox "Raw DC Volts measurement: " & Format(data, "0.000") & " Volts"
tstSht.Cells(curRow, 1) = "3.1 直流電壓測量,10V擋,快速測量,原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Voltage.DCVoltage.Configure 10, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "V"
curRow = curRow + 1
'Use the measurement as the NULL value
myDmm.Math.NullValue = data
myDmm.Math.Enable = True
tstSht.Cells(curRow, 1) = "3.2 直流電壓測量,10V擋,使用Offset校準(zhǔn)"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "V"
curRow = curRow + 1
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
' 交流電壓測量
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'10V AC,低分辨率快速測試
myDmm.Voltage.ACVoltage.Configure 10, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast
tstSht.Cells(curRow, 1) = "3.3 交流電壓測量,10V擋,低分辨率,快速原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Voltage.ACVoltage.Configure 10, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "V"
curRow = curRow + 1
'Use the measurement as the NULL value
myDmm.Math.NullValue = data
myDmm.Math.Enable = True
tstSht.Cells(curRow, 1) = "3.4 交流電壓測量,10V擋,使用Offset校準(zhǔn)"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "V"
curRow = curRow + 1
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'直流電流測量
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'100mA擋,低分辨率,快速模式
myDmm.Current.DCCurrent.Configure 0.1, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast
tstSht.Cells(curRow, 1) = "3.5 直流電流測量,100mA擋,快速原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Current.DCCurrent.Configure 0.1, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read() * 1000
tstSht.Cells(curRow, 4) = "mA"
curRow = curRow + 1
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'交流電量測量
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'100mA擋,低分辨率快速方式
myDmm.Current.ACCurrent.Configure 0.1, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast
tstSht.Cells(curRow, 1) = "3.6 交流電流測量,100mA擋,快速原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Current.ACCurrent.Configure 0.1, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read() * 1000
tstSht.Cells(curRow, 4) = "mA"
curRow = curRow + 1
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'頻率測量
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
myDmm.Frequency.Configure 100, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast
myDmm.Frequency.VoltageRange = 10
tstSht.Cells(curRow, 1) = "3.7 頻率測量,100Hz,10V 擋,快速原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Frequency.Configure 100, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast" & vbCrLf & "myDmm.Frequency.VoltageRange = 10"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "Hz"
curRow = curRow + 1
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'電阻測量
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'10k ohm 快速測量
myDmm.Resistance.Configure 10000#, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast
tstSht.Cells(curRow, 1) = "3.8 電阻測量(2線法),10K擋,快速原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Resistance.Configure 10000#, Agilent34405ResolutionEnum.Agilent34405ResolutionLeast"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "Ohms"
curRow = curRow + 1
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'溫度測量
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'配置為 5k Ohms 量程
myDmm.Temperature.Thermistor.Configure Agilent34405ThermistorTypeEnum.Agilent34405ThermistorType5000, Agilent34405ResolutionEnum.Agilent34405ResolutionBest
tstSht.Cells(curRow, 1) = "3.9 溫度測量,5K Ohm擋,快速原始數(shù)據(jù)"
tstSht.Cells(curRow, 2) = "myDmm.Temperature.Thermistor.Configure Agilent34405ThermistorTypeEnum.Agilent34405ThermistorType5000," & vbCrLf & " Agilent34405ResolutionEnum.Agilent34405ResolutionBest"
myDmm.System2.WaitForOperationComplete 1000
tstSht.Cells(curRow, 3) = myDmm.Measurement.Read()
tstSht.Cells(curRow, 4) = "degrees C"
curRow = curRow + 2
'********************************************************************************************
'主程序完成,以下是補(bǔ)充部分。
'錯(cuò)誤檢測.
'********************************************************************************************
tstSht.Cells(curRow, 1) = "4 系統(tǒng)錯(cuò)誤檢查"
curRow = curRow + 1
errorCode = -1
Do
myDmm.Utility.ErrorQuery errorCode, errorMsg
tstSht.Cells(curRow, 1) = "錯(cuò)誤編號:" & errorCode
tstSht.Cells(curRow, 2) = errorMsg
curRow = curRow + 1
Loop While errorCode <> 0
'系統(tǒng)恢復(fù)并關(guān)閉測試程序
myDmm.System2.WriteString "*RST" '系統(tǒng)復(fù)位
myDmm.Close
curRow = curRow + 3
tstSht.Cells(curRow, 1) = "測試完成,數(shù)據(jù)關(guān)閉。 時(shí)間:"
tstSht.Cells(curRow, 2) = Format(Now(), "YYYY-mm-DD HH:MM:SS")
'***********************************************************************************************
'************************************表格格式化部分略去**********************************
'***********************************************************************************************
tstSht.Application.ActiveWorkbook.Save '保存測量的結(jié)果數(shù)據(jù)文件。
MsgBox "測試完成。。"
Exit Sub
'下面是出錯(cuò)處理過程。比較簡單,未做詳細(xì)處理。
ErrHandler:
MsgBox "測試過程出錯(cuò)。錯(cuò)誤信息為:" & Err.Description
End Sub
實(shí)際運(yùn)行的結(jié)果如下(數(shù)據(jù)表格的格式化):

這樣基本上實(shí)現(xiàn)了自動(dòng)控制萬用表進(jìn)行數(shù)據(jù)獲取的目的。在需要自動(dòng)連續(xù)讀數(shù)的場所,可以大大降低對測試人員的需求。
|
|