GPIB NI interfacing

For issues with communication ports, protocols, etc.
MikeAEL
Posts: 6
Joined: Oct 09, 2009 10:47
Location: London

GPIB NI interfacing

Postby MikeAEL » Nov 02, 2016 11:41

Hi All
After updating from 0.90.1 to 1.05.0, my NI GPIB card is not seeing any instruments.
No errors are being displayed.
Any help would be greatly appreciated.

Also can't see where the instructions are to add programs as a code.

****** More info added to problem *******
RUN NIspy in the background which scans all GPIB commands sent/received comparing the working version

ibfind(gpib0) 'This is the working version.

ibfind(4 random ascii characters) 'This is incorrect.

***********************************

Code: Select all

'Program.BAS below
'-----------------------------------------------------------------------------
'Put the following files in the same directory:
'        FB_GPIB_DMM_TEST.bas
'        FB_Niglobal_17.bi
'
' The NI file: gpib-32.dll should be in C:\WINDOWS\SYSTEM32.
'Compile with: fbc -s console -lang fb -w pedantic
'Compiler version: fbc v.017b (or greater)
'Configure HP34401A DMM for GPIB:03 and SCPI language
'-----------------------------------------------------------------------------0
#Include Once "FB_Niglobal_17.bi"

Const MAXREADLOOP = 20
Const RD_STR_LEN = 64
Dim As String s_cmd, s_key, s_rd = Space(64)
Dim sz_rd As String*RD_STR_LEN
Dim As Integer brd0,dev,GPIBrtn
Dim As Double VOC
'-----------------------------------------------------------------------------0
'NI library routines from GPIB-32.DLL
'-----------------------------------------------------------------------------0
Dim Shared hndl As Any Ptr
Dim Shared ibfind32 As Function(Byval sstr As String) As Long
Dim Shared ibrd32 As Function(Byval ud As Long,Byval sstr As String, Byval cnt As Long) As Long
Dim Shared ibwrt32 As Function(Byval ud As Long,Byval sstr As String, Byval cnt As Long) As Long
Dim Shared ibonl32 As Function(Byval ud As Long, Byval v As Long) As Long
Dim Shared ibclr32 As Function(Byval ud As Long) As Long
'-----------------------------------------------------------------------------0
'get a handle for gpib-32
        hndl = dylibload( "gpib-32" )
        If( hndl = 0 ) Then
                Print "Cannot load the h_ni dynamic library, aborting program..."
                'If you see this message, gpib-32.dll wasn't available
                Sleep
                End 1
        End If
       
'get a pointer in h_ni.dll to function ibfindA and alias to 'ibfind32'
ibfind32 = dylibsymbol( hndl, "ibfindA" )               
        If( ibfind32 = 0 ) Then
                Print "Cannot initialize library function 'ibfind32', aborting program..."
                Sleep
                End 1
        End If
        ibrd32  = dylibsymbol(hndl, "ibrd")
        ibwrt32 = dylibsymbol(hndl, "ibwrt")
        ibonl32 = dylibsymbol(hndl, "ibonl")
        ibclr32 = dylibsymbol(hndl, "ibclr")

'-----------------------------------------------------------------------------0
'GPIB INTERFACE INITIALIZATION
        brd0 = ibfind32("gpib0")               'Find the GPIB Controller [32000]
        GPIBrtn = ibonl32(brd0, 1)             'Add to agree with NIspy
        dev = ibfind32("DEV3")                 'Find instrument at DEV addr:nn

'-----------------------------------------------------------------------------0
'DMM INITIALIZATION
  IBCLR32 (dev)
  s_cmd = "*idn?"
  GPIBrtn = ibwrt32(dev, s_cmd,Len(s_cmd))
  GPIBrtn = ibrd32(dev, s_rd,Len(s_rd))
  Print "RDG >";(s_rd);"<"
  print
  If Instr(s_rd, "3500") Then
                Print "34401A found."
  Else
                print "NIGPIB488.BAS v1"       
                print
                Print "HP34401A NOT FOUND."
                Print "Sleeping ... Any key to Exit"
                Sleep
                End
  End if
 
        s_cmd = "conf:volt:dc min,max"
        GPIBrtn = ibwrt32(dev, s_cmd,Len(s_cmd))                                                                 'HP Volt function

