Function Reference


_viSetAttribute

Set any VISA attribute This function, which is called by _viSetTimeout, can ALSO be used to set the other VISA specific attributes. Read the VISA documentation for more information and a list of VISA attributes and their corresponding values

#include <Visa.au3>
_viSetAttribute ( $hSession, $iAttribute, $iValue )

Parameters

$hSession A VISA descriptor (STRING) OR a VISA session handle (INTEGER).
See the Remarks of the _viExecCommand() for more info.
$iAttribute The index of the attribute that must be changed.
Attributes are defined in the VISA library.
This AutoIt library only defines a CONSTANT for the TIMEOUT attribute ($VI_ATTR_TMO_VALUE) and for the Serial Interface attributes and values (see the remarks) but you can pass any other valid index (as an integer) if you want to.
$iValue The value of the attribute. It must be an integer and the possible values depend on the attribute type and are defined in the VISA documentation.

Return Value

Success: 0.
Failure: -1 and sets the @error flag to non-zero if the VISA DLL could not be open
or a NON ZERO value representing the VISA error code (see the VISA programmer's guide).

Remarks

This is a list of the currently pre-defined attributes and values. Remember that you can use any other valid attribute/value by passing the corresponding integer index (as defined in the VISA programmer's guide) to this function.

* Attribute: $VI_ATTR_TMO_VALUE -> Set Timeout
* Values:
    A timeout in MILLISECONDS or
    $VI_TMO_IMMEDIATE (or 0) for "Return immediatly"
    VI_TMO_INFINITE (or "INF") for "No timeout"

* Attribute: $VI_ATTR_ASRL_BAUD
* Values:
    Any valid baudrate (9600, 115200, etc)

* Attribute: $VI_ATTR_ASRL_DATA_BITS
* Values:
    From 5 to 8

* Attribute: $VI_ATTR_ASRL_PARITY
* Values:
    $VI_ASRL_PAR_NONE
    $VI_ASRL_PAR_ODD
    $VI_ASRL_PAR_EVEN
    $VI_ASRL_PAR_MARK
    $VI_ASRL_PAR_SPACE

* Attribute: $VI_ATTR_ASRL_STOP_BITS
* Values:
    $VI_ASRL_STOP_ONE
    $VI_ASRL_STOP_ONE5
    $VI_ASRL_STOP_TWO

* Attribute: $VI_ATTR_ASRL_FLOW_CNTRL
* Values:
    $VI_ASRL_FLOW_NONE
    $VI_ASRL_FLOW_XON_XOFF
    $VI_ASRL_FLOW_RTS_CTS
    $VI_ASRL_FLOW_DTR_DSR

As for all the VISA functions the VISA libraries must be installed (you can check whether visa32.dll is in {WINDOWS}\system32).
You onlly need a GPIB card (such as a National Instruments NI PCI-GPIB card or an Agilent 82350B PCI High-Performance GPIB card) if you use the GPIB related functions.

* For a detailed description of the most common VISA DESCRIPTORS look at the Remarks of the help on the _viExecCommand() function

Related

_viClose, _viExecCommand, _viOpen, _viSetTimeout

Example

; - This assumes that you have instrument set to GPIB address 3.
; If you have an instrument in a different address change "GPIB::3::0" to the
; corresponding descriptor. Do the same for the call to _viOpen
; It shows how to use the _viSetAttribute. In this example we use _viSetAttribute
; instead of _viSetTimeout to set the GPIB timeout of a _viExecCommand operation.

#include <MsgBoxConstants.au3>
#include <Visa.au3>

Local $h_Session = 0

; Query the ID of the instrument in GPIB address 3
MsgBox($MB_SYSTEMMODAL, "Step 1", "Simple GPIB query with explicit TIMEOUT set")
Local $s_Answer = _viExecCommand("GPIB::3::0", "*IDN?", 10000) ; 10 secs timeout
MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer) ; Show the answer

; This is the same as using the _viSetAttribute function first:
MsgBox($MB_SYSTEMMODAL, "Step 2", "_vOpen + timeout using _viSetAttribute + GPIB query")
Local $h_Instr = _viOpen(3)
; NOTE - This is the same as: _viSetTimeout($h_Instr, 10000)
_viSetAttribute($h_Instr, $VI_ATTR_TMO_VALUE, 10000) ; 10000 ms = 10 secs

$s_Answer = _viExecCommand($h_Instr, "*IDN?") ; No need to set the timeout now
MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer) ; Show the answer

MsgBox($MB_SYSTEMMODAL, "Step 3", "Close the Instrument connection using _viClose")
_viClose($h_Instr) ; Close the instrument connection