Home Forums HTBasic Forum HTBasic and visa32.Ddll

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9086
    Cariou Mathieu
    Participant

      Hi,
      I use HTBasic 10.1 i would like to use visa library by loading the visa32 DLL.

      The issue :
      The HTBasic software crashes as soon as the first DLL function is called (ViGetDefaultRM()). It doesnt go until PRINT “Status Value after exiting from ViOpenDefaultRM :”;Statusvisa

      Does anyone have an idea about this issue ?

      My configuration :
      Windows 10 IOT LTSC 64bit
      HT Basic 10.1
      visa32.dll from NI-VISA Version 2023 Q2

      The HTBasic code :
      LONG Statusvisa ! Visa Status Code Variable
      LONG Defaultrm ! Unique ID of Default Ressource Manager Session

      !********************************************
      ! LOADING OF VISA (visa32.dll)
      !********************************************
      DLL UNLOAD ALL
      DLL LOAD “visa32”

      DLL GET “LONG visa32:viGetDefaultRM” AS “Vigetdefaultrm”
      DLL GET “LONG visa32:viOpenDefaultRM” AS “Viopendefaultrm”
      DLL GET “LONG visa32:viOpen” AS “Viopen”
      DLL GET “LONG visa32:viClose” AS “Viclose”
      DLL GET “LONG visa32:viSetAttribute” AS “Visetattribute”
      DLL GET “LONG visa32:viRead” AS “Viread”

      PRINT “———————————————————”
      PRINT ” LOADED FUNCIONS OF THE VISA DRIVER ”
      PRINT “———————————————————”
      LIST DLL

      PRINT “—————————”
      PRINT ” START ”
      PRINT “—————————”

      Statusvisa=FNViopendefaultrm(Defaultrm)
      PRINT “Status Value after exiting from ViOpenDefaultRM :”;Statusvisa
      Statusvisa=Viclose((Defaultrm))
      DLL UNLOAD “visa32”
      END

      Thank you
      Best
      Mathieu

      #9087
      ZeRider
      Participant

        Hi Mathieu,
        Do you want to test this?

        LONG Retour
        LONG Session

        !———————————————————
        Default: ! VI Open Default RM
        !———————————————————
        DISP “—> VI OPEN DEFAULT RM : In progress …”
        !
        DLL GET “STDCALL LONG VISA32:viOpenDefaultRM” AS “Vi_open_default” ! Function
        !
        Retour=-1000
        Retour=FNVi_open_default(Session)
        !
        SELECT Retour
        CASE 0
        PRINT “> VI OPEN DEFAULT RM”
        PRINT “VIsession =”;Session
        CASE ELSE
        Type$=”DEC”
        Valeur$=VAL$(Retour)
        CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
        PRINT “* VI OPEN DEFAULT RM : Retour=”;Retour
        CALL List_error(Hex$)
        END SELECT

        With the two SUB below … :

        SUB Convert(Type$,Valeur$,Dec,Hex$,Bin$)!*********************************
        Convert: ! Conversion DEC/HEX/BIN
        !*********************************
        SELECT Type$
        CASE “DEC”
        Dec=VAL(Valeur$) ! DECIMAL
        Hex$=DVAL$(Dec,16) ! DEC2HEX [8]
        Bin$=DVAL$(Dec,2) ! DEC2BIN [32]
        CASE “HEX”
        Hex$=Valeur$ ! HEXADECIMAL
        Bin$=DVAL$(DVAL(Hex$,16),2)! HEX2BIN [32]
        Dec=DVAL(Hex$,16) ! HEX2DEC [8]
        CASE “BIN”
        ALLOCATE B$[32]
        Bin$=Valeur$ ! BINAIRE
        B$=Bin$ !
        IF LEN(Bin$)<16 THEN B$=RPT$(“0”,16-LEN(Bin$))&Bin$
        IF VAL(B$)>10000001 THEN B$=RPT$(“1”,15)&B$
        Dec=DVAL(B$,2) ! BIN2DEC
        Hex$=DVAL$(DVAL(Bin$,2),16)! BIN2HEX [8]
        Hex$=Hex$[5,8] !
        DEALLOCATE B$
        END SELECT
        Exit: !
        SUBEND
        !
        SUB List_error(Hex$)!***************************************************
        List_error: !
        ! Liste d’erreurs extraites du document “NI-VISAProgrammersManual.pdf”
        !
        ALLOCATE Code$[80],Value$[80],Meaning$[200]
        !
        N: DATA “VI_SUCCESS”,”0″,”Operation completed successfully”
        DATA “VI_SUCCESS_EVENT_EN”,”3FFF0002″,”Specified event is already enabled for at least one of the specified mechanisms”
        DATA “VI_SUCCESS_EVENT_DIS”,”3FFF0003″,”Specified event is already disabled for at least one of the specified mechanisms”
        DATA “VI_SUCCESS_QUEUE_EMPTY”,”3FFF0004″,”Operation completed successfully but queue was already empty”
        DATA “VI_SUCCESS_TERM_CHAR”,”3FFF0005″,”The specified termination character was read”
        DATA “VI_SUCCESS_MAX_CNT”,”3FFF0006″,”The number of bytes read is equal to the input count”
        DATA “VI_WARN_CONFIG_NLOADED”,”3FFF0077″,”The specified configuration either does not exist or could not be loaded using VISA-specified defaults”
        DATA “VI_SUCCESS_DEV_NPRESENT”,”3FFF007D”,”Session opened successfully but the device at the specified address is not responding”
        DATA “VI_SUCCESS_TRIG_MAPPED”,”3FFF007E”,”The path from trigSrc to trigDest is already mapped”
        DATA “VI_SUCCESS_QUEUE_NEMPTY”,”3FFF0080″,”Wait terminated successfully on receipt of an event notification There is still at least one more event occurrence of the requested type(s) available for this session”
        DATA “VI_WARN_NULL_OBJECT”,”3FFF0082″,”The specified object reference is uninitialized”
        DATA “VI_WARN_NSUP_ATTR_STATE”,”3FFF0084″,”Although the specified state of the attribute is valid it is not supported by this resource implementation”
        DATA “VI_WARN_UNKNOWN_STATUS”,”3FFF0085″,”The status code passed to the operation could not be interpreted”
        DATA “VI_WARN_NSUP_BUF”,”3FFF0088″,”The specified buffer is not supported”
        DATA “VI_SUCCESS_NCHAIN”,”3FFF0098″,”Event handled successfully Do not invoke any other handlers on this session for this event”
        DATA “VI_SUCCESS_NESTED_SHARED”,”3FFF0099″,”Operation completed successfully and this session has nested shared locks”
        DATA “VI_SUCCESS_NESTED_EXCLUSIVE”,”3FFF009A”,”Operation completed successfully and this session has nested exclusive locks”
        DATA “VI_SUCCESS_SYNC”,”3FFF009B”,”Asynchronous operation request was actually performed synchronously”
        DATA “VI_ERROR_SYSTEM_ERROR”,”BFFF0000″,”Unknown system error (miscellaneous error)”
        DATA “VI_ERROR_INV_OBJECT”,”BFFF000E”,”The given session or object reference is invalid”
        DATA “VI_ERROR_RSRC_LOCKED”,”BFFF000F”,”Specified type of lock cannot be obtained or specified operation cannot be performed because the resource is locked”
        DATA “VI_ERROR_INV_EXPR”,”BFFF0010″,”Invalid expression specified for search”
        DATA “VI_ERROR_RSRC_NFOUND”,”BFFF0011″,”Insufficient location information or the device or resource is not present in the system”
        DATA “VI_ERROR_INV_RSRC_NAME”,”BFFF0012″,”Invalid resource reference specified Parsing error”
        DATA “VI_ERROR_INV_ACC_MODE”,”BFFF0013″,”Invalid access mode”
        DATA “VI_ERROR_TMO”,”BFFF0015″,”Timeout expired before operation completed”
        DATA “VI_ERROR_CLOSING_FAILED”,”BFFF0016″,”Unable to deallocate the previously allocated data structures corresponding to this session or object reference”
        DATA “VI_ERROR_INV_DEGREE”,”BFFF001B”,”Specified degree is invalid”
        DATA “VI_ERROR_INV_JOB_ID”,”BFFF001C”,”Specified job identifier is invalid”
        DATA “VI_ERROR_NSUP_ATTR”,”BFFF001D”,”The specified attribute is not defined or supported by the referenced session or event or find list”
        DATA “VI_ERROR_NSUP_ATTR_STATE”,”BFFF001E”,”The specified state of the attribute is not valid or is not supported as defined by the session or event or find list”
        DATA “VI_ERROR_ATTR_READONLY”,”BFFF001F”,”The specified attribute is read-only”
        DATA “VI_ERROR_INV_LOCK_TYPE”,”BFFF0020″,”The specified type of lock is not supported by this resource”
        DATA “VI_ERROR_INV_ACCESS_KEY”,”BFFF0021″,”The access key to the resource associated with this session is invalid”
        DATA “VI_ERROR_INV_EVENT”,”BFFF0026″,”Specified event type is not supported by the resource”
        DATA “VI_ERROR_INV_MECH”,”BFFF0027″,”Invalid mechanism specified”
        DATA “VI_ERROR_HNDLR_NINSTALLED”,”BFFF0028″,”A handler is not currently installed for the specified event”
        DATA “VI_ERROR_INV_HNDLR_REF”,”BFFF0029″,”The given handler reference is invalid”
        DATA “VI_ERROR_INV_CONTEXT”,”BFFF002A”,”Specified event context is invalid”
        DATA “VI_ERROR_QUEUE_OVERFLOW”,”BFFF002D”,”The event queue for the specified type has overflowed (usually due to previous events not having been closed)”
        DATA “VI_ERROR_NENABLED”,”BFFF002F”,”The session must be enabled for events of the specified type in order to receive them”
        DATA “VI_ERROR_ABORT”,”BFFF0030″,”The operation was aborted”
        DATA “VI_ERROR_RAW_WR_PROT_VIOL”,”BFFF0034″,”Violation of raw write protocol occurred during transfer”
        DATA “VI_ERROR_RAW_RD_PROT_VIOL”,”BFFF0035″,”Violation of raw read protocol occurred during transfer”
        DATA “VI_ERROR_OUTP_PROT_VIOL”,”BFFF0036″,”Device reported an output protocol error during transfer”
        DATA “VI_ERROR_INP_PROT_VIOL”,”BFFF0037″,”Device reported an input protocol error during transfer”
        DATA “VI_ERROR_BERR”,”BFFF0038″,”Bus error occurred during transfer”
        DATA “VI_ERROR_IN_PROGRESS”,”BFFF0039″,”Unable to queue the asynchronous operation because there is already an operation in progress”
        DATA “VI_ERROR_INV_SETUP”,”BFFF003A”,”Unable to start operation because setup is invalid (due to attributes being set to an inconsistent state)”
        DATA “VI_ERROR_QUEUE_ERROR”,”BFFF003B”,”Unable to queue asynchronous operation”
        DATA “VI_ERROR_ALLOC”,”BFFF003C”,”Insufficient system resources to perform necessary memory allocation”
        DATA “VI_ERROR_INV_MASK”,”BFFF003D”,”Invalid buffer mask specified”
        DATA “VI_ERROR_IO”,”BFFF003E”,”Could not perform operation because of I/O error”
        DATA “VI_ERROR_INV_FMT”,”BFFF003F”,”A format specifier in the format string is invalid”
        DATA “VI_ERROR_NSUP_FMT”,”BFFF0041″,”A format specifier in the format string is not supported”
        DATA “VI_ERROR_LINE_IN_USE”,”BFFF0042″,”The specified trigger line is currently in use”
        DATA “VI_ERROR_NSUP_MODE”,”BFFF0046″,”The specified mode is not supported by this VISA implementation”
        DATA “VI_ERROR_SRQ_NOCCURRED”,”BFFF004A”,”Service request has not been received for the session”
        DATA “VI_ERROR_INV_SPACE”,”BFFF004E”,”Invalid address space specified”
        DATA “VI_ERROR_INV_OFFSET”,”BFFF0051″,”Invalid offset specified”
        DATA “VI_ERROR_INV_WIDTH”,”BFFF0052″,”Invalid source or destination width specified”
        DATA “VI_ERROR_NSUP_OFFSET”,”BFFF0054″,”Specified offset is not accessible from this hardware”
        DATA “VI_ERROR_NSUP_VAR_WIDTH”,”BFFF0055″,”Cannot support source and destination widths that are different”
        DATA “VI_ERROR_WINDOW_NMAPPED”,”BFFF0057″,”The specified session is not currently mapped”
        DATA “VI_ERROR_RESP_PENDING”,”BFFF0059″,”A previous response is still pending causing a multiple query error”
        DATA “VI_ERROR_NLISTENERS”,”BFFF005F”,”No Listeners condition is detected (both NRFD and NDAC are deasserted)”
        DATA “VI_ERROR_NCIC”,”BFFF0060″,”The interface associated with this session is not currently the controller in charge”
        DATA “VI_ERROR_NSYS_CNTLR”,”BFFF0061″,”The interface associated with this session is not the system controller”
        DATA “VI_ERROR_NSUP_OPER”,”BFFF0067″,”The given session or object reference does not support this operation”
        DATA “VI_ERROR_INTR_PENDING”,”BFFF0068″,”An interrupt is still pending from a previous call”
        DATA “VI_ERROR_ASRL_PARITY”,”BFFF006A”,”A parity error occurred during transfer”
        DATA “VI_ERROR_ASRL_FRAMING”,”BFFF006B”,”A framing error occurred during transfer”
        DATA “VI_ERROR_ASRL_OVERRUN”,”BFFF006C”,”An overrun error occurred during transfer A character was not read from the hardware before the next character arrived”
        DATA “VI_ERROR_TRIG_NMAPPED”,”BFFF006E”,”The path from trigSrc to trigDest is not currently mapped”
        DATA “VI_ERROR_NSUP_ALIGN_OFFSET”,”BFFF0070″,”The specified offset is not properly aligned for the access width of the operation”
        DATA “VI_ERROR_USER_BUF”,”BFFF0071″,”A specified user buffer is not valid or cannot be accessed for the required size”
        DATA “VI_ERROR_RSRC_BUSY”,”BFFF0072″,”The resource is valid but VISA cannot currently access it”
        DATA “VI_ERROR_NSUP_WIDTH”,”BFFF0076″,”Specified width is not supported by this hardware”
        DATA “VI_ERROR_INV_PARAMETER”,”BFFF0078″,”The value of some parameter—which parameter is not known—is invalid”
        DATA “VI_ERROR_INV_PROT”,”BFFF0079″,”The protocol specified is invalid”
        DATA “VI_ERROR_INV_SIZE”,”BFFF007B”,”Invalid size of window specified”
        DATA “VI_ERROR_WINDOW_MAPPED”,”BFFF0080″,”The specified session currently contains a mapped window”
        DATA “VI_ERROR_NIMPL_OPER”,”BFFF0081″,”The given operation is not implemented”
        DATA “VI_ERROR_INV_LENGTH”,”BFFF0083″,”Invalid length specified”
        DATA “VI_ERROR_INV_MODE”,”BFFF0091″,”The specified mode is invalid”
        DATA “VI_ERROR_SESN_NLOCKED”,”BFFF009C”,”The current session did not have any lock on the resource”
        DATA “VI_ERROR_MEM_NSHARED”,”BFFF009D”,”The device does not export any memory”
        DATA “VI_ERROR_LIBRARY_NFOUND”,”BFFF009E”,”A code library required by VISA could not be located or loaded”
        DATA “VI_ERROR_NSUP_INTR”,”BFFF009F”,”The interface cannot generate an interrupt on the requested level or with the requested statusID value”
        DATA “VI_ERROR_INV_LINE”,”BFFF00A0″,”The value specified by the line parameter is invalid”
        DATA “VI_ERROR_FILE_ACCESS”,”BFFF00A1″,”An error occurred while trying to open the specified file Possible reasons include an invalid path or lack of access rights”
        DATA “VI_ERROR_FILE_IO”,”BFFF00A2″,”An error occurred while performing I/O on the specified file”
        DATA “VI_ERROR_NSUP_LINE”,”BFFF00A3″,”One of the specified lines (trigSrc or trigDest) is not supported by this VISA implementation or the combination of lines is not a valid mapping”
        DATA “VI_ERROR_NSUP_MECH”,”BFFF00A4″,”The specified mechanism is not supported by the given event type”
        DATA “VI_ERROR_INTF_NUM_NCONFIG”,”BFFF00A5″,”The interface type is valid but the specified interface number is not configured”
        DATA “VI_ERROR_CONN_LOST”,”BFFF00A6″,”The connection for the given session has been lost”
        DATA “VI_ERROR_MACHINE_NAVAIL”,”BFFF00A7″,”The remote machine does not exist or is not accepting any connections”
        DATA “VI_ERROR_NPERMISSION”,”BFFF00A8″,”Access to the remote machine is denied”
        RESTORE N
        !
        !
        ON ERROR GOTO Exit! Error Not Found in the list …
        I=0
        Value$=”NotFound”
        !
        PRINT “Value = “;Hex$
        !
        WHILE Value$<>Hex$
        READ Code$,Value$,Meaning$
        I=I+1
        END WHILE
        !
        PRINT “ERROR CODE (“&VAL$(I)&”) : “;Code$
        PRINT “Meaning : “;Meaning$
        !
        Exit: OFF ERROR
        SUBEND

        #9088
        Cariou Mathieu
        Participant

          Hi Mr ZeRider,

          Thank you very much !
          It seems like everything is ok now since i put “STDCALL” at the DLL GET section as you proposed.
          I’m not sure what STDCALL is about as i didn’t see that in the software DLL example. However it is mentionned in the software documentation at that page : DLL GET but i don’t realy see when to use it or not.

          Here below is the code i used for getting informations from a tcpip connected instrument. It is inspired by ZeRider code in the previous post !

          Best
          Mathieu
          !************
          ! Example
          !**********
          LONG Retour ! Status code
          LONG Session ! Unique logical ID to a default Ressource Manager Session
          LONG Instru ! Unique logical ID to a session
          LONG Ret_count ! Represent an integer that will be set to the number of byte actually transferred (From viWrite and viRead() From “VISA Library Specification” document)
          DIM Rep$[100] ! Represent the buffer to receive data from device. (From viRead() from “VISA Library Specification” document)

          DIM Connex$[64]
          Connex$=”TCPIP0::instrumentIPAddress::inst0::INSTR” ! Connexion parameters

          DLL UNLOAD ALL

          DLL LOAD “visa32”
          DLL GET “STDCALL LONG VISA32:viOpenDefaultRM” AS “Vi_open_default” ! Function from VISA DLL
          DLL GET “STDCALL LONG VISA32:viOpen” AS “Vi_open” ! Function from VISA DLL
          DLL GET “STDCALL LONG VISA32:viClose” AS “Vi_close” ! Function from VISA DLL
          DLL GET “STDCALL LONG VISA32:viWrite” AS “Vi_write” ! Function from VISA DLL
          DLL GET “STDCALL LONG VISA32:viRead” AS “Vi_read” ! Function from VISA DLL
          DLL GET “STDCALL LONG VISA32:viGetAttribute” AS “Vi_get_att” ! Function from VISA DLL

          !———————————————————
          Default: ! VI Open Default RM
          !———————————————————
          DISP “—> VI OPEN DEFAULT RM : In progress …”

          !********************************************

          Retour=-1000
          Retour=FNVi_open_default(Session)

          SELECT Retour
          CASE 0
          PRINT “> VI OPEN DEFAULT RM”
          PRINT “VIsession =”;Session
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI OPEN DEFAULT RM : Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          !———————————————————
          Viopen: ! VI Open SESSION
          !———————————————————

          DISP “—> VI OPEN SESSION: In progress …”

          Retour=-1000
          Retour=FNVi_open((Session),Connex$,0,0,Instru)

          SELECT Retour
          CASE 0
          PRINT “> VI OPEN SESSION”
          PRINT “Instru =”;Instru
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI OPEN SESSION: Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          !———————————————————
          Viwrite: ! VI Write CMD
          !———————————————————

          DISP “—> VI Write CMD: In progress …”
          Retour=-1000

          Cmd_count=6 ! Nbr of byte to be writter
          Retour=FNVi_write((Instru),”*IDN?”,6,Ret_count)

          SELECT Retour
          CASE 0
          PRINT “> VI WRITE ”
          PRINT “Instru =”;Instru
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI WRITE : Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          !———————————————————
          Viread: ! VI Read response
          !———————————————————

          DISP “—> VI Read : In progress …”
          Retour=-1000

          Retour=FNVi_read((Instru),Rep$,100,Ret_count)
          PRINT “IDN : “;Rep$

          SELECT Retour
          CASE 0
          PRINT “> VI READ ”
          PRINT “Instru =”;Instru
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI READ : Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          !———————————————————
          Vigetattribute: ! VI Get IP Address Attribute
          !———————————————————

          DISP “—> VI Get IP Address attribute : In progress …”
          Retour=-1000

          LONG Decval=DVAL(“bfff0195”,16) ! Decimal value of VI_ATTR_TCPIP_ADDR 0xBFFF0195
          Retour=FNVi_get_att((Instru),(Decval),Rep$)
          PRINT “IP Address : “;Rep$

          SELECT Retour
          CASE 0
          PRINT “> VI GET IP ADDRESSE ATTRIBUTE ”
          PRINT “Instru =”;Instru
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI GET ATTRIBUTE : Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          !———————————————————
          Viclose_instru: ! VI Close Instru
          !———————————————————

          DISP “—> VI CLOSE SESSION: In progress …”
          Retour=-1000
          Retour=FNVi_close((Instru))

          SELECT Retour
          CASE 0
          PRINT “> VI CLOSE SESSION ”
          PRINT “Instru =”;Instru
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI CLOSE SESSION : Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          !———————————————————
          Viclose_session: ! VI Close Session
          !———————————————————

          DISP “—> VI CLOSE DEFAULT RM : In progress …”
          Retour=-1000
          Retour=FNVi_close((Session))

          SELECT Retour
          CASE 0
          PRINT “> VI CLOSE DEFAULT RM ”
          PRINT “Session =”;Session
          CASE ELSE
          Type$=”DEC”
          Valeur$=VAL$(Retour)
          CALL Convert(Type$,Valeur$,Dec,Hex$,Bin$)
          PRINT “* VI VI CLOSE DEFAULT RM : Retour=”;Retour
          CALL List_error(Hex$)
          END SELECT

          DISP “—-> All is closed ”
          END

          ! To use this code, add the two SUBs proposed by ZeRider at the previous post

          #9089
          ZeRider
          Participant

            Great, I’m glad everything is working now !!!
            Good job Mathieu

            #9111
            PatB
            Moderator

              The latest released version of HTBasic 2021 now contains a native VISA driver. This can be loaded in Device Setup and will allow you to communicate with instruments natively in HTBasic using standard ENTER and OUTPUT statements, greatly simplifying your programming.

            Viewing 5 posts - 1 through 5 (of 5 total)
            • You must be logged in to reply to this topic.
            Scroll to Top
            HTB icon

            Please Sign In