久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 14278|回復: 1
打印 上一主題 下一主題
收起左側

Agilent 34405A 數字萬用表的自動數據采集(Excel 2007)

[復制鏈接]
跳轉到指定樓層
樓主
ID:91442 發表于 2015-10-29 12:58 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
通常在需要大量的連續試驗數據采集時,需要使用自動化的可編程萬用表。其中HP/Agilent/Fluke/Keithley等多個廠家的儀表都支持用戶編程,并且支持 IEEE802.2 SCPI(標準儀器編程接口)命令編程。其中可用的接口可能是 GPIB/HPIB, 標準RS-232串口(含TTL規格接口),USB,PXI等,支持在多種開發環境下使用,支持多個儀器類型。這里以 Agilent 34405A 5 1/2 位數字萬用表為例做一介紹。如果將其編程接口形式改編,可以用于如HP34401/34410A等儀表中,實現同樣的目的。

'*****************************************************************************************************************
'
' Agilent 34405A 5 1/2位數字萬用表演示程序 for Excel
'
' 本程序由 Agilent 提供的例程改編。
'
' 應用前提:
' 1. 在系統中已經安裝了 IVISharedComponets 2.3.0 版(根據操作系統的差異,選擇32位或64位均可)。
' 2. 系統中已安裝 driver_ivi_matlab_Agilent_34405_1_1_1_0(34405A的驅動程序,32位或64位,根據系統確定)。
' 3. IOLibSuite_17_1_20011, 基本操作庫。這些資料需要下載的話,需要在 wwwagilentcom/find/34405a 頁面下載(驅動),可能需要注冊。
' 4. 驗證系統是否可用的前提是在設備管理器中可以看到 "USB Test and Measument Devices" --> "USB Test and Measurement Device (IVI)"
' 5. 在設備管理器中選中該設備,點擊右鍵,選擇屬性,選擇"詳細信息"-->"設備范例ID",可以得到"USB\VID_0957&PID_0618\TW48070141"的字符,記錄備用。
'
' Excel中應用:
' 1. 在要記錄數據的Excel文檔中,創建新的宏模塊。
' 2. 點擊VB編輯器的"工具"-->"引用", 打開該文檔的工程引用窗口。
' 3. 在可引用的引用列表中,選擇"IVI Agilent34405 1.1 Type Library" 和 "IviDriver 1.0 Type Library",確定后關閉引用對話框。

' 4. 在要做測試的用戶模塊開頭,定義全局的 DMM 引用變量。 如"Dim myDmm as New Agilent34405" 為后續程序使用。
' 5. 使用前面在設備管理其中獲得的設備范例ID,作為要打開的設備名稱,操作設備。
' 6. 設備使用 Initialize 命令打開。使用結束后,使用Close命令關閉。
' 7. 設備Initialize 以后,設備面板上就會出現"Remote"的顯示,表示設備已經處于遙控模式。
' 8. 使用 34405A 面板上的 Local 按鍵可以使設備脫落Remote模式,接收面板控制。
' 9. 這些設備可以直接使用類型庫的內置函數操作,也可以通過 Agilent/HP 的 SCPI 腳本命令操作。兩者的功能相同。
'******************************************************************************************************************

'以下程序示例了設備的打開和具體功能測試。 使用的是 34405A的內置類型庫進行操作。

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
'數據保存變量
Dim tstSht As Worksheet
Dim curRow As Integer

On Error GoTo ErrHandler
errorCode = -1

'*****************************************************************************************
'每次運行時,刪除已有的同名的數據表,然后再重新創建一個新的記錄表
'******************************************************************************************

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 操作演示"
'*****************************************************************************************
'以下為測試過程的內容
'*****************************************************************************************

tstSht.Cells(1, 1) = "Agilent 34405A 自動操作演示程序 V1.0"
tstSht.Cells(2, 1) = "記錄時間:" & Format(Now(), "YYYY-mm-dd HH:MM:ss")

tstSht.Cells(4, 1) = "1. 設備信息查詢"

'設備初始化
ressourceDesc = "USB0::0x0957::0x0618::TW48070141::0::INSTR"
'ressourceDesc = "USB0::<manufacturer_ID>::<model_code>::<serial_number>::0::INSTR"

'此初始化過程對執行結果進行保存。 注意, Simulate 必須設置為 false, 否則會虛假運行。
initOptions = "QueryInstrStatus=true, Simulate=false, DriverSetup= Model=, Trace=true, TraceName=c:\\temp\\traceOut"

idquery = True  '查詢設備ID
reset = True    '設備初始化

myDmm.Initialize ressourceDesc, idquery, reset, initOptions         '儀器初始化

tstSht.Cells(5, 1) = "設備驅動初始化正常。"
tstSht.Cells(6, 1) = "標識符:  "
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) = "設備描述: "
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) = "蜂鳴器狀態:"
tstSht.Cells(15, 2) = myDmm.System.BeeperState
tstSht.Cells(16, 1) = "儀器當前狀態:"
tstSht.Cells(16, 2) = myDmm.DriverOperation.QueryInstrumentStatus

'*************************************************************************************************************************************************
'使用 SCPI 命令操作設備:通過 System2.WriteString 和 System2.ReadString 實現 SCPI命令的輸出和結果輸出。

' 具體的 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()

'**************************************************************************************************************

'以下通過內置命令操作設備,將設備的全部功能都循環使用一次。
'**************************************************************************************************************
tstSht.Cells(22, 1) = "3. 常用操作命令演示"

myDmm.System.TimeoutMilliseconds = 15000  '系統響應超時時間定義為 15s。

'DMM 復位
myDmm.Utility.reset

curRow = 22
curRow = curRow + 1

'設置 DMM 為即時觸發模式
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擋,快速測量,原始數據"
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校準"
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擋,低分辨率,快速原始數據"
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校準"
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擋,快速原始數據"
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擋,快速原始數據"
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 擋,快速原始數據"
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擋,快速原始數據"
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擋,快速原始數據"
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
'********************************************************************************************
'主程序完成,以下是補充部分。
'錯誤檢測.

'********************************************************************************************

tstSht.Cells(curRow, 1) = "4 系統錯誤檢查"
curRow = curRow + 1
errorCode = -1

Do
    myDmm.Utility.ErrorQuery errorCode, errorMsg
    tstSht.Cells(curRow, 1) = "錯誤編號:" & errorCode
    tstSht.Cells(curRow, 2) = errorMsg
    curRow = curRow + 1
Loop While errorCode <> 0

'系統恢復并關閉測試程序
myDmm.System2.WriteString "*RST"  '系統復位
myDmm.Close

curRow = curRow + 3
tstSht.Cells(curRow, 1) = "測試完成,數據關閉。 時間:"
tstSht.Cells(curRow, 2) = Format(Now(), "YYYY-mm-DD HH:MM:SS")
'***********************************************************************************************

'************************************表格格式化部分略去**********************************
'***********************************************************************************************

tstSht.Application.ActiveWorkbook.Save  '保存測量的結果數據文件。
MsgBox "測試完成!!!"

Exit Sub
'下面是出錯處理過程。比較簡單,未做詳細處理。        
ErrHandler:
    MsgBox "測試過程出錯。錯誤信息為:" & Err.Description

End Sub


實際運行的結果如下(數據表格的格式化):


這樣基本上實現了自動控制萬用表進行數據獲取的目的。在需要自動連續讀數的場所,可以大大降低對測試人員的需求。

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:701042 發表于 2020-3-4 12:54 | 只看該作者
感謝分享,根據你的文章和代碼,我成功連接了我的Ag34461萬用表。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久国产精品视频观看 | 国产视频一区二区三区四区五区 | 一级片免费视频 | 成人一区二区在线 | 91综合在线视频 | 精品一二三区 | 亚洲视频 欧美视频 | 国产精品一区二区三区在线播放 | 久久久久国产一区二区三区四区 | 国产一区二区三区四区 | 日本不卡一区二区三区 | 蜜月aⅴ免费一区二区三区 99re在线视频 | 精品亚洲永久免费精品 | 草久网 | 亚洲在线成人 | 日日操夜夜干 | 国产一区二区精品在线 | 男女av| 一级黄色片在线看 | 精品国产一级 | 久久国产精品网 | 欧美精品一区二区三区在线 | 一区二区三区视频在线 | 男人天堂网址 | 天天插天天操 | 久久精品亚洲精品国产欧美kt∨ | 一区二区三区四区电影 | 日日噜噜噜夜夜爽爽狠狠视频97 | 99免费在线| 男女羞羞视频在线免费观看 | 精品一区国产 | 欧美在线亚洲 | 国产精品久久久久久高潮 | 韩日av在线| 欧美精品成人一区二区三区四区 | 在线观看视频91 | 在线色网址 | 久久精品一级 | 高清黄色| 国产亚洲一区二区精品 | 国产丝袜一区二区三区免费视频 |