⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 vb,agilent 816x vxipnp control library application.
💻 FRM
字号:
VERSION 5.00
Object = "{02B5E320-7292-11CF-93D5-0020AF99504A}#1.0#0"; "mschart.ocx"
Begin VB.Form MainDlg 
   Appearance      =   0  'Flat
   AutoRedraw      =   -1  'True
   BackColor       =   &H8000000B&
   Caption         =   "Display to Reference (VbSample 3)"
   ClientHeight    =   5115
   ClientLeft      =   4350
   ClientTop       =   2850
   ClientWidth     =   7230
   ClipControls    =   0   'False
   FillColor       =   &H00C0C0C0&
   LinkTopic       =   "Form1"
   ScaleHeight     =   5115
   ScaleWidth      =   7230
   Begin VB.Timer Timer1 
      Left            =   6720
      Top             =   4200
   End
   Begin VB.Frame Frame2 
      Caption         =   "Attenuation"
      Height          =   735
      Left            =   5160
      TabIndex        =   13
      Top             =   3840
      Width           =   1335
      Begin VB.Label attenuationLabel 
         Alignment       =   2  'Center
         Caption         =   "0"
         Height          =   255
         Left            =   360
         TabIndex        =   14
         Top             =   240
         Width           =   615
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "No of Reads"
      Height          =   735
      Left            =   5160
      TabIndex        =   11
      Top             =   2880
      Width           =   1335
      Begin VB.Label Value_No 
         Alignment       =   2  'Center
         Caption         =   "0"
         Height          =   255
         Left            =   240
         TabIndex        =   12
         Top             =   360
         Width           =   735
      End
   End
   Begin MSChartLib.MSChart MSChart 
      Height          =   2895
      Left            =   240
      OleObjectBlob   =   "Form1.frx":0000
      TabIndex        =   10
      Top             =   1800
      Width           =   4695
   End
   Begin VB.CommandButton Start 
      Caption         =   "Start"
      Height          =   615
      Left            =   5160
      TabIndex        =   7
      Top             =   2040
      Width           =   1335
   End
   Begin VB.CommandButton DispToRef 
      Caption         =   "Display --> Reference"
      Height          =   615
      Left            =   5160
      TabIndex        =   6
      ToolTipText     =   "Press this button to set the powermeter reference to the value shown in the display"
      Top             =   1320
      Width           =   1335
   End
   Begin VB.CommandButton FLSwlToPwm 
      Caption         =   "Source Wavelength --> Powermeter"
      Height          =   615
      Left            =   5160
      TabIndex        =   5
      ToolTipText     =   "Press this button to set  the powermeter wavelength to the laser source wavelength"
      Top             =   600
      Width           =   1335
   End
   Begin VB.CommandButton Close 
      Caption         =   "Close"
      Height          =   375
      Left            =   5160
      TabIndex        =   0
      Top             =   120
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "Powermeter Reference"
      Height          =   255
      Left            =   2520
      TabIndex        =   9
      Top             =   1080
      Width           =   1815
   End
   Begin VB.Label PWM_Reference 
      Alignment       =   2  'Center
      BackColor       =   &H8000000E&
      BorderStyle     =   1  'Fixed Single
      Height          =   255
      Left            =   2520
      TabIndex        =   8
      Top             =   1320
      Width           =   1695
   End
   Begin VB.Label PWM_wl 
      Alignment       =   2  'Center
      BackColor       =   &H8000000E&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Powerm. Wavelength"
      Height          =   255
      Left            =   2520
      TabIndex        =   4
      ToolTipText     =   "wavelength of the powermeter"
      Top             =   600
      Width           =   1695
   End
   Begin VB.Label FLS_wl 
      Alignment       =   2  'Center
      BackColor       =   &H8000000E&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Src Wavelength"
      Height          =   255
      Left            =   360
      TabIndex        =   3
      ToolTipText     =   "Wavelength of the laser source"
      Top             =   600
      Width           =   1695
   End
   Begin VB.Label Label_PWM_wl 
      Caption         =   "Powermeter Wavelength"
      Height          =   255
      Left            =   2520
      TabIndex        =   2
      Top             =   360
      Width           =   1815
   End
   Begin VB.Label Label_FLS_wl 
      Caption         =   "Laser Source Wavelength"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   360
      Width           =   1935
   End
End
Attribute VB_Name = "MainDlg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim notElapsed As Boolean



Private Sub Close_Click()
Me.Hide
Unload MainDlg
End Sub

Private Sub DispToRef_Click()
Dim retStatus, refMode  As Long
Dim avTime, refValueInt, refValueExt As Double

'turn laser on
retStatus = hp816x_set_FLS_laserState(IHandle, FLS_Slot, 1)
checkStatus (retStatus)
attenuation = 0
retStatus = hp816x_set_FLS_attenuation(IHandle, FLS_Slot, attenuation, attenuation)
checkStatus (retStatus)
'wait till the first measurement is valid
'read the averaging time and delay the execution
retStatus = hp816x_get_PWM_averagingTime_Q(IHandle, PWM_Slot, hp816x_CHAN_1, avTime)
checkStatus (retStatus)
notElapsed = False
Timer1.Enabled = True
Timer1.Interval = avTime * 1000
'read the new value back
While notElapsed
Wend
'End With
'update the control
retStatus = hp816x_get_PWM_referenceValue_Q(IHandle, PWM_Slot, hp816x_CHAN_0, _
            refMode, refValueInt, refValueExt)
checkStatus (retStatus)
PWM_Reference.Caption = Format(refValueInt, "0.0000E+00")

'measure now relativ to the reference
retStatus = hp816x_set_PWM_referenceSource(IHandle, PWM_Slot, hp816x_CHAN_0, _
                     hp816x_PWM_REF_RELATIV, hp816x_PWM_TO_REF, 0, 0)
checkStatus (retStatus)

End Sub


Private Sub FLSwlToPwm_Click()
Dim lower, upper As Double
Dim retStatus  As Long
'read source wavelength
retStatus = hp816x_get_FLS_wavelength_Q(IHandle, FLS_Slot, lower, upper)
checkStatus (retStatus)
FLS_wl.Caption = Format(lower, "0.0000E+00")
'set the powermeter wavelength equal the source wavelength
retStatus = hp816x_set_PWM_wavelength(IHandle, PWM_Slot, hp816x_CHAN_0, lower)
checkStatus (retStatus)
PWM_wl.Caption = Format(lower, "0.0000E+00")
End Sub

Private Sub Form_Initialize()
Dim retStatus  As Long
Dim MId As String * 256 'module id string
Dim message, Title, Default
Dim slotInfo(18) As Long
Dim refMode As Long
Dim refValueInt, refValueExt, upperWave, _
    lowerWave, minWavelength, maxWavelength, _
    currentWavelength As Double

'get the HPIB address
Title = "Enter HPIB Address"
Default = "GPIB0::20::INSTR"
message = "HPIB Address"
MyValue = InputBox(message, Title, Default)
'initialize the visa library
retStatus = hp816x_init(MyValue, 0, 0, IHandle)
checkStatus (retStatus)
retStatus = hp816x_errorQueryDetect(IHandle, 1)
checkStatus (retStatus)
retStatus = hp816x_getSlotInformation_Q(IHandle, hp816x_MAX_SLOTS, slotInfo(0))
checkStatus (retStatus)

For i = 0 To 18 Step 1
If (slotInfo(i) <> 0) Then
 If (slotInfo(i) = hp816x_FIXED_SINGLE_SOURCE Or slotInfo(i) = hp816x_FIXED_DUAL_SOURCE) Then
    If (FLS_Slot = 0) Then
        FLS_Slot = i
    End If
 End If
 If (slotInfo(i) = hp816x_SINGLE_SENSOR Or slotInfo(i) = hp816x_DUAL_SENSOR) Then
    If (PWM_Slot = 0) Then
        PWM_Slot = i
    End If
 End If
End If
Next
If (FLS_Slot = 0 Or PWM_Slot = 0) Then
warning = "This example needs a fixed laser source" + Chr(13) + _
            Chr(10) + "and a powermeter"
retStatus = MsgBox(warning, vbOKOnly + vbCritical)
'unload the library
retStatus = hp816x_close(IHandle)
End
End If
'fill the reference static control
retStatus = hp816x_get_PWM_referenceValue_Q(IHandle, PWM_Slot, hp816x_CHAN_0, _
            refMode, refValueInt, refValueExt)

checkStatus (retStatus)
PWM_Reference.Caption = refValueInt

'fill the laser source wavelength static control
retStatus = hp816x_get_FLS_wavelength_Q(IHandle, FLS_Slot, _
            lowerWave, upperWave)
checkStatus (retStatus)
FLS_wl.Caption = Format(lowerWave, "0.0000E+00")

'fill the powermeter source wavelength static control
retStatus = hp816x_get_PWM_wavelength_Q(IHandle, PWM_Slot, hp816x_CHAN_0, _
             minWavelength, maxWavelength, currentWavelength)
checkStatus (retStatus)

PWM_wl.Caption = Format(currentWavelength, "0.0000E+00")
'initialize the mschart
With MSChart
        .Plot.Axis(VtChAxisIdX, 0).ValueScale.Auto = False
        .Plot.Axis(VtChAxisIdX, 0).Intersection.LabelsInsidePlot = True
        .Plot.Axis(VtChAxisIdX, 0).Labels.Item(1).Auto = False
        .Plot.Axis(VtChAxisIdX, 0).Labels.Item(1).TextLayout.Orientation = VtOrientationHorizontal
        .Plot.Axis(VtChAxisIdX, 0).Tick.Style = VtChAxisTickStyleCenter
        .Plot.Axis(VtChAxisIdX, 0).Tick.Length = 1
        .Plot.Axis(VtChAxisIdY, 0).AxisTitle.Text = "Power(db)"
        .Plot.Axis(VtChAxisIdX, 0).AxisTitle.Text = "Attenuation (db)"
        .SeriesType = VtChSeriesType2dLine
        .Plot.SeriesCollection(1).LegendText = "Power"
        .RowLabelIndex = 1
        Dim Y(1 To 100, 1 To 1) As Double
        .ChartData = Y
        .RowCount = 150
        .Column = 1
        j = 0
        For i = 1 To 150 Step 50
        .Row = i
        .RowLabel = CStr(j)
        j = j + 2
        Next i
        .Refresh

End With

End Sub



Private Sub Form_Terminate()
Dim retStatus, lState As Long
Dim attenuation, reference As Double
'set attenuation to zero
attenuation = 0
attenuationLabel.Caption = attenuation
attenuationLabel.Refresh
retStatus = hp816x_set_FLS_attenuation(IHandle, FLS_Slot, attenuation, attenuation)
checkStatus (retStatus)
'turn laser off
lState = 0
retStatus = hp816x_set_FLS_laserState(IHandle, FLS_Slot, lState)
checkStatus (retStatus)
'return to absolute measuring
retStatus = hp816x_set_PWM_powerUnit(IHandle, PWM_Slot, hp816x_CHAN_0, hp816x_PU_WATT)
checkStatus (retStatus)
reference = 0
retStatus = hp816x_set_PWM_referenceSource(IHandle, PWM_Slot, hp816x_CHAN_0, _
                     hp816x_PWM_REF_ABSOLUTE, hp816x_PWM_TO_REF, 0, 0)
checkStatus (retStatus)
retStatus = hp816x_set_PWM_referenceValue(IHandle, PWM_Slot, hp816x_CHAN_0, 1E-18, 1E-18)
checkStatus (retStatus)
retStatus = hp816x_close(IHandle)
End Sub





Private Sub Start_Click()
Dim retStatus  As Long
Dim pwmValue, attenuation As Double
Dim data(1 To 150, 1 To 1) As Double
'set the attenuation for the source to 0
With MSChart
    attenuation = 0
    retStatus = hp816x_set_FLS_attenuation(IHandle, FLS_Slot, attenuation, attenuation)
    checkStatus (retStatus)
    attenuationLabel.Caption = attenuation
    attenuationLabel.Caption = ""
    Value_No.Caption = "0"
    For i = 1 To 150 Step 1
        retStatus = hp816x_PWM_readValue(IHandle, PWM_Slot, hp816x_CHAN_1, pwmValue)
        checkStatus (retStatus)
        If (retStatus < VI_SUCCESS) Then GoTo ErrExit
        Value_No.Caption = i
        .Row = i
        .data = pwmValue
            'increase attenuation for i = 50 and  for i = 100
            If (i = 50 Or i = 100) Then
            attenuation = attenuation + 2
            attenuationLabel.Caption = attenuation
            retStatus = hp816x_set_FLS_attenuation(IHandle, FLS_Slot, _
                        attenuation, attenuation)
            checkStatus (retStatus)
            attenuationLabel.Refresh
            End If

        Value_No.Refresh
    Next i
ErrExit:
End With
End Sub


Private Sub Timer1_Timer()
'display to reference
retStatus = hp816x_PWM_displayToReference(IHandle, PWM_Slot, hp816x_CHAN_0)
checkStatus (retStatus)
notElapsed = True
Timer1.Enabled = False

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -