Chapter 7 Application Programs

Example Programs for Excel 7.0

Excel 7.0 Example: Port Configuration Macro

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 HP VISA User’s Guide (part number E2090-90029). ’"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Public Sub SendSCPI(SCPICmd As String)

This routine sends a SCPI command string to the HP-IB 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 Dim replyString As String Dim nulpos As Integer

Dim actual As Long

Buffer used for returned string

Store the string returned

Location of any nul’s in readbuf

Number of characters sent/returned

’ Read the response string

 

errorStatus = viRead(vi, ByVal readbuf, 2048, actual)

7

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

323