樓主想用EXCEL采集一臺儀器(頻譜儀)的測驗資料,手里有以前的例子(做好的VBA),以前是用來采集HP的矢網儀,現在用來采集安捷倫的頻譜儀,代碼不多,也能看懂,但一些關鍵的指令不是很懂,感覺不能與頻譜儀建立連接。就來論壇求助了。
uj5u.com熱心網友回復:
介面檔案總得給一個吧。uj5u.com熱心網友回復:
好,我這就把代碼附上。Option Explicit
' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
' Copyright (c) Agilent Technologies Inc. 1999. All Rights Reserved. '
' '
' Agilent Technologies provides programming samples for illustration '
' purposes only. This sample program assumes that you are familiar '
' with the programming language being demonstrated and the tools used '
' to create and debug procedures. Agilent support engineers can help answer '
' questions relating to the functionality of the software components '
' provided by Agilent, but they will not modify these samples to provide added '
' functionality or construct procedures to meet your specific needs. '
' '
' You have a royalty-free right to use, modify, reproduce, and distribute '
' this sample program (and/or any modified version) in any way you find '
' useful, provided that you agree that Agilent has no warranty, obligations, '
' or liability for any sample programs. '
' '
' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
Dim nextTime As Variant
Dim continue As Boolean
Dim Scope As VisaComLib.FormattedIO488
Dim i As Integer
Dim T As Integer
Sub cmdStart_Click()
' set continue true to set the monitor
continue = True
' start the readings
update
End Sub
Sub cmdstop_click()
Dim AMPTarget As Variant
Dim i As Integer
For i = 0 To 178
AMPTarget = Cells(10 + i, 1)
Cells(10 + i, 2) = ""
Next
End Sub
Sub update()
' Using the Agt3494A control on this sheet, get the frequency
' and place in cell 'A1'
' set the timer to take the next reading
Dim Freq As Long
Dim reply As String
Dim AMP As Variant
Dim AMP2 As String
Dim AMPTarget As Variant
Dim FeqUp As Variant
Dim FeqDown As Variant
On Error GoTo MeasureError
If continue Then ' take the reading
'----------------濾波器1測驗--------------------
MsgBox "開始測驗放大器。。。"
'-----測驗頻點增益----
Scope.WriteString "CHAN1"
'Scope.WriteString "STAR 6GHZ"
'Scope.WriteString "STOP 18GHZ"
Scope.WriteString "AVEROOff"
'delay 1
Scope.WriteString "AVEROOn"
delay 8
Dim i As Integer
For i = 0 To 178
AMPTarget = 0.3 + i * 0.1
Scope.WriteString "MARK1" & Str$(AMPTarget) & "GHz"
Scope.WriteString "OUTPMARK"
AMP = Scope.ReadNumber
Cells(10 + i, 2) = AMP
Next
'delay 1
Scope.WriteString "AVEROOff"
delay 1
MsgBox "測驗完畢"
End If
Exit Sub
MeasureError:
continue = False
MsgBox "Error making measurement." & vbCrLf & _
"Check IO settings, and make sure you have a valid waveform for this measurement."
End Sub
Sub SetIO(ByRef ioAddress As String)
' set the I/O address to the text box in case the
' user changed it.
' bring up the input dialog and save any changes to the
' text box
Dim mgr As AgilentRMLib.SRMCls
On Error GoTo ioError
ioAddress = InputBox("Enter the IO address of the Scope", "Set IO address", ioAddress)
If Len(ioAddress) > 5 Then
Set mgr = New AgilentRMLib.SRMCls
Set Scope = New VisaComLib.FormattedIO488
Set Scope.IO = mgr.Open(ioAddress)
End If
Exit Sub
ioError:
MsgBox "Set IO error:" & vbCrLf & Err.Description
End Sub
Private Sub CommandButton2_Click()
SetIO Cells(5, 3)
End Sub
'------------------延時程式---------
Sub delay(T As Single)
Dim T1 As Single
T1 = Timer
Do
DoEvents
Loop While Timer - T1 < T
End Sub
uj5u.com熱心網友回復:
EXCEL界面上主要就三個按鈕。
uj5u.com熱心網友回復:
Dim Scope As VisaComLib.FormattedIO488' Using the Agt3494A control on this sheet, get the frequency
' and place in cell 'A1'
' set the timer to take the next reading
需要使用控制元件,看或搜相關控制元件的使用手冊。
uj5u.com熱心網友回復:
你說的對,我去找找 agilent e4440a 的指令手冊。雖然感覺不是很好找的樣子轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/86811.html
標籤:VBA
下一篇:34401a編程控制問題
