Exemplo n.º 1
0
    def connect_and_disconnect(
            self,
            connect_spec,
            disconnect_spec,
            multiconnect_mode=enums.MulticonnectMode.DEFAULT,
            operation_order=enums.OperationOrder.AFTER,
            wait_for_debounce=True):
        r'''connect_and_disconnect

        Connects routes and disconnects routes in a similar fashion to
        connect and disconnect except that the operations happen in
        the context of a single method call. This method is useful for
        switching from one state to another state. connect_and_disconnect
        manipulates the hardware connections and disconnections only when the
        routes are different between the connection and disconnection
        specifications. If any routes are common between the connection and
        disconnection specifications, NI Switch Executive determines whether or
        not the relays need to be switched. This functionality has the distinct
        advantage of increased throughput for shared connections, because
        hardware does not have to be involved and potentially increases relay
        lifetime by decreasing the number of times that the relay has to be
        switched. In the event of an error, the call to
        connect_and_disconnect attempts to undo any connections made, but
        does not attempt to reconnect disconnections. Some errors can be caught
        before manipulating hardware, although it is feasible that a hardware
        call could fail causing some connections to be momentarily closed and
        then reopened.

        Args:
            connect_spec (str): String describing the connections to be made. The route specification
                strings are best summarized as a series of routes delimited by
                ampersands. The specified routes may be route names, route group names,
                or fully specified route paths delimited by square brackets. Some
                examples of route specification strings are: MyRoute MyRouteGroup
                MyRoute & MyRouteGroup [A->Switch1/r0->B] MyRoute & MyRouteGroup &
                [A->Switch1/r0->B] Refer to Route Specification Strings in the NI Switch
                Executive Help for more information.

            disconnect_spec (str): String describing the disconnections to be made. The route specification
                strings are best summarized as a series of routes delimited by
                ampersands. The specified routes may be route names, route group names,
                or fully specified route paths delimited by square brackets. Some
                examples of route specification strings are: MyRoute MyRouteGroup
                MyRoute & MyRouteGroup [A->Switch1/r0->B] MyRoute & MyRouteGroup &
                [A->Switch1/r0->B] Refer to Route Specification Strings in the NI Switch
                Executive Help for more information.

            multiconnect_mode (enums.MulticonnectMode): This value sets the connection mode for the method. The mode might be
                one of the following: NISE_VAL_USE_DEFAULT_MODE (-1) - uses the mode
                selected as the default for the route in the NI Switch Executive virtual
                device configuration. If a mode has not been selected for the route in
                the NI Switch Executive virtual device, this parameter defaults to
                NISE_VAL_MULTICONNECT_ROUTES. NISE_VAL_NO_MULTICONNECT (0) -
                routes specified in the connection specification must be disconnected
                before they can be reconnected. Calling Connect on a route that was
                connected using No Multiconnect mode results in an error condition.
                NISE_VAL_MULTICONNECT_ROUTES (1) - routes specified in the connection
                specification can be connected multiple times. The first call to Connect
                performs the physical hardware connection. Successive calls to Connect
                increase a connection reference count. Similarly, calls to Disconnect
                decrease the reference count. Once it reaches 0, the hardware is
                physically disconnected. This behavior is slightly different with SPDT
                relays. For more information, refer to the Exclusions and SPDT Relays
                topic in the NI Switch Executive Help. Multiconnecting routes applies to
                entire routes and not to route segments.

                Note:
                One or more of the referenced values are not in the Python API for this driver. Enums that only define values, or represent True/False, have been removed.

            operation_order (enums.OperationOrder): Sets the order of the operation for the method. Defined values are
                Break Before Make and Break After Make. NISE_VAL_BREAK_BEFORE_MAKE
                (1) - The method disconnects the routes specified in the disconnect
                specification before connecting the routes specified in the connect
                specification. This is the typical mode of operation.
                NISE_VAL_BREAK_AFTER_MAKE (2) - The method connects the routes
                specified in the connection specification before connecting the routes
                specified in the disconnection specification. This mode of operation is
                normally used when you are switching current and want to ensure that a
                load is always connected to your source. The order of operation is to
                connect first or disconnect first.

                Note:
                One or more of the referenced values are not in the Python API for this driver. Enums that only define values, or represent True/False, have been removed.

            wait_for_debounce (bool): Waits (if true) for switches to debounce between its connect and
                disconnect operations. If false, it immediately begins the second
                operation after completing the first. The order of connect and
                disconnect operation is set by the Operation Order input.

        '''
        if type(multiconnect_mode) is not enums.MulticonnectMode:
            raise TypeError('Parameter mode must be of type ' +
                            str(enums.MulticonnectMode))
        if type(operation_order) is not enums.OperationOrder:
            raise TypeError('Parameter mode must be of type ' +
                            str(enums.OperationOrder))
        vi_ctype = _visatype.ViSession(self._vi)  # case S110
        connect_spec_ctype = ctypes.create_string_buffer(
            connect_spec.encode(self._encoding))  # case C020
        disconnect_spec_ctype = ctypes.create_string_buffer(
            disconnect_spec.encode(self._encoding))  # case C020
        multiconnect_mode_ctype = _visatype.ViInt32(
            multiconnect_mode.value)  # case S130
        operation_order_ctype = _visatype.ViInt32(
            operation_order.value)  # case S130
        wait_for_debounce_ctype = _visatype.ViBoolean(
            wait_for_debounce)  # case S150
        error_code = self._library.niSE_ConnectAndDisconnect(
            vi_ctype, connect_spec_ctype, disconnect_spec_ctype,
            multiconnect_mode_ctype, operation_order_ctype,
            wait_for_debounce_ctype)
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=False,
                            is_error_handling=False)
        return
Exemplo n.º 2
0
    def connect(self,
                connect_spec,
                multiconnect_mode=enums.MulticonnectMode.DEFAULT,
                wait_for_debounce=True):
        r'''connect

        Connects the routes specified by the connection specification. When
        connecting, it may allow for multiconnection based on the
        multiconnection mode. In the event of an error, the call to
        connect will attempt to undo any connections made so that the
        system will be left in the same state that it was in before the call was
        made. Some errors can be caught before manipulating hardware, although
        it is feasible that a hardware call could fail causing some connections
        to be momentarily closed and then reopened. If the wait for debounce
        parameter is set, the method will not return until the switch system
        has debounced.

        Args:
            connect_spec (str): String describing the connections to be made. The route specification
                strings are best summarized as a series of routes delimited by
                ampersands. The specified routes may be route names, route group names,
                or fully specified route paths delimited by square brackets. Some
                examples of route specification strings are: MyRoute MyRouteGroup
                MyRoute & MyRouteGroup [A->Switch1/r0->B] MyRoute & MyRouteGroup &
                [A->Switch1/r0->B] Refer to Route Specification Strings in the NI Switch
                Executive Help for more information.

            multiconnect_mode (enums.MulticonnectMode): This value sets the connection mode for the method. The mode might be
                one of the following: NISE_VAL_USE_DEFAULT_MODE (-1) - uses the mode
                selected as the default for the route in the NI Switch Executive virtual
                device configuration. If a mode has not been selected for the route in
                the NI Switch Executive virtual device, this parameter defaults to
                NISE_VAL_MULTICONNECT_ROUTES. NISE_VAL_NO_MULTICONNECT (0) -
                routes specified in the connection specification must be disconnected
                before they can be reconnected. Calling Connect on a route that was
                connected using No Multiconnect mode results in an error condition.
                NISE_VAL_MULTICONNECT_ROUTES (1)- routes specified in the connection
                specification can be connected multiple times. The first call to Connect
                performs the physical hardware connection. Successive calls to Connect
                increase a connection reference count. Similarly, calls to Disconnect
                decrease the reference count. Once it reaches 0, the hardware is
                physically disconnected. Multiconnecting routes applies to entire routes
                and not to route segments.

                Note:
                One or more of the referenced values are not in the Python API for this driver. Enums that only define values, or represent True/False, have been removed.

            wait_for_debounce (bool): Waits (if true) for switches to debounce between its connect and
                disconnect operations. If false, it immediately begins the second
                operation after completing the first. The order of connect and
                disconnect operation is set by the Operation Order input.

        '''
        if type(multiconnect_mode) is not enums.MulticonnectMode:
            raise TypeError('Parameter mode must be of type ' +
                            str(enums.MulticonnectMode))
        vi_ctype = _visatype.ViSession(self._vi)  # case S110
        connect_spec_ctype = ctypes.create_string_buffer(
            connect_spec.encode(self._encoding))  # case C020
        multiconnect_mode_ctype = _visatype.ViInt32(
            multiconnect_mode.value)  # case S130
        wait_for_debounce_ctype = _visatype.ViBoolean(
            wait_for_debounce)  # case S150
        error_code = self._library.niSE_Connect(vi_ctype, connect_spec_ctype,
                                                multiconnect_mode_ctype,
                                                wait_for_debounce_ctype)
        errors.handle_error(self,
                            error_code,
                            ignore_warnings=False,
                            is_error_handling=False)
        return