# Opening a switch handle

A switch handle identifies a switch block on an open MVIP switching device. swiOpenSwitch opens a switching device and creates a context
for subsequent switching calls. The handle is used to refer to the switch block in the Switching service functions.

A switch handle is always associated with a context. When you specify a switch handle, the context is implied, as shown in the following illustration:

To open a switch handle:

- Specify MVIP-90 mode or MVIP-95 mode

- Enable terminus output state restoration

Natural Access services can share contexts and service object handles
. Therefore, you can share open switch handles by using ctaAttachObject on a shared context. Refer to the Natural Access Developer's Reference Manual for more information.

## Specifying MVIP-95 or MVIP-90 mode

Switch handles can be opened in the MVIP-95 mode or in the MVIP-90 mode.

In MVIP-95 mode, the terminus
arguments to the Switching service functions are interpreted as MVIP-95 bus, stream, and timeslot values. MVIP-95 is the default mode.

If the underlying device driver is an MVIP-95 device driver, the switch can be opened only in the default mode (MVIP-95).

Caution: | Since MVIP-95 device drivers can be opened only in MVIP-95 mode, NMS recommends writing all applications that may use MVIP-95 device drivers in the future to use MVIP-95 mode even if the application is not currently using MVIP-95 device drivers.

If the underlying device driver is an MVIP-95 device driver or an MVIP-90 device driver and the SWI_MVIP90 constant is used as a parameter to swiOpenSwitch, the switch is opened as an MVIP-90 switch. The terminus streams and timeslots
are interpreted as MVIP-90 streams and timeslots. The bus field of the terminus is ignored.

If the underlying device driver is an MVIP-90 device driver, and the switch was opened in MVIP-95 mode, the Switching service translates the MVIP-95 terminus parameters into the appropriate MVIP-90 streams and timeslots before passing the commands down to the MVIP-90 device driver.

## Enabling terminus output state restoration

When the SWI_ENABLE_RESTORE constant is used as a parameter to swiOpenSwitch, the states of the switch block outputs are saved so that they can be restored when the switch handle is closed using swiCloseSwitch. If you want to use the SWI_ENABLE_RESTORE mode, a single terminus should not be controlled by more than one switch handle. Otherwise, a terminus affected by your application might be restored to a condition set by another application or to a condition set through a different switch handle in your own application.

swiResetSwitch cannot be called if the switch handle is opened with the SWI_ENABLE_RESTORE constant enabled.