# Function Reference

# _viSetTimeout

Sets the VISA timeout in MILISECONDS

#include <Visa.au3>
_viSetTimeout ( $hSession, $iTimeoutMS )

## Parameters

$hSession | A VISA descriptor (STRING) OR a VISA session handle (INTEGER). See the Remarks of the _viExecCommand() for more info.
$iTimeoutMS | The timeout IN MILISECONDS for VISA operations (mainly for GPIB queries) If you set it to 0 the tiemouts are DISABLED. If you set it to "INF" the VISA operations will NEVER timeout. Be careful with this as it could easly hung your program ifv your instrument does not respond to one of your queries. Depending on the bus type (GPIB, TCP, etc) the timeout might not be set to the exact value that you request. Instead the closest valid timeout bigger than the one that you requested will be used.

## 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

Most of the time it is not necessary to call this function, as _viExecCommand() has a third OPTIONAL parameter $iTimeoutMS which can also be used to set the VISA timeout.
As for all the VISA functions the VISA libraries must be installed (you can check whether visa32.dll is in {WINDOWS}\system32) and a GPIB card (such as a National Instruments NI PCI-GPIB card or an Agilent 82350B PCI High-Performance GPIB card) must be installed
* 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, _viSetAttribute

## 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 _viExecCommand function with a timeout or how to
    ; call _viSetTimeout instead.

    #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 _viSetTimeout function first:
    MsgBox($MB_SYSTEMMODAL, "Step 2", "_vOpen + timeout using _viSetTimeout + GPIB query")
    Local $h_Instr = _viOpen(3)
    _viSetTimeout($h_Instr, 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