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

📄 iocmd.frm

📁 HP GPIB的VB和C语言库文件,参考范例.
💻 FRM
字号:
VERSION 4.00
Begin VB.Form IOCMD 
   Appearance      =   0  'Flat
   BackColor       =   &H00C0C0C0&
   Caption         =   "Instrument I/O Command Utility"
   ClientHeight    =   3690
   ClientLeft      =   1035
   ClientTop       =   3810
   ClientWidth     =   6930
   BeginProperty Font 
      name            =   "MS Sans Serif"
      charset         =   0
      weight          =   700
      size            =   8.25
      underline       =   0   'False
      italic          =   0   'False
      strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H80000008&
   Height          =   4050
   Icon            =   "IOCMD.frx":0000
   Left            =   975
   LinkTopic       =   "Form1"
   ScaleHeight     =   3690
   ScaleWidth      =   6930
   Top             =   3510
   Width           =   7050
   Begin VB.TextBox txtCommand 
      Appearance      =   0  'Flat
      Height          =   288
      Left            =   2280
      TabIndex        =   5
      Text            =   "*IDN?"
      Top             =   1560
      Width           =   3972
   End
   Begin VB.CommandButton cmdOutputCmd 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "Output Command"
      Default         =   -1  'True
      Height          =   492
      Left            =   2520
      TabIndex        =   4
      Top             =   2760
      Width           =   1812
   End
   Begin VB.TextBox txtResponse 
      Appearance      =   0  'Flat
      Height          =   288
      Left            =   2280
      TabIndex        =   1
      Top             =   2160
      Width           =   4332
   End
   Begin VB.TextBox txtInstAddr 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Height          =   288
      Left            =   2280
      TabIndex        =   0
      Text            =   "hpib7,0"
      Top             =   960
      Width           =   2412
   End
   Begin VB.Label Label3 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H0000FFFF&
      Caption         =   "Command :"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   240
      TabIndex        =   6
      Top             =   1560
      Width           =   1095
   End
   Begin VB.Label Label2 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H0000FFFF&
      Caption         =   "Response:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   240
      TabIndex        =   3
      Top             =   2160
      Width           =   1095
   End
   Begin VB.Label Label1 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H0000FFFF&
      Caption         =   "Instrument Address:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   240
      TabIndex        =   2
      Top             =   960
      Width           =   1815
   End
End
Attribute VB_Name = "IOCMD"
Attribute VB_Creatable = False
Attribute VB_Exposed = False

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  This routine uses the Standard Instrument Control
'  Library to send commands to an instrument.  The address
'  of the instrument is obtained from a Text box named
'  txtInstAddr.  If the command is a SCPI query command
'  then the response to the command will be read and
'  displayed in the txtResponse Text box.
'
'  Note that any SICL errors that occur are displayed in
'  the txtResponse Text box.
'
'  This routine is called each time the cmdOutputCmd Command
'  button is clicked.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub cmdOutputCmd_Click()
   Dim id As Integer                ' device session id
   Dim readbuf As String * 128      ' buffer used for iread
   Dim commandstr As String * 128   ' command passed to instrument
   Dim index As Integer             ' used to parse SCPI error message
   Dim nargs As Integer             ' # args converted by format string

'  Set up an error handler within this subroutine that will get
'  called if a SICL error occurs.
   On Error GoTo ErrorHandler

'  Disable the button used to initiate I/O while I/O is
'  being performed.
   cmdOutputCmd.Enabled = False

'  Clear the response string in the txtResponse TextBox.
   txtResponse.Text = ""

'  Open a device session using the device address contained in
'  the Text field of the txtInstAddr TextBox.
   id = iopen(txtInstAddr.Text)

'  Set the I/O timeout value for this session to 1 second.
   Call itimeout(id, 1000)

'  Clear the error/event queue for the instrument.  This allows
'  us to query the instrument after sending a command to see if
'  the command was accepted.
   nargs = ivprintf(id, "*CLS" + Chr$(10))

'  Write the command to the instrument terminated by a linefeed.
   commandstr = txtCommand.Text + Chr$(10)
   nargs = ivprintf(id, commandstr)

'  If the command is a SCPI query command ending in '?',
'  then read and display the response to the command.
   If InStr(txtCommand.Text, "?") Then
      nargs = ivscanf(id, "%128t", readbuf)

   '  Strip out returns and line feeds from the response string.
      readbuf = strip_crlf(readbuf)

   '  Display the response string in the Text field of the
   '  txtResponse TextBox.
      txtResponse.Text = readbuf
   End If

'  Query the instrument to see if the command was accepted
   nargs = ivprintf(id, "SYST:ERR?" + Chr$(10))
   nargs = ivscanf(id, "%128t", readbuf)
   
'  Strip out returns and line feeds from the response string.  Note
'  that strip_crlf is a utility routine defined in SICL.BAS.
   readbuf = strip_crlf(readbuf)

'  The SCPI error # is separated by the error message by a ',' character
   index = InStr(readbuf, ",")
   If index <> 0 Then
      If Val(Left$(readbuf, index - 1)) <> 0 Then
         txtResponse.Text = "SCPI Error " + readbuf
      End If
   Else
'     handle non-SCPI errors
      txtResponse.Text = "Error " + readbuf
   End If

'  Close the device session.
   Call iclose(id)

'  Enable the button used to initiate I/O
   cmdOutputCmd.Enabled = True
   Exit Sub

ErrorHandler:

'  Display the error message in the txtResponse TextBox.
   txtResponse.Text = "*** Error : " + Error$

'  Close the device session if iopen was successful.
   If id <> 0 Then
      iclose (id)
   End If
   
'  Enable the button used to initiate I/O
   cmdOutputCmd.Enabled = True
 
   Exit Sub

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  The following routine is called when the application's
'  Start Up form is unloaded.  It calls siclcleanup to
'  release resources allocated by SICL for this
'  application.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Unload(Cancel As Integer)
   Call siclcleanup    ' Tell SICL to clean up for this task
End Sub

⌨️ 快捷键说明

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