Sample for GPIB-1, PCIGPIB-1, USB-GPIB-1  

Sample Source for Visual-Basic


  ' gpib.bas : Sample project for the GPIB-1, PCIGPIB and USB GPIB Modules
'
' Author: Michael Reimer, QUANCOM Informationssysteme GmbH, Germany
'
' Website: http://www.quancom.de
'
' Product:
' GPIB PCI Controller http://www.quancom.de/qprod01/eng/pb/pcigpib_1.htm
' GPIB ISA Controller http://www.quancom.de/qprod01/eng/pb/GPIB_1.htm
' GPIB USB Controller http://www.quancom.de/qprod01/eng/pb/usb_gpib_1.htm
'
' Information:
'
' To use the QLIB Commands in your source, do the following:
' (1) Install the QLIB ( QUANCOM Driver Libarary )
' (2) Add module "qlib.bas" to your project.
'

Sub Main()

Dim s As String
Dim handle As Long
Dim result As Long
Dim register As Integer
Dim nCardID As Integer
Dim nListener As Long
Dim serial_poll_byte As Long

' The following sequence tries to find the
' Bus Type ( PCI, ISA or USB ) of the
' installed GPIB Controller
         
handle = QAPIExtOpenCard(PCIGPIB, 0)

If (handle = 0) Then

    handle = QAPIExtOpenCard(GPIB, 0)

    If (handle = 0) Then

       handle = QAPIExtOpenCard(USBGPIB, 0)

   End If

End If

If (handle = 0) Then
  MsgBox "Unable to find GPIB Controller Card!", 16, "Error"
  Exit Sub
End If

' Ok, we found a QUANCOM GPIB Controller Card
'
' Now we can send a string to the listner with address 3
' Change the address to the appropriate address for your
' device ( normally set by DIP-Switches on the back side )
'
' ---------------------------------------------------------------------------
' PART 1a: Writing a string to the DMM ( The DMM is a the listener )
'
' Listener: A device capable of receiving data over the interface
' when addressed to Listen by the active controller. Examples of such
' devices are printers, programmable power supplies, or any other
' programmable instrument. There can be up to 14 Listeners on the GPIB Bus
' at one time.
' ---------------------------------------------------------------------------
'
' Select the listener address, which is set by a DIP-Switch on the
' back side of your instrument.
'

nListener = 3
s = "z"

' Send "z" to the listner 3, which resets the DMM to the initial settings.

result = QAPIExtWriteString(handle, nListener, s, Len(s), 0)
 
If (result) Then
    ' data send to gpib device
Else
    ' failure
    MsgBox "Failure sending data!", vbInformation, "Information"
End If

' ---------------------------------------------------------------------------
' PART 1b: Reading a DMM ( The DMM is a talker )
'
' Talker: A device capable of transmitting data over the interface when
' addressed to talk by the active controller. Examples of such devices
' are voltmeters, data-acquisition systems, or any other programmable
' instrument. There can be only one addressed talker on the GPIB Bus at one
' time.
' ---------------------------------------------------------------------------
'
' Select the talker address, which is set by a DIP-Switch on the
' back side of your instrument.
'
nListener = 3
s = Space$(1024) ' create buffer 1024 chars
'
' Read value from DMM with talker address 3

result = QAPIExtReadString(handle, nListener, s, Len(s), 0)
 
If (result) Then
    ' data successfully read from gpib device
     
    MsgBox "Read from device " & nListener & " String " & s
     
Else
    ' failure
    MsgBox "Failure reading data!", vbInformation, "Information"
End If

' ---------------------------------------------------------------------------
' PART2: Checking whether a device has requested service ( SRQ Service Request)
'
' A device can interrupt the active controller by asserting the SRQ line. The
' SRQ is a single line, and if there are multiple devices on the GPIB Bus that
' have been configured to assert an SRQ, the active controller will have
' to "poll" the devices to figure out which one actually asserted the SRQ.
' More than one device could in principle assert an SRQ at the same time. The
' active controller can poll the devices in one of two ways: serial poll
' or parallel poll.
' ---------------------------------------------------------------------------

result = QAPIExtSpecial(handle, JOB_READSRQ, 0, 0)

If (result = 0) Then
      MsgBox "No service requested", 16, "Information"
Else
      MsgBox "Device has requested service ( SRQ )", 16, "Information"
End If

' ---------------------------------------------------------------------------
' PART3: Reading Serial Poll Status from DMM
'
' In a serial poll, the active controller asks each device in turn to
' send back a status byte that indicates whether the device has asserted
' the SRQ. Bit 6 of this byte (where the bits are numbered 0 through 7) is set
' if the device is requesting service. The definition of the other bits
' is device dependent (under 488.1 at least; 488.2 provides a much more
' concise definition of the status byte).
'
' The program has to perform this same sequence with every device
' it needs to poll.
' ---------------------------------------------------------------------------
'
' We poll all devices from 1 to 15 here. This is normally not nescessary and
' very time consuming. Poll only valid devices on the GPIB Bus.

serial_poll_byte = 0

For nListener = 1 To 15

result = QAPIExtSpecialSP(handle, JOB_SERIALPOLL, nListener, serial_poll_byte)
 
  If (result) Then
     ' data successfully read from gpib device
     MsgBox "Serial poll from device " & nListener & " returns = " & Val(serial_poll_byte)
  Else
     ' failure
     MsgBox "Failure reading data!", vbInformation, "Information"
  End If

Next nListener

' ---------------------------------------------------------------------------
' PART4: Send a command to DMM
'
' The following commands are accepted by all devices on the GPIB Bus
' simultaneously. The address part will be ignored.
'
' - JOB_DCL (Device Clear): The DCL command causes all devices to return to a device
'   dependent initial state.
'
' - JOB_LLO (Local Lockout): The LLO command disables the return-to-local front
'   panel key on the device. The user can no longer change the device settings
'   from its front panel.
'
' The following commands need an address and are only accepted by addressed
' devices. Whether the devices are the listeners or the talkers depends on the
' command. The three commands are as follows:
'
' - JOB_GET (Group Execute Trigger): The GET command tells all the addressed
'   listeners to perform some device-dependent function, like take a measurement.
'   GET allows for synchronizing a measurement function between multiple devices.
'   This is only used in specialized cases.
'
' - JOB_SDC (Selected Device Clear): The SDC command resets the addressed listeners
'   to a device-dependent state. It performs the same function as DCL,
'   but only resets the addressed listeners, not all the devices.
'
' - JOB_GTL (Go To Local): The GTL command sets the addressed listeners back to
'   local mode.
' ---------------------------------------------------------------------------

' Send DCL to all devices

result = QAPIExtSpecial(handle, JOB_DCL, 1, 0)

If (Not result) Then
  MsgBox "Command DCL failed!", 16, "Information"
End If

' Send LLO to all devices

result = QAPIExtSpecial(handle, JOB_LLO, 1, 0)

If (Not result) Then
  MsgBox "Command LLO failed!", 16, "Information"
End If

' Send GET to device 3

result = QAPIExtSpecial(handle, JOB_GET, 3, 0)

If (Not result) Then
  MsgBox "Command GET failed!", 16, "Information"
End If

' Send SDC to device 3

result = QAPIExtSpecial(handle, JOB_SDC, 3, 0)

If (Not result) Then
  MsgBox "Command SDC failed!", 16, "Information"
End If

' Send GTL to device 3

result = QAPIExtSpecial(handle, JOB_GTL, 3, 0)

If (Not result) Then
  MsgBox "Command GTL failed!", 16, "Information"
End If

QAPIExtCloseCard (handle)

End Sub

Private Sub Form_Load()
Call Main
End Sub