📄 devsamp.frm
字号:
If (ibsta% And RQS) Then sta$ = sta$ + " RQS"
If (ibsta% And CMPL) Then sta$ = sta$ + " CMPL"
If (ibsta% And LOK) Then sta$ = sta$ + " LOK"
If (ibsta% And RREM) Then sta$ = sta$ + " REM"
If (ibsta% And CIC) Then sta$ = sta$ + " CIC"
If (ibsta% And AATN) Then sta$ = sta$ + " ATN"
If (ibsta% And TACS) Then sta$ = sta$ + " TACS"
If (ibsta% And LACS) Then sta$ = sta$ + " LACS"
If (ibsta% And DTAS) Then sta$ = sta$ + " DTAS"
If (ibsta% And DCAS) Then sta$ = sta$ + " DCAS"
sta$ = sta$ + ">"
AddIbsta = sta$
End Function
Private Sub AvgVal_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
'
' Clear the list of readings in the test window
'
Private Sub ClearReadingsList()
If ReadingsList.ListCount > 0 Then
For i% = 0 To ReadingsList.ListCount - 1
ReadingsList.RemoveItem 0
Next i%
End If
ReadingsList.Refresh
End Sub
Private Sub CurrentReading_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub CurrentSample_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub ErrMsg(msg$)
msg$ = msg$ + AddIbsta() + AddIberr() + AddIbcnt()
If MsgBox(msg$, 5) = 2 Then
End
End If
End Sub
'
' Initalize the form controls.
'
Private Sub Form_Load()
GPIBglobalsRegistered = 0
NumberOfReadings% = 50
NumReadings.Text = Format$(NumberOfReadings%, "#")
CurrentSample.Text = ""
CurrentReading.Text = ""
Call ClearReadingsList
addr.Text = "1"
addr.AddItem "1"
addr.AddItem "2"
addr.AddItem "3"
addr.AddItem "4"
addr.AddItem "5"
addr.AddItem "6"
addr.AddItem "7"
addr.AddItem "8"
addr.AddItem "9"
addr.AddItem "10"
addr.AddItem "11"
addr.AddItem "12"
addr.AddItem "13"
addr.AddItem "14"
addr.AddItem "15"
addr.AddItem "16"
addr.AddItem "17"
addr.AddItem "18"
addr.AddItem "19"
addr.AddItem "20"
addr.AddItem "21"
addr.AddItem "22"
addr.AddItem "23"
addr.AddItem "24"
addr.AddItem "25"
addr.AddItem "26"
addr.AddItem "27"
addr.AddItem "28"
addr.AddItem "29"
addr.AddItem "30"
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.
Call ibtrg(Dev%)
If (ibsta And EERR) Then
Call ErrMsg("Error triggering device.")
Meter_Get_Reading = 0
Exit Function
End If
' Request the triggered measurement by sending VAL1?
wrtbuf$ = "VAL1?"
Call ibwrt(Dev%, wrtbuf$)
If (ibsta And EERR) Then
Call ErrMsg("Error writing to device.")
Meter_Get_Reading = 0
Exit Function
End If
' Wait for the Fluke 45 to request service (RQS) or
' timeout
Call ibwait(Dev%, &H4800)
If (ibsta And EERR) Then
Call ErrMsg("Error waiting for RQS or TIMO.")
Meter_Get_Reading = 0
Exit Function
End If
If (ibsta And &H4000) Then
Call ErrMsg("Wait for RQS timed out.")
Meter_Get_Reading = 0
Exit Function
End If
' If the returned status byte is &H50 then the Fluke
' 45 has valid data to send
Call ibrsp(Dev%, SPollByte%)
If (ibsta And EERR) Then
Call ErrMsg("Error serial polling the device.")
Meter_Get_Reading = 0
Exit Function
End If
If (SPollByte% <> &H50) Then
Call ErrMsg("Serial poll byte is NOT &H50.")
Meter_Get_Reading = 0
Exit Function
End If
' Read the Fluke 45 measurement.
rdbuf$ = Space$(10)
Call ibrd(Dev%, rdbuf$)
If (ibsta And EERR) Then
Call ErrMsg("Error reading from device.")
Meter_Get_Reading = 0
Exit Function
End If
reading_val# = Val(rdbuf$)
Meter_Get_Reading = 1
End Function
Private Function Meter_Init(addr%) As Integer
Call ibdev(0, addr%, 0, T10s, 1, 0, Dev%)
If Dev% < 0 Then
MsgBox "Error opening device. I'm quitting!", 16
End
End If
Call ibclr(Dev%)
If (ibsta And EERR) Then
Call ErrMsg("Error clearing device.")
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 then 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).
wrtbuf$ = "*RST; VAC; AUTO; TRIGGER 2; *SRE 16"
Call ibwrt(Dev%, wrtbuf$)
If (ibsta And EERR) Then
Call ErrMsg("Error initializing device.")
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
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%, "#")
Do
tmp% = Meter_Init(Val(addr.Text))
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 device off-line
Call ibonl(Dev%, 0)
If (ibsta And EERR) Then
Call ErrMsg("Error putting device off-line.")
End If
' Calculate the average and standard deviation values
If (NumberOfReadings% > 0) Then
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")
End If
' 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
Public Sub Main()
Load Form
Load Test
X = Forms.Count
Show
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -