
245
Chapter 6 Application Programs
Example Programs for Excel 7.0
4
6
Option Explicit
’ Declarations for VISA.DLL
’ Basic I/O Operations
Private Declare Function viOpenDefaultRM Lib "VISA32.DLL" Alias "#141" (sesn As Long) As Long
Private Declare Function viOpen Lib "VISA32.DLL" Alias "#131" (ByVal sesn As Long, _
ByVal desc As String, ByVal mode As Long, ByVal TimeOut As Long, vi As Long) As Long
Private Declare Function viClose Lib "VISA32.DLL" Alias "#132" (ByVal vi As Long) As Long
Private Declare Function viRead Lib "VISA32.DLL" Alias "#256" (ByVal vi As Long, _
ByVal Buffer As String, ByVal Count As Long, retCount As Long) As Long
Private Declare Function viWrite Lib "VISA32.DLL" Alias "#257" (ByVal vi As Long, _
ByVal Buffer As String, ByVal Count As Long, retCount As Long) As Long
’ Error Codes
Global Const VI_SUCCESS = 0
’ Global Variables
Global videfaultRM As Long
’ Resource manager id for VISA GPIB
Global vi As Long
’ Stores the session for VISA
Dim errorStatus As Long
’ VTL error code
Global VISAaddr As String
’"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
’ This routine requires the file ’VISA32.DLL’ which typically resides in the
’ c:\windows\system directory on your PC. This routine uses the VTL Library to send
’ commands to the instrument. A description of these and additional VTL commands can be
’ found in the Agilent VISA User’s Guide.
’"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Public Sub SendSCPI(SCPICmd As String)
’ This routine sends a SCPI command string to the GPIB port. If the command is a
’ query command (contains a question mark), you must read the response with ’getScpi’
Dim commandstr As String
’ Command passed to instrument
Dim actual As Long
’ Number of characters sent/returned
’Write the command to the instrument terminated by a line feed
commandstr = SCPICmd & Chr$(10)
errorStatus =
viWrite(vi, ByVal commandstr, Len(commandstr), actual)
End Sub
Function getScpi() As String
Dim readbuf As String * 2048
’ Buffer used for returned string
Dim replyString As String
’ Store the string returned
Dim nulpos As Integer
’ Location of any nul’s in readbuf
Dim actual As Long
’ Number of characters sent/returned
’ Read the response string
errorStatus =
viRead(vi, ByVal readbuf, 2048, actual)
replyString = readbuf
’ Strip out any nul’s from the response string
nulpos = InStr(replyString, Chr$(0))
If nulpos Then
replyString = Left(replyString, nulpos - 1)
End If
getScpi
=
replyString
End Function
Continued on next page
Excel 7.0 Example:
Port Configuration Macro
34970A Refresh UG.book Page 245 Wednesday, February 17, 2010 12:34 PM
Содержание 34970A
Страница 16: ...16 34970A Refresh UG book Page 16 Wednesday February 17 2010 12 34 PM ...
Страница 20: ...34970A Refresh UG book Page 20 Wednesday February 17 2010 12 34 PM ...
Страница 21: ...1 1 Quick Start 34970A Refresh UG book Page 21 Wednesday February 17 2010 12 34 PM ...
Страница 39: ...2 2 Front Panel Overview 34970A Refresh UG book Page 39 Wednesday February 17 2010 12 34 PM ...
Страница 59: ...3 3 System Overview 34970A Refresh UG book Page 59 Wednesday February 17 2010 12 34 PM ...
Страница 87: ...4 4 Features and Functions 34970A Refresh UG book Page 87 Wednesday February 17 2010 12 34 PM ...
Страница 217: ...5 5 Error Messages 34970A Refresh UG book Page 217 Wednesday February 17 2010 12 34 PM ...
Страница 240: ...240 Chapter 5 Error Messages Plug In Module Errors 34970A Refresh UG book Page 240 Wednesday February 17 2010 12 34 PM ...
Страница 241: ...6 6 Application Programs 34970A Refresh UG book Page 241 Wednesday February 17 2010 12 34 PM ...
Страница 254: ...254 34970A Refresh UG book Page 254 Wednesday February 17 2010 12 34 PM ...
Страница 255: ...7 7 Tutorial 34970A Refresh UG book Page 255 Wednesday February 17 2010 12 34 PM ...
Страница 324: ...324 34970A Refresh UG book Page 324 Wednesday February 17 2010 12 34 PM ...