Navigate Up
Sign In
 
 

IEEE-488 Interface Program in Visual Basic

GPIB Board Installation

This procedure works for Plug and Play GPIB Hardware and Software for Windows 98/95. This example used the AT-GPIB/TNT GPIB card.

Setup

1.  Install the GPIB Plug and Play Software and Hardware using National Instruments instructions.

2.  Verify that the following files have been installed to the Windows System folder:

a.  gpib-32.dll

b.  gpib.dll

c.  gpib32ft.dll

(Files b and c will support 16-bit Windows GPIB applications if any are being used.)

3.  Locate the following files and make note of their location. These files will be used during the development process of a Visual Basic program.

a.  Niglobal.bas

b.  Vbib-32.bas

 

NOTE: If the files in steps 2 and 3 are not installed on your computer, they may be copied from the National Instruments setup disks or they may be downloaded from www.ni.com.

Configuration

Configure the GPIB by selecting the System icon in the Windows 98/95 Control Panel located under Settings on the Start Menu. Configure the GPIB Settings as shown in Figure 1. Configure the DEV12 Device Template as shown in Figure 2.

 

GPIB Setting Configuration 

Figure 1. GPIB Setting Configuration

 

DEV12 Device Template Configuration 

Figure 2. DEV12 Device Template Configuration

 

Visual Basic IEEE-488 Interface Program Setup

The IEEE-488 interface program works with Visual Basic 6.0 (VB6) on an IBM PC (or compatible) with a Pentium-class processor. A Pentium 90 or higher is recommended, running Windows 95 or better. It assumes your IEEE-488 (GPIB) card is installed and operating correctly. Use the following procedure to develop the IEEE-488 Interface Program in Visual Basic.

 

1.  Start VB6.

2.  Choose Standard EXE and select Open.

3.  Resize form window to desired size.

4.  On the Project Menu, select Add Module, select the Existing tab, then navigate to the location on your computer to add the following files: Niglobal.bas and Vbib-32.bas.

5.  Add controls to form:

a.  Add three Label controls to the form.

b.  Add two TextBox controls to the form.

c.  Add one CommandButton control to the form.

6.  On the View Menu, select Properties Window.

7.  In the Properties window, use the dropdown list to select between the different controls of the current project.

 

Figure 3 

 

8.  Set the properties of the controls as defined in Table 1.

9.  Save the program.

 

Table 1. Serial Interface Program Control Properties

Current Name

Property

New Value

Label1

Name

Caption

lblExitProgram

Type "exit" to end program.

Label2

Name

Caption

lblCommand

Command

Label3

Name

Caption

lblResponse

Response

Text1

Name

Text

txtCommand

<blank>

Text2

Name

Text

txtResponse

<blank>

Command1

Name

Caption

Default

cmdSend

Send

True

Form1

Name

Caption

frmIEEE

IEEE Interface Program

 

10.  Add code (provided in Table 2).

a.  In the Code Editor window, under the Object dropdown list, select (General). Add the statement: Public gSend as Boolean

b.  Double Click on cmdSend. Add code segment under Private Sub cmdSend_Click( ) as shown in Table 2.

c.  In the Code Editor window, under the Object dropdown list, select Form. Make sure the Procedure dropdown list is set at Load.
The Code window should have written the segment of code: Private Sub Form_Load( ). Add the code to this subroutine as shown in Table 2.

11.  Save the program.

12.  Run the program. The program should resemble the following.

 

Figure 4 

 

13.  Type a command query as described in your instrument User's Manual, in the chapter called Remote Interface.

14.  Press Enter or select the Send button with the mouse to send command.

15.  Type Exit and press Enter to quit.

 

 

Table 2. Visual Basic IEEE-488 Interface Program. See GPIB_VB.TXT.

Public gSend As Boolean                                     'Global used for Send button state

Private Sub cmdSend_Click()                                 'Routine to handle Send button press

    gSend = True                                            'Set Flag to True

End Sub

Private Sub Form_Load()                                     'Main code section

    Dim strReturn As String                                 'Used to return response

    Dim term As String                                      'Terminators

    Dim strCommand As String                                'Data string sent to instrument

    Dim intDevice As Integer                                'Device number used with IEEE

   

    frmIEEE.Show                                            'Show main window

    term = Chr(13) & Chr(10)                                'Terminators are <CR><LF>

    strReturn = ""                                          'Clear return string

   

    Call ibdev(0, 12, 0, T10s, 1, &H140A, intDevice)        'Initialize the IEEE device

    Call ibconfig(intDevice, ibcREADDR,1)                   'Setup Repeat Addressing

    Do

        Do                                                  'Wait loop

        DoEvents                                            'Give up processor to other events

        Loop Until gSend = True                             'Loop until Send button pressed

        gSend = False                                       'Set Flag as False

       

        strCommand = frmIEEE.txtCommand.Text                'Get Command

        strReturn = ""                                      'Clear response display

       

        strCommand = UCase(strCommand)                      'Set all characters to upper case

        If strCommand = "EXIT" Then                         'Get out on EXIT

            End

        End If

       

        Call ibwrt(intDevice, strCommand & term)            'Send command to instrument

        If (ibsta And EERR) Then                            'Check for IEEE errors

            'do error handling if needed                    'Handle errors here

        End If

       

        If InStr(strCommand, "?") <> 0 Then                 'Check to see if query

            strReturn = Space(100)                          'Build empty return buffer

            Call ibrd(intDevice, strReturn)                 'Read back response

            If (ibsta And EERR) Then                        'Check for IEEE errors

                'do error handling if needed                'Handle errors here

            End If

           

            If strReturn <> "" Then                         'Check if empty string

                strReturn = RTrim(strReturn)                'Remove extra spaces & terminators

                Do While Right(strReturn, 1) = Chr(10) Or Right(strReturn, 1) = Chr(13)

                    strReturn = Left(strReturn, Len(strReturn) - 1)

                Loop

            Else

                strReturn = "No Response"                   'Send No Response

            End If

           

            frmIEEE.txtResponse.Text = strReturn            'Put response in text on main form

        End If

    Loop

End Sub