|
Sample for GPIB-1, PCIGPIB-1, USB-GPIB-1
|
Sample Source for Lotus Notes
| |
' gpib.bas : Sample project for using Lotus Notes with the GPIB-1, PCIGPIB and USB GPIB Modules ' ' Author: Michael Reimer, QUANCOM Informationssysteme GmbH, Germany ' ' Website: http://www.quancom.de ' ' Information: ' ' When installing the QLIB ( QUANCOM Driver Library ) you will find the QLIB.NSF ' Lotus Sample Database in the folder d:\program files\quancom\qlib32\gpib\lotus . ' ' To use the QLIB Commands in your source, do the following: ' Step 0: Install the QLIB ( QUANCOM Driver Library ) ' Step 1: Copy Script Library "qlib" to your database ' Step 2: Add Statement Use "qlib" to section Globals->Options ' ' Change the address to the appropriate address for your ' device ( normally set by DIP-Switches on the back side ) ' ' ------------------------------------------------------------------ ' PART 1: Writing a string to a GPIB / HPIB / IEEE488 DMM ( The DMM ' is a listener ) from Lotus Notes. ' 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. ' ------------------------------------------------------------------
Sub SendString() Dim ws As New NotesUIWorkspace Dim uidoc As NotesUiDocument Dim nDevice As Long Dim nListener As Long Dim s As String Dim handle As Long Dim result As Long Dim nCardID As Integer Dim CardName As String Dim Listener As String Set uidoc = ws.CurrentDocument CardName = uidoc.FieldGetText("SelectedCard") If ( CardName = "") Then Msgbox "Please select the GPIB Card!" ,16,"Error" Exit Sub End If ' QLIB supports up to 8 GPIB Controller nDevice = Val(Right$(CardName, 1)) If (Instr(CardName, "PCIGPIB")) Then nCardID = PCIGPIB Elseif (Instr(CardName, "USBGPIB")) Then nCardID = USBGPIB Else nCardID = GPIB End If ' Retrieve Listener Address Listener = uidoc.FieldGetText("Listener") nListener = Val(Right$(Listener, 2)) ' Retrieve Text to send to the GPIB Device s = uidoc.FieldGetText("StringToSend") handle = QAPIExtOpenCard(nCardID, nDevice) If (handle <> 0) Then result = QAPIExtWriteString(handle, nListener, s, Len(s), 0) If (result) Then ' data send to gpib device Else ' failure Msgbox "Failure sending data!", 16, "Information" End If End If End Sub
' ------------------------------------------------------------------ ' PART 2: Reading a GPIB / IEEE-488 / HPIB Device from Lotus Notes ' ' 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. '
Sub ReadString() Dim ws As New NotesUIWorkspace Dim uidoc As NotesUiDocument Dim nDevice As Long Dim nListener As Long Dim s As String Dim handle As Long Dim result As Long Dim nCardID As Integer Dim CardName As String Dim Listener As String Set uidoc = ws.CurrentDocument CardName = uidoc.FieldGetText("SelectedCard") If ( CardName = "") Then Msgbox "Please select the GPIB Card!" ,16,"Error" Exit Sub End If ' QLIB supports up to 8 GPIB Controller nDevice = Val(Right$(CardName, 1)) If (Instr(CardName, "PCIGPIB")) Then nCardID = PCIGPIB Elseif (Instr(CardName, "USBGPIB")) Then nCardID = USBGPIB Else nCardID = GPIB End If ' Retrieve Listener Address Listener = uidoc.FieldGetText("Talker") nListener = Val(Right$(Listener, 2)) ' Create string buffer s = Space$(256) handle = QAPIExtOpenCard(nCardID, nDevice) If (handle <> 0) Then result = QAPIExtReadString(handle, nListener, s, Len(s), 0) If (result) Then ' data successfully read from gpib device Call uidoc.FieldSetText("String", s) Else ' failure Msgbox "Failure reading data!", vbInformation, "Information" End If End If End Sub
' ------------------------------------------------------------------ ' PART3: 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. ' ------------------------------------------------------------------
Sub ReadSRQ() Dim ws As New NotesUIWorkspace Dim uidoc As NotesUiDocument Dim nDevice As Long Dim nListener As Long Dim s As String Dim handle As Long Dim result As Long Dim nCmd As Long Dim nCardID As Integer Dim CardName As String Dim Listener As String Set uidoc = ws.CurrentDocument CardName = uidoc.FieldGetText("SelectedCard") If ( CardName = "") Then Msgbox "Please select the GPIB Card!" ,16,"Error" Exit Sub End If ' QLIB supports up to 8 GPIB Controller nDevice = Val(Right$(CardName, 1)) If (Instr(CardName, "PCIGPIB")) Then nCardID = PCIGPIB Elseif (Instr(CardName, "USBGPIB")) Then nCardID = USBGPIB Else nCardID = GPIB End If handle = QAPIExtOpenCard(nCardID, nDevice) If (handle <> 0) Then result = QAPIExtSpecial(handle, JOB_READSRQ, 0, 0) If (result = 0) Then Msgbox "No service requested",16,"Info" Else Msgbox "Device has requested service ( SRQ )",16,"Info" End If End If End Sub
' ------------------------------------------------------------------ ' PART4: 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. ' ------------------------------------------------------------------ ' Sub SerialPoll() Dim ws As New NotesUIWorkspace Dim uidoc As NotesUiDocument Dim nDevice As Long Dim nListener As Long Dim s As String Dim handle As Long Dim result As Long Dim pollbyte As Long Dim nCardID As Integer Dim CardName As String Dim Listener As String Set uidoc = ws.CurrentDocument CardName = uidoc.FieldGetText("SelectedCard") If ( CardName = "") Then Msgbox "Please select the GPIB Card!" ,16,"Error" Exit Sub End If ' QLIB supports up to 8 GPIB Controller nDevice = Val(Right$(CardName, 1)) If (Instr(CardName, "PCIGPIB")) Then nCardID = PCIGPIB Elseif (Instr(CardName, "USBGPIB")) Then nCardID = USBGPIB Else nCardID = GPIB End If ' Retrieve Listener Address Listener = uidoc.FieldGetText("Listener2") nListener = Val(Right$(Listener, 2)) ' Create string buffer s = Space$(256) handle = QAPIExtOpenCard(nCardID, nDevice) If (handle <> 0) Then result = QAPIExtSpecialSP(handle, JOB_SERIALPOLL, nListener, pollbyte) If (result) Then ' data successfully read from gpib device Call uidoc.FieldSetText("String2", "Hex: " & Hex(Val(pollbyte)) & " Dec: " & (Val(pollbyte))) Else ' failure Msgbox "Failure reading data!", vbInformation, "Information" End If End If End Sub
' ------------------------------------------------------------------ ' PART5: 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. ' ------------------------------------------------------------------
Sub SendCommand() Dim ws As New NotesUIWorkspace Dim uidoc As NotesUiDocument Dim nDevice As Long Dim nListener As Long Dim s As String Dim handle As Long Dim result As Long Dim nCmd As Long Dim nCardID As Integer Dim CardName As String Dim Listener As String Dim CommandName As String Set uidoc = ws.CurrentDocument CardName = uidoc.FieldGetText("SelectedCard") CommandName = uidoc.FieldGetText("CommandList") If ( CardName = "") Then Msgbox "Please select the GPIB Card!" ,16,"Error" Exit Sub End If ' QLIB supports up to 8 GPIB Controller nDevice = Val(Right$(CardName, 1)) If (Instr(CardName, "PCIGPIB")) Then nCardID = PCIGPIB Elseif (Instr(CardName, "USBGPIB")) Then nCardID = USBGPIB Else nCardID = GPIB End If ' Retrieve Listener Address Listener = uidoc.FieldGetText("Listener3") nListener = Val(Right$(Listener, 2)) handle = QAPIExtOpenCard(nCardID, nDevice) If (handle <> 0) Then Select Case Left$( CommandName,3) Case "GTL": nCmd = JOB_GTL Case "SDC": nCmd = JOB_SDC Case "GET": nCmd = JOB_GET Case "LLO": nCmd = JOB_LLO Case "DCL": nCmd = JOB_DCL End Select result = QAPIExtSpecial(handle, nCmd, nListener, 0) If (result) Then ' cmd successfully send to gpib device Else ' failure Msgbox "Failure sending command!", vbInformation, "Information" End If End If End Sub
|
|
|