這是表單的
Option Explicit
''' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
''' Copyright ?2002 Agilent Technologies Inc. All rights reserved.
'''
''' You have a royalty-free right to use, modify, reproduce and distribute
''' the Sample Application Files (and/or any modified version) in any way
''' you find useful, provided that you agree that Agilent Technologies has no
''' warranty, obligations or liability for any Sample Application Files.
'''
''' Agilent Technologies provides programming examples for illustration 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 Technologies support engineers can help explain the
''' functionality of Agilent Technologies software components and associated
''' commands, but they will not modify these samples to provide added
''' functionality or construct procedures to meet your specific needs.
''' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'
' This example program calls the module DAQ_34970A to set a scan and
' then get the readings from the instrument. The module DAQ_34970.bas
' was created by the 34970A Code Wizard VB6.0 add in. The module was modified
' to call a routine that places data onto the form.
' This code requires a MUX module in slot 1
'
' It demonstrates how to monitor channels set up on the 34970A by calling the
' channel list, allowing the user to select one of the channels, and then getting
' a reading (Monitor) from that channel.
'
Dim Daq As VisaComLib.FormattedIO488
Const IO_ADDRESS = "ASRL1::INSTR"
Dim m_ioAddress As String
Dim x As Integer, y As Integer, z As Integer, w As Integer, v As Integer
Public Sub WriteDataToForm(Readings() As Double, _
Units() As String, _
ChanNumb() As Integer, _
Time() As Date, _
ByVal Sweep As Integer, _
ByVal numberChannels As Integer)
' A call to this routine was added to the code developed by the
' 34970A code Wizard
' This code will fill out the scan text box every time it is executed.
' If you do not use the Units, Channel annotation, or Time when making
' new code, you will have to modify this code.
'
Dim I As Long
Dim lineUnits As String
Dim lineChannels As String
lineUnits = ""
lineChannels = ""
If Sweep = 1 Then
For I = 1 To numberChannels
' We put a heading only for the first sweep
lineUnits = lineUnits & Units(1, I) & vbTab
lineChannels = lineChannels & Str$(ChanNumb(1, I)) & vbTab
Next I
txtScanData.SelText = lineUnits & vbCrLf & lineChannels & vbCrLf
End If
For I = 101 To numberChannels
Me.txtScanData.SelText = Format$(Readings(Sweep, I), "0.0e+0") & vbTab
Next I
Me.txtScanData.SelText = vbCrLf
End Sub
Private Sub cmdMonitor_Click()
Dim channel As String
If isconnected Then
channel = MonitorChannel
Monitor Daq, txtMonitor, channel
InstrumentError Daq
End If
End Sub
Private Sub cmdRefreshChannels_Click()
Me.MousePointer = vbHourglass
If isconnected Then
GetScanList Daq, lstChannel
InstrumentError Daq
End If
Me.cmdMonitor.Enabled = True
Me.MousePointer = vbDefault
End Sub
Private Sub cmdStartScan_Click()
Me.MousePointer = vbHourglass
If isconnected Then
Me.txtScanData.Text = ""
main_34970A Daq
InstrumentError Daq
cmdRefreshChannels_Click
End If
Me.MousePointer = vbDefault
End Sub
Private Function MonitorChannel() As String
' returns the user selected channel to monitor
Dim Index As Long
With lstChannel
Index = .ListIndex
If Index > 0 Then
MonitorChannel = Right$(.List(Index), 3)
Else
MonitorChannel = "Front Panel"
Exit Function
End If
End With
End Function
Public Sub InstrumentError(Instrument As VisaComLib.FormattedIO488)
Dim reply As String
With Instrument
.WriteString "Syst:Error?"
reply = .ReadString
End With
If Val(reply) <> 0 Then
MsgBox "Instrument Error: " & vbCrLf & reply, vbCritical
InstrumentError Instrument
End If
End Sub
Private Function isconnected() As Boolean
' determines if the instrument is connected, and
' gives a message if not
Dim result() As Variant
Dim oldTimeout As Long
On Error GoTo connectError
With Daq
oldTimeout = .io.Timeout
.io.Timeout = 1000
.WriteString "*IDN?"
result = .ReadList
.io.Timeout = oldTimeout
End With
If InStr(1, result(1), "34970A", vbTextCompare) = 0 Then
GoTo WrongInstrumentError
End If
isconnected = True
Exit Function
connectError:
Daq.io.Timeout = 10000
MsgBox "Instrument not connected. Please check connections and use the Set I/O toolbar button to set the instrument connection."
isconnected = False
Exit Function
WrongInstrumentError:
MsgBox "Incorrect instrument: " & vbCrLf & _
"Expected 34970A " & vbCrLf & _
"Instrument discovered: " & result(1)
isconnected = False
End Function
Private Sub cmdSetIO_Click()
' 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 VisaComLib.ResourceManager
On Error GoTo ioError
m_ioAddress = InputBox("Enter the IO address of the Function Generator", "Set IO address", m_ioAddress)
Set mgr = New VisaComLib.ResourceManager
Set Daq = New VisaComLib.FormattedIO488
Set Daq.io = mgr.Open(m_ioAddress)
Exit Sub
ioError:
MsgBox "Set IO error:" & vbCrLf & Err.Description
End Sub
完全不懂啊,編譯出現錯誤
could not interpret I/O as single number
uj5u.com熱心網友回復:
一般來說這種東西還是看手冊比較方便, 只要弄懂幾個關鍵的部件或物件即可.我的前提是你VB沒有問題的話. 如果你VB也不過關, 那么還是花點錢請人做吧.
uj5u.com熱心網友回復:
編譯能出現“could not interpret I/O as single number”錯誤?估計你連運行時錯誤和編譯錯誤都分不清。運行時錯誤不屬于代碼問題,是運行的時候出現的,沒辦法幫你解決,因為沒有你的硬體和環境。
uj5u.com熱心網友回復:
用別人的動態庫讀取設定硬體的吧?動態庫沒有用好。去找這個動態庫的資料吧
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/122891.html
標籤:多媒體
上一篇:VB小白一枚求教
