📄 simple.frm
字号:
VERSION 5.00
Begin VB.Form Simple
Caption = "Power Supply Read/Write"
ClientHeight = 5400
ClientLeft = 2505
ClientTop = 1410
ClientWidth = 5310
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 5400
ScaleWidth = 5310
Begin VB.ListBox ReadingsList
Height = 1620
Left = 1080
TabIndex = 6
Top = 2160
Width = 2895
End
Begin VB.Frame Frame1
Caption = "Read/Write Application for Power Supply"
Height = 4488
Left = 484
TabIndex = 0
Top = 363
Width = 4246
Begin VB.TextBox PPSCommand
Height = 374
Left = 605
TabIndex = 4
Top = 605
Width = 2915
End
Begin VB.CommandButton QuitCmd
Caption = "Quit"
Height = 374
Left = 2299
TabIndex = 2
Top = 3630
Width = 737
End
Begin VB.CommandButton RunCmd
Caption = "Run"
Height = 374
Left = 968
TabIndex = 1
Top = 3630
Width = 737
End
Begin VB.Label Label2
Caption = "String to Write"
Height = 253
Left = 605
TabIndex = 5
Top = 363
Width = 1705
End
Begin VB.Label Label1
Caption = "String Read from Power Supply"
Height = 253
Left = 605
TabIndex = 3
Top = 1452
Width = 2552
End
End
End
Attribute VB_Name = "Simple"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Filename - Simple.frm
'
' This application demonstrates how to read from and write to the
' Tektronix PS2520G Programmable Power Supply using GPIB.
'
' This sample application is comprised of three basic parts:
'
' 1. Initialization
' 2. Main Body
' 3. Cleanup
'
' The Initialization portion consists of getting a handle to a
' device and then clearing the device.
'
' In the Main Body, this application queries a device for its
' identification code by issuing the '*IDN?' command. Many
' instruments respond to this command with an identification string.
' Note, 488.2 compliant devices are required to respond to this
' command.
'
' The last step, Cleanup, takes the device offline.
Option Explicit
Const BDINDEX = 0 ' Board Index
Const PRIMARY_ADDR_OF_PPS = 1 ' Primary address of device
Const NO_SECONDARY_ADDR = 0 ' Secondary address of device
Const TIMEOUT = T10s ' Timeout value = 10 seconds
Const EOTMODE = 1 ' Enable the END message
Const EOSMODE = 0 ' Disable the EOS mode
Const ARRAYSIZE = 1024 ' Size of read buffer
Dim ErrorMnemonic
Dim ErrMsg As String * 100
Dim Dev As Integer
Dim ValueStr As String * ARRAYSIZE
Private Sub GPIBCleanup(msg$)
' After each GPIB call, the application checks whether the call
' succeeded. If an NI-488.2 call fails, the GPIB driver sets the
' corresponding bit in the global status variable. If the call
' failed, this procedure prints an error message, takes the device
' offline and exits.
ErrorMnemonic = Array("EDVR", "ECIC", "ENOL", "EADR", "EARG", _
"ESAC", "EABO", "ENEB", "EDMA", "", _
"EOIP", "ECAP", "EFSO", "", "EBUS", _
"ESTB", "ESRQ", "", "", "", "ETAB")
ErrMsg$ = msg$ & Chr(13) & "ibsta = &H" & Hex(ibsta) & Chr(13) _
& "iberr = " & iberr & " <" & ErrorMnemonic(iberr) & ">"
MsgBox ErrMsg$, vbCritical, "Error"
ilonl Dev%, 0
End
End Sub
Private Sub Form_Load()
' ========================================================================
'
' INITIALIZATION SECTION
'
' ========================================================================
' The application brings the power supply online using ildev. A
' device handle, Dev, is returned and is used in all subsequent
' calls to the device.
Dev% = ildev(BDINDEX, PRIMARY_ADDR_OF_PPS, NO_SECONDARY_ADDR, _
TIMEOUT, EOTMODE, EOSMODE)
If (ibsta And EERR) Then
ErrMsg = "Unable to open device" & Chr(13) & "ibsta = &H" _
& Hex(ibsta) & Chr(13) & "iberr = " & iberr
MsgBox ErrMsg, vbCritical, "Error"
End
End If
' The application resets the GPIB portion of the device by calling
' ilclr.
ilclr Dev%
If (ibsta And EERR) Then
Call GPIBCleanup("Unable to clear device")
End If
' The default command to be written to the power supply is
' displayed in the text box.
PPSCommand.Text = "*IDN?"
End Sub
Private Sub RunCmd_Click()
Dim DisplayStr As String
' ========================================================================
'
' MAIN BODY SECTION
'
' In this application, the Main Body communicates with the instrument
' by writing a command to it and reading its response. This would be
' the right place to put other instrument communication.
'
' ========================================================================
' The application writes the text in PPSCommand to the power
' supply.
ilwrt Dev%, PPSCommand.Text, Len(PPSCommand.Text)
If (ibsta And EERR) Then
Call GPIBCleanup("Unable to request data from Power Supply")
End If
' The application reads the ASCII string from the power supply
' into the ValueStr variable.
ilrd Dev%, ValueStr$, Len(ValueStr$)
If (ibsta And EERR) Then
Call GPIBCleanup("Unable to read from device")
End If
' The power supply returns a Line Feed character with its output
' string. You could use the LEFT$() function which returns a
' specified number of characters from the left side of a string to
' remove the Line Feed character. The code fragment below
' illustrates how to use the LEFT$() function along with the GPIB
' global count variable, ibcntl, to copy the contents of ValueStr
' into a new string called DisplayStr. Note, that you need one less
' character than the total number contained in ibcntl.
DisplayStr = Left$(ValueStr, ibcntl - 1)
' The reading from the power supply is displayed in the List box.
ReadingsList.AddItem DisplayStr
ReadingsList.Refresh
End Sub
Private Sub QuitCmd_Click()
' ========================================================================
'
' CLEANUP SECTION
'
' ========================================================================
'The device is taken offline.
ilonl Dev%, 0
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -