# Function Reference

# _viOpen

Opens a VISA connection to an Instrument/Device

#include <Visa.au3>
_viOpen ( $sVisa_Address [, $sVisa_Secondary_Address = 0] )

## Parameters

$sVisa_Address | A VISA resource descriptor STRING (see the NOTES of _viExecCommand() above for more info) As shortcut you can also directly pass a GPIB address as an integer
$sVisa_Secondary_Address | [optional] The "secondary GPIB address". Only used if the primary address is passed as an integer. Only some GPIB instruments have secondary addresses. In those cases this optional parameter can be used to specify it. This parameter is ZERO by default, which means NO SECONDARY ADDRESS.

## Return Value

Success: | a (POSITIVE) VISA Instrument Handle.
Failure: | -1 and sets the @error flag to non-zero.

## Remarks

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, _viFindGpib, _viGpibBusReset, _viGTL, _viSetAttribute, _viSetTimeout

## Example

    ; - This assumes that you have instrument set to GPIB address 1
    ; It shows how to use the _viExecCommand function in stand alone mode and combined
    ; with _viOpen and _viClose.
    ; It also shows the _viGTL function

    #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", "Open the instrument connection with _viOpen")
    Local $h_Instr = _viOpen("GPIB::3::0")
    MsgBox($MB_SYSTEMMODAL, "Instrument Handle obtained", "$h_Instr = " & $h_Instr) ; Show the Session Handle
    ; Query the instrument

    MsgBox($MB_SYSTEMMODAL, "Step 2", "Query the instrument using the VISA instrument handle")
    Local $s_Answer = _viExecCommand($h_Instr, "*IDN?") ; $h_Instr is NOT A STRING now!
    MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer) ; Show the answer
    ; Query again. There is no need to OPEN the link again

    MsgBox($MB_SYSTEMMODAL, "Step 3", "Query again. There is no need to OPEN the link again")
    $s_Answer = _viExecCommand($h_Instr, "*IDN?")
    MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer) ; Show the answer

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

    MsgBox($MB_SYSTEMMODAL, "Step 5", "Open the Instrument connection using only the address number")
    $h_Instr = _viOpen(3)
    MsgBox($MB_SYSTEMMODAL, "Instrument Handle obtained", "$h_Instr = " & $h_Instr) ; Show the Session Handle
    ; Query the instrument

    MsgBox($MB_SYSTEMMODAL, "Step 6", "Query the instrument using the VISA instrument handle")
    $s_Answer = _viExecCommand($h_Instr, "*IDN?") ; $h_Instr is NOT A STRING now!
    MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer) ; Show the answer
    ; Query again. There is no need to OPEN the link again

    MsgBox($MB_SYSTEMMODAL, "Step 7", "Query again. There is no need to OPEN the link again")
    $s_Answer = _viExecCommand($h_Instr, "*IDN?")
    MsgBox($MB_SYSTEMMODAL, "GPIB QUERY result", $s_Answer) ; Show the answer

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