'Check DMM for error messages.       
        s_cmd = "syst:err?"
        GPIBrtn = ibwrt32(dev, s_cmd,Len(s_cmd))
        s_rd=Space(64)
        GPIBrtn = ibrd32(dev, s_rd,Len(s_rd))
        Print s_rd

'-----------------------------------------------------------------------------0
'Main
Print "Press Q to quit"
Do
        s_key = Ucase(Inkey)       
        s_cmd = "init;fetc?"
        GPIBrtn=ibwrt32(dev, s_cmd,Len(s_cmd))
        sz_rd = Space(RD_STR_LEN)
        GPIBrtn = ibrd32(dev, sz_rd,RD_STR_LEN)
        VOC = Val(sz_rd)
        Locate 10, 21
        Print Using "THIS VALUE SHOULD BE ON METER: ##.######^^^^ V"; VOC;
        Sleep 300
Loop Until s_key = "Q"

Print
Print "sleeping...";
Sleep
End

'------------------------



Code: Select all

'FB_NIGLOBAL_17.BI
'------------------------
'FB_NIGLOBAL_17.BI                '''for b v.17+
'Modified for use with FreeBasic
'1. FB has no GLOBAL keyword ... ALL CONSTs are global ... s, GLOBAL prefix to
'''Attribute VB_Name = "NIGLOBAL"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 32-bit Visual Basic Language Interface
' Version 1.8
' Copyright 2001 National Instruments Corporation.
' All Rights Reserved.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   This module contains the variable  declarations,
'   constant definitions, and type information that
'   is recognized by the entire application.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''Option Explicit        '''Not allowed in v.17+

