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

📄 samp4882.frm

📁 广泛用于示波器上的gpig工业标准接口的计算机编成库
💻 FRM
📖 第 1 页 / 共 2 页
字号:
'
'   Initalize the form controls.
'
Private Sub Form_Load()
    NumberOfReadings% = 50
    NumReadings.Text = Format$(NumberOfReadings%, "#")
    CurrentSample.Text = ""
    CurrentReading.Text = ""
    Call ClearReadingsList
End Sub

'
'   Format the reading to maintain constant numeric
'   display width for positive and negative numbers.
'
Private Function FormatReading(reading_val#) As String
    If reading_val# < 0# Then
        FormatReading$ = Format$(reading_val#, "0.00000")
    Else
        FormatReading$ = Format$(reading_val#, " 0.00000")
    End If
End Function


'
'   Information about automated testing.
'
Private Sub Info_Click()
    msg$ = "This form shows a typical interface for an automated test program.  The test operator enters the number of readings "
    msg$ = msg$ + "to acquire.  The other controls in the test window show status information when the test is executing and acquired "
    msg$ = msg$ + "and calculated data when the test is complete." + Chr$(10) + Chr$(10) + "When running an automated test, the user enters only test-specific "
    msg$ = msg$ + "information - all instrument configuration is done automatically by the test program."

    MsgBox msg$, 64
End Sub

Private Function Meter_Get_Reading(reading_val#) As Integer
    '  Trigger the Fluke 45 by sending the trigger command (*TRG) and
    '  request a measurement by sending the command "VAL1?".  If the
    '  error bit EERR is set in IBSTA%, call GPIBERR with an error
    '  message.

    Static Status As Integer
    
    Call Send(0, Fluke%, "*TRG; VAL1?", NLend)
    If (ibsta And EERR) Then
        Call ErrMsg("Error sending trigger. ")
        Meter_Get_Reading = 0
        Exit Function
    End If
   
    '  Wait for the Fluke 45 to assert SRQ, meaning it is ready to send a
    '  measurement.  If SRQ is not assserted within the timeout period,
    '  call GPIBERR with an error message.  The timeout period by default
    '  is 10 seconds.
    Call WaitSRQ(0, SRQasserted%)
    If (SRQasserted% = 0) Then
        Call ErrMsg("Error:  FLUKE 45 did not assert SRQ. ")
        Meter_Get_Reading = 0
        Exit Function
    End If
   
    '  Read the serial poll status byte of the FLuke 45.  If the error
    '  bit EERR is set in IBSTA%, call GPIBERR with an error message.
     
    Call ReadStatusByte(0, Fluke%, Status%)
    If (ibsta And EERR) Then
        Call ErrMsg("Error:  could not read status byte from FLUKE 45. ")
        Meter_Get_Reading = 0
        Exit Function
    End If

    '  Check if the Message Available Bit (bit 4) of the return status
    '  byte is set.  If this bit is not set, print the status byte and
    '  call GPIBERR with an error message.
    If (Status% And &H10) <> &H10 Then
        Call ErrMsg("Error:  status byte does not have MAV bit (&H10) set. ")
        Meter_Get_Reading = 0
        Exit Function
    End If
   
    '  Read the Fluke 45 measurement.  Store the measurement in string
    '  READING$.  The constant STOPend, defined in NIGLOBAL.BAS, instructs
    '  the subroutine Receive to terminate the read when END is detected.
    '  If the error bit EERR is set in IBSTA%, call GPIBERR with an error
    '  message.
    Reading$ = Space$(20)
    Call Receive(0, Fluke%, Reading$, STOPend)
    If (ibsta And EERR) Then
        Call ErrMsg("Error getting reading from FLUKE 45. ")
        Meter_Get_Reading = 0
        Exit Function
    End If
    '  The intent of this next line is to tack a ';' onto
    '  the end of the Reading$.  This is so the subsequent
    '  call to Val works properly.
    Reading$ = Mid$(Reading$, 1, ibcnt%) + ";"
    reading_val# = Val(Reading$)

    Meter_Get_Reading = 1

End Function

Private Function Meter_Init() As Integer
   
   ReDim result%(30)
   ReDim instruments%(31)                  ' array of primary addresses

   Fluke% = -1

   '  Our board needs to be the Controller-In-Charge in order to find all
   '  listeners on the GPIB.  To accomplish this, the subroutine SendIFC
   '  is called.  If the error bit EERR is set in IBSTA%, call GPIBERR with
   '  an error message.
   Call SendIFC(0)
   If (ibsta And EERR) Then
        Call ErrMsg("Error sending IFC.")
        Meter_Init = 0
        Exit Function
   End If

   '  Create an array containing all valid GPIB primary addresses.  This
   '  array (INSTRUMENTS%) will be given to the subroutine FindLstn to find all
   '  listeners.  The constant NOADDR, defined in NIGLOBAL.BAS, signifies the end
   '  of the array.
   For k% = 0 To 30
        instruments%(k%) = k%
   Next k%
   instruments%(31) = NOADDR

'   PRINT "Finding all listeners on the bus..."
   
   Screen.MousePointer = 11    'Wait (hourglass) cursor

   Call FindLstn(0, instruments%(), result%(), 31)
   If (ibsta And EERR) Then
        Screen.MousePointer = 0
        Call ErrMsg("Error finding all listeners.")
        Meter_Init = 0
        Exit Function
   End If

   '  Assign the value of IBCNT% to the variable NUM_LISTENERS%.  The GPIB
   '  interface board is detected as a listener on the bus; however, it is
   '  not included in the final count of the number of listeners.   Print
   '  the number of listeners found.
   num_listeners% = ibcnt% - 1

   '  Send the *IDN? command to each device that was found.  Your GPIB interface
   '  board is at address 0 by default.  The board does not respond to *IDN?, so
   '  skip it.
   '
   '  Establish a FOR loop to determine if the Fluke 45 is a listener on the
   '  GPIB.  The variable k% will serve as a counter for the FOR loop and as
   '  the index to the array RESULT%.

   For k% = 1 To num_listeners%

        '  Send the identification query to each listen address in the
        '  array RESULT%.  The constant NLend, defined in NIGLOBAL.BAS,
        '  instructs the subroutine Send to append a linefeed character
        '  with EOI asserted to the end of the message.  If the error
        '  bit EERR is set in IBSTA%, call GPIBERR with an error message.
           Call Send(0, result%(k%), "*IDN?", NLend)
           If (ibsta And EERR) Then
                Call ErrMsg("Error sending '*IDN?'. ")
                Meter_Init = 0
                Exit Function
           End If

        '  Read the name identification response returned from each device.
        '  Store the response in string READING$.  The constant STOPend,
        '  defined in NIGLOBAL.BAS, instructs the subroutine Receive to
        '  terminate the read when END is detected.  If the error bit EERR
        '  is set in IBSTA%, call GPIBERR with an error message.
           Reading$ = Space$(&H32)
           Call Receive(0, result%(k%), Reading$, STOPend)
           If (ibsta And EERR) Then
                Call ErrMsg("Error in receiving response to '*IDN?'. ")
                Meter_Init = 0
                Exit Function
           End If

        '  The low byte of the listen address is the primary address.
        '  Assign the variable PAD% the primary address of the device.
           pad% = result%(k%) And &HFF

        '  Determine if the name identification is the Fluke 45.  If it is
        '  the FLuke 45, assign PAD% to FLUKE%,  print message that the
        '  FLuke 45 has been found, call the subroutine FOUND, branch to
        '  the label PROGEND.
           If Left$(Reading$, 9) = "FLUKE, 45" Then
                Fluke% = pad%
                Exit For
           End If

   Next k%         '  End of FOR loop

   Screen.MousePointer = 0

   If (Fluke% <> -1) Then
        tmp$ = "Found the Fluke 45 at primary address " + Str$(Fluke%)
        MsgBox tmp$, 0
   Else
        Call ErrMsg("Did not find FLUKE 45.  Check your GPIB cables and try again.")
        Meter_Init = 0
        Exit Function
   End If


    '  DevClear will send the GPIB Selected Device Clear (SDC) command message to
    '  the Fluke 45.  If the error bit EERR is set in IBSTA%, call GPIBERR with
    '  an error message.
    Call DevClear(0, Fluke%)
    If (ibsta And EERR) Then
        Call ErrMsg("Error in clearing the FLUKE 45. ")
        Meter_Init = 0
        Exit Function
    End If

    '  Reset the Fluke 45 (*RST), program the Fluke 45 to
    '  measure using volts alternating current (VAC) using
    '  auto-ranging (AUTO), to wait for a trigger from the
    '  GPIB interface board (TRIGGER 2), and the assert the
    '  IEEE-488 Service Request, SRQ, when the measurement
    '  has been completed and the Fluke 45 is ready to send
    '  the result (*SRE 16).
    Call Send(0, Fluke%, "*RST; VAC; AUTO; TRIGGER 2; *SRE 16", NLend)
    If (ibsta And EERR) Then
        Call ErrMsg("Error in writing commands to Fluke 45. ")
        Meter_Init = 0
        Exit Function
    End If

    Meter_Init = 1

End Function

Private Sub QuitButton_Click()
    End
End Sub

Private Sub RunRepeat_Click()
    Call RunTest
End Sub

'
'   This function is the test program.
'
Private Sub RunTest()

    Static ReadingsArray#(100)

'   Clear status and calculated data displays

    CurrentSample.Text = ""
    CurrentReading.Text = ""
    AvgVal.Text = ""
    StdDevVal.Text = ""

    Call ClearReadingsList

'   Disable user inputs during test.

    QuitButton.Enabled = 0

'   Number of readings must be less than 101

    NumberOfReadings% = Val(NumReadings.Text)
    If NumberOfReadings% > 100 Then
        NumberOfReadings% = 50
    End If
    NumReadings.Text = Format$(NumberOfReadings%, "#")

    Status.Caption = " FINDING "
    Status.Refresh

    Do
        tmp% = Meter_Init()
    Loop Until tmp% = 1

    AvgValue# = 0#
    Status.Caption = " RUNNING "
    Status.Refresh

'   Collect the readings.

    For i% = 1 To NumberOfReadings%
        Do
            tmp% = Meter_Get_Reading(ReadingsArray#(i%))
        Loop Until tmp% = 1
        CurrentSample.Text = Str$(i%)
        CurrentReading.Text = FormatReading$(ReadingsArray#(i%))
        CurrentSample.Refresh
        CurrentReading.Refresh
        AvgValue# = AvgValue# + ReadingsArray#(i%)
    Next i%

'   Display the list of readings.

    For i% = 1 To NumberOfReadings%
        If i% < 10 Then
            DispStr$ = Format$(i%, "   #") + Space$(16) + FormatReading$(ReadingsArray#(i%))
        Else
            DispStr$ = Format$(i%, "  #") + Space$(16) + FormatReading$(ReadingsArray#(i%))
        End If
        ReadingsList.AddItem DispStr$
    Next i%

'   Put the board off-line
    Call ibonl(0, 0)
    If (ibsta And EERR) Then
        Call ErrMsg("Error putting board off-line. ")
    End If

'   Calculate the average and standard deviation values

    AvgValue# = AvgValue# / NumberOfReadings%
    AvgVal.Text = Format$(AvgValue#, "0.00000")
    StdDev# = 0#
    For i% = 1 To NumberOfReadings%
        StdDev# = StdDev# + (ReadingsArray#(i%) - AvgValue#) ^ 2
    Next i%
    StdDev# = Sqr(StdDev# / NumberOfReadings%)
    StdDevVal.Text = Format$(StdDev#, "0.00000")
    
'   Enable user inputs.

    QuitButton.Enabled = 1
    CurrentSample.Text = ""
    CurrentReading.Text = ""
    Status.Caption = " STOPPED "
End Sub

Private Sub StdDevVal_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

⌨️ 快捷键说明

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