找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 13026|回复: 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空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:701042 发表于 2020-3-4 12:54 | 只看该作者
感谢分享,根据你的文章和代码,我成功连接了我的Ag34461万用表。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表