'24MAR2007 make these into global vars '''jr07'''

Dim Shared ibstaa As Integer
Dim Shared iberr As Integer
Dim Shared ibcnt As Integer
Dim Shared ibcntl As Long

' Needed to register for GPIB Global Thread.
Dim Shared Longibsta As Long
Dim Shared Longiberr As Long
Dim Shared Longibcnt As Long
Dim Shared GPIBglobalsRegistered As Integer

Dim Shared buf As String

Dim Shared bytebuf() As Byte

Const UNL = &H3F    ' GPIB unlisten command
Const UNT = &H5F    ' GPIB untalk command
Const GTL = &H1     ' GPIB go to local
Const SDC = &H4     ' GPIB selected device clear
Const PPC = &H5     ' GPIB parallel poll configure
Const GGET = &H8    ' GPIB group execute trigger
Const TCT = &H9     ' GPIB take control
Const LLO = &H11    ' GPIB local lock out
Const DCL = &H14    ' GPIB device clear
Const PPU = &H15    ' GPIB parallel poll unconfigure
Const SPE = &H18    ' GPIB serial poll enable
Const SPD = &H19    ' GPIB serial poll disable
Const PPE = &H60    ' GPIB parallel poll enable
Const PPD = &H70    ' GPIB parallel poll disable

' GPIB status bit vector :
'       status variable ibsta and wait mask

Const EERR = &H8000      ' Error detected
Const TIMO = &H4000      ' Timeout
Const EEND = &H2000      ' EOI or EOS detected
Const SRQI = &H1000      ' SRQ detected by CIC
Const RQS = &H800        ' Device requesting service
Const CMPL = &H100       ' I/O completed
Const LOK = &H80         ' Local lockout state
Const RRem = &H40        ' Remote state
Const CIC = &H20         ' Controller-in-Charge
Const AATN = &H10        ' Attention asserted
Const TACS = &H8         ' Talker active
Const LACS = &H4         ' Listener active
Const DTAS = &H2         ' Device trigger state
Const DCAS = &H1         ' Device clear state

' Error messages returned in global variable iberr

Const EDVR = 0      ' System error
Const ECIC = 1      ' Function requires GPIB board to be CIC
Const ENOL = 2      ' Write function detected no listeners
Const EADR = 3      ' Interface board not addressed correctly
Const EARG = 4      ' Invalid argument to function call
Const ESAC = 5      ' Function requires GPIB board to be SAC
Const EABO = 6      ' I/O operation aborted
Const ENEB = 7      ' Non-existent interface board
Const EDMA = 8      ' DMA Error
Const EOIP = 10     ' I/O operation started before previous
                           ' operation completed
Const ECAP = 11     ' No capability for intended operation
Const EFSO = 12     ' File system operation error
Const EBUS = 14     ' Command error during device call
Const ESTB = 15     ' Serial poll status byte lost
Const ESRQ = 16     ' SRQ remains asserted
Const ETAB = 20     ' The return buffer is full
Const ELCK = 21     ' Address or board is locked
Const EARM = 22     ' ibnotify's asynchronous event
                           ' notification failed to rearm
Const EHDL = 23     ' Invalid GPIB handle type for function
Const WCFG = 24     ' Configuration warning
Const ECFG = 24     ' Configuration warning
Const EWIP = 26     ' Wait already in progress on input ud
Const ERST = 27     ' The event notification was cancelled   
                           ' due to a reset of the interface


' EOS mode bits

'Both BIN and BINARY are keywords in FreeBasic -jr-
'Const BIN = &H1000   ' Eight bit compare
Const XEOS = &H800   ' Send EOI with EOS byte
Const REOS = &H400   ' Terminate read on EOS

' Timeout values and meanings

Const TNONE = 0      ' Infinite timeout (disabled)
Const T10us = 1      ' Timeout of 10 us (ideal)
Const T30us = 2      ' Timeout of 30 us (ideal)
Const T100us = 3     ' Timeout of 100 us (ideal)
Const T300us = 4     ' Timeout of 300 us (ideal)
Const T1ms = 5       ' Timeout of 1 ms (ideal)
Const T3ms = 6       ' Timeout of 3 ms (ideal)
Const T10ms = 7      ' Timeout of 10 ms (ideal)
Const T30ms = 8      ' Timeout of 30 ms (ideal)
Const T100ms = 9     ' Timeout of 100 ms (ideal)
Const T300ms = 10    ' Timeout of 300 ms (ideal)
Const T1s = 11       ' Timeout of 1 s (ideal)
Const T3s = 12       ' Timeout of 3 s (ideal)
Const T10s = 13      ' Timeout of 10 s (ideal)
Const T30s = 14      ' Timeout of 30 s (ideal)
Const T100s = 15     ' Timeout of 100 s (ideal)
Const T300s = 16     ' Timeout of 300 s (ideal)
Const T1000s = 17    ' Timeout of 1000 s (maximum)

' IBLN constants

Const ALL_SAD = -1
Const NO_SAD = 0

' The following constants are used for the second parameter of the
' ibconfig function.  They are the "option" selection codes.

Const IbcPAD = &H1             ' Primary Address
Const IbcSAD = &H2             ' Secondary Address
Const IbcTMO = &H3             ' Timeout Value
Const IbcEOT = &H4             ' Send EOI with last data byte?
Const IbcPPC = &H5             ' Parallel Poll Configure
Const IbcREADDR = &H6          ' Repeat Addressing
Const IbcAUTOPOLL = &H7        ' Disable Auto Serial Polling
Const IbcCICPROT = &H8         ' Use the CIC Protocol?
Const IbcIRQ = &H9             ' Use PIO for I/O
Const IbcSC = &HA              ' Board is System Controller.
Const IbcSRE = &HB             ' Assert SRE on device calls?
Const IbcEOSrd = &HC           ' Terminate reads on EOS.
Const IbcEOSwrt = &HD          ' Send EOI with EOS character.
Const IbcEOScmp = &HE          ' Use 7 or 8-bit EOS compare.
Const IbcEOSchar = &HF         ' The EOS character.
Const IbcPP2 = &H10            ' Use Parallel Poll Mode 2.
Const IbcTIMING = &H11         ' NORMAL, HIGH, or VERY_HIGH timing.
Const IbcDMA = &H12            ' Use DMA for I/O.
Const IbcReadAdjust = &H13     ' Swap bytes during an ibrd.
Const IbcWriteAdjust = &H14    ' Swap bytes during an ibwrt.
Const IbcSendLLO = &H17        ' Enable/disable the sending of LLO.
Const IbcSPollTime = &H18      ' Set the timeout value for serial polls.
Const IbcPPollTime = &H19      ' Set the parallel poll length period
Const IbcEndBitIsNormal = &H1A    ' Remove EOS from END bit of IBSTA.
Const IbcUnAddr = &H1B            ' Enable/disable device unaddressing.
Const IbcSignalNumber = &H1C      ' Set UNIX signal number - unsupported
Const IbcBlockIfLocked = &H1D     ' Enable/disable blocking for locked boards/devices
Const IbcHSCableLength = &H1F     ' Enable/disable high-speed handshaking.
Const IbcIst = &H20               ' Set the IST bit
Const IbcRsv = &H21               ' Set the RSV bit
Const IbcLON = &H22               ' Enable listen only mode.


'   Constants that can be used (in addition to the ibconfig constants)
'   when calling the IBASK function.

Const IbaPAD = &H1             ' Primary Address
Const IbaSAD = &H2             ' Secondary Address
Const IbaTMO = &H3             ' Timeout Value
Const IbaEOT = &H4             ' Send EOI with last data byte?
Const IbaPPC = &H5             ' Parallel Poll Configure
Const IbaREADDR = &H6          ' Repeat Addressing
Const IbaAUTOPOLL = &H7        ' Disable Auto Serial Polling
Const IbaCICPROT = &H8         ' Use the CIC Protocol?
Const IbaIRQ = &H9             ' Use PIO for I/O
Const IbaSC = &HA              ' Board is System Controller.
Const IbaSRE = &HB             ' Assert SRE on device calls?
Const IbaEOSrd = &HC           ' Terminate reads on EOS.
Const IbaEOSwrt = &HD          ' Send EOI with EOS character.
Const IbaEOScmp = &HE          ' Use 7 or 8-bit EOS compare.
Const IbaEOSchar = &HF         ' The EOS character.
Const IbaPP2 = &H10            ' Use Parallel Poll Mode 2.
Const IbaTIMING = &H11         ' NORMAL, HIGH, or VERY_HIGH timing.
Const IbaDMA = &H12            ' Use DMA for I/O.
Const IbaReadAdjust = &H13     ' Swap bytes during an ibrd.
Const IbaWriteAdjust = &H14    ' Swap bytes during an ibwrt.
Const IbaSendLLO = &H17        ' Enable/disable the sending of LLO.
Const IbaSPollTime = &H18      ' Set the timeout value for serial polls.
Const IbaPPollTime = &H19      ' Set the parallel poll length period
Const IbaEndBitIsNormal = &H1A ' Remove EOS from END bit of IBSTA.
Const IbaUnAddr = &H1B         ' Enable/disable device unaddressing.
Const IbaSignalNumber = &H1C   ' Set UNIX signal number - unsupported
Const IbaBlockIfLocked = &H1D  ' Enable/disable blocking for locked boards/devices.
Const IbaHSCableLength = &H1F  ' Enable/disable high-speed handshaking.
Const IbaIst = &H20            ' Set the IST bit
Const IbaRsv = &H21            ' Set the RSV bit
Const IbaLON = &H22            ' Enable listen only mode.
Const IbaBNA = &H200           ' A device's access board.
Const IbaBaseAddr = &H201      ' A GPIB board's base I/O address.
Const IbaDmaChannel = &H202    ' A GPIB board's DMA channel.
Const IbaIrqLevel = &H203      ' A GPIB board's IRQ level.
Const IbaBaud = &H204          ' Baud rate used to communicate to CT box.
Const IbaParity = &H205        ' Parity setting for CT box.
Const IbaStopBits = &H206      ' Stop bits used for communicating to CT.
Const IbaDataBits = &H207      ' Data bits used for communicating to CT.
Const IbaComPort = &H208       ' System COM port used for CT box.
Const IbaComIrqLevel = &H209   ' System COM port's interrupt level.
Const IbaComPortBase = &H20A   ' System COM port's base I/O address.
Const IbaSingleCycleDma = &H20B   ' Does the board use single cycle DMA?
Const IbaSlotNumber = &H20C       ' Board's slot number.
Const IbaLPTNumber = &H20D        ' Parallel port number
Const IbaLPTType = &H20E          ' Parallel port protocol

' These are the values used by the 488.2 Send command

Const NULLend = &H0            ' Do nothing at the end of a transfer
Const NLend = &H1              ' Send NL with EOI after a transfer
Const DABend = &H2             ' Send EOI with the last DAB

' This value is useds by the 488.2 Receive command

Const STOPend = &H100          ' Stop the read on EOI

' The following values are used by the iblines function.  The integer
' returned by iblines contains:
'       The lower byte will contain a "monitor" bit mask.  If a bit
'               is set (1) in this mask, then the corresponding line
'               can be monitored by the driver.  If the bit is clear (0),
'               then the line cannot be monitored.
'       The upper byte will contain the status of the bus lines.
'               Each bit corresponds to a certain bus line, and has
'               a corresponding "monitor" bit in the lower byte.

Const ValidEOI = &H80
Const ValidATN = &H40
Const ValidSRQ = &H20
Const ValidREN = &H10
Const ValidIFC = &H8
Const ValidNRFD = &H4
Const ValidNDAC = &H2
Const ValidDAV = &H1
Const BusEOI = &H8000
Const BusATN = &H4000
Const BusSRQ = &H2000
Const BusREN = &H1000
Const BusIFC = &H800
Const BusNRFD = &H400
Const BusNDAC = &H200
Const BusDAV = &H100

' This value is used to terminate an address list.  It should be
' assigned to the last entry.  (488.2)

Const NOADDR = &HFFFF

' This value is defined for when the GPIBnotify Callback
' has failed to rearm.

Const IBNOTIFY_REARM_FAILED = &HE00A003F

' These constants are for use with iblockx/ibunlockx
' functions for GPIB-ENET

Const TIMMEDIATE = -1
Const TINFINITE = -2
Const MAX_LOCKSHARENAME_LENGTH = 64
 
'------------------------
Last edited by MikeAEL on Nov 02, 2016 15:49, edited 1 time in total.
MrSwiss
Posts: 2021
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: GPIB NI interfacing

Postby MrSwiss » Nov 02, 2016 15:39

@MikeAEL,

please edit your post above and put the code into: [code][/code] brackets.
You can get them by clicking the Code-Button (whilst writing a post).

The referenced NI spec. seems very old, isn't there a more recent one?
MikeAEL
Posts: 6
Joined: Oct 09, 2009 10:47
Location: London

Re: GPIB NI interfacing

Postby MikeAEL » Nov 03, 2016 9:30

Unfortunately I did not write the code. So I am stuck with v0.90.1.
St_W
Posts: 1114
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: GPIB NI interfacing

Postby St_W » Nov 03, 2016 9:43

You are passing FB Strings to that external library, are you sure that this is correct?
I don't know the definition for those DLL function calls, but try to replace String by ZString or ZString Ptr and pass pointers in the second case using StrPtr().

You seem to be using the 32-bit version of the compiler, as the DLL load would fail otherwise, so everything alright regarding that.

I can't spot any other possible issues with the code for now after having a quick look.
MikeAEL
Posts: 6
Joined: Oct 09, 2009 10:47
Location: London

Re: GPIB NI interfacing

Postby MikeAEL » Nov 03, 2016 9:56

I will try as mentioned. Works in 0.90.1 but not in any version greater than.
Thanks for your guidance.
MrSwiss
Posts: 2021
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: GPIB NI interfacing

Postby MrSwiss » Nov 03, 2016 9:58

St_W wrote:You are passing FB Strings to that external library, are you sure that this is correct?
Since it says SCPI, String (better ZString) seems to be correct, at first sight.
Those Integer(s) do look like FB-Short to me (2 Byte Integer) ...
I'll have to check deeper ...
MikeAEL
Posts: 6
Joined: Oct 09, 2009 10:47
Location: London

Re: GPIB NI interfacing

Postby MikeAEL » Nov 03, 2016 10:31

Big thanks. 'Zstring ptr' works. Thanks again for your help.

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest