Skip to content

Connection¤

Connection ¤

Connection(
    address: str,
    *,
    backend: Literal["MSL", "PyVISA", "NIDAQ"] | Backend = MSL,
    eid: str = "",
    manufacturer: str = "",
    model: str = "",
    serial: str = "",
    **properties: Any
)

Information about how to interface with equipment.

Parameters:

Name Type Description Default
address str

The VISA-style address of the connection (see here for examples).

required
backend Literal['MSL', 'PyVISA', 'NIDAQ'] | Backend

The backend to use to communicate with the equipment.

MSL
eid str

The equipment id to associate with the Connection instance.

''
manufacturer str

The name of the manufacturer of the equipment.

''
model str

The model number of the equipment.

''
serial str

The serial number (or unique identifier) of the equipment.

''
properties Any

Additional key-value pairs to use when communicating with the equipment. For example, the baud_rate and parity values for an RS-232 connection.

{}
Source code in src/msl/equipment/schema.py
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
def __init__(
    self,
    address: str,
    *,
    backend: Literal["MSL", "PyVISA", "NIDAQ"] | Backend = Backend.MSL,
    eid: str = "",
    manufacturer: str = "",
    model: str = "",
    serial: str = "",
    **properties: _Any,  # noqa: ANN401
) -> None:
    """Information about how to interface with equipment.

    Args:
        address: The VISA-style address of the connection (see [here][address-syntax] for examples).
        backend: The [backend][msl.equipment.enumerations.Backend] to use to communicate with the equipment.
        eid: The [equipment id][msl.equipment.schema.Equipment.id] to associate with the [Connection][] instance.
        manufacturer: The name of the manufacturer of the equipment.
        model: The model number of the equipment.
        serial: The serial number (or unique identifier) of the equipment.
        properties: Additional key-value pairs to use when communicating with the equipment.
            For example, the _baud_rate_ and _parity_ values for an _RS-232_ connection.
    """
    self.address: str = address
    """The VISA-style address of the connection (see [here][address-syntax] for examples)."""

    self.backend: Backend = Backend(backend)
    """The [backend][msl.equipment.enumerations.Backend] that is used to communicate with the equipment."""

    self.eid: str = eid
    """The [equipment id][msl.equipment.schema.Equipment.id] associated with the [Connection][] instance."""

    self.manufacturer: str = manufacturer
    """The name of the manufacturer of the equipment."""

    self.model: str = model
    """The model number of the equipment."""

    # check for a properties key being explicitly defined and the value is a dict
    properties = (  # pyright: ignore[reportUnknownVariableType]
        properties["properties"]
        if ("properties" in properties and isinstance(properties["properties"], dict))
        else properties
    )

    self.properties: dict[str, _Any] = properties
    """Additional key-value pairs to use when communicating with the equipment.

    For example, the *baud_rate* and *parity* values for an *RS-232* connection.
    """

    self.serial: str = serial
    """The serial number (or unique identifier) of the equipment."""

address instance-attribute ¤

address: str = address

The VISA-style address of the connection (see here for examples).

backend instance-attribute ¤

backend: Backend = Backend(backend)

The backend that is used to communicate with the equipment.

eid instance-attribute ¤

eid: str = eid

The equipment id associated with the Connection instance.

manufacturer instance-attribute ¤

manufacturer: str = manufacturer

The name of the manufacturer of the equipment.

model instance-attribute ¤

model: str = model

The model number of the equipment.

properties instance-attribute ¤

properties: dict[str, Any] = properties

Additional key-value pairs to use when communicating with the equipment.

For example, the baud_rate and parity values for an RS-232 connection.

serial instance-attribute ¤

serial: str = serial

The serial number (or unique identifier) of the equipment.

connect ¤

connect() -> Any

Connect to the equipment for computer control.

The following sequence is used to decide how the connection is established.

  1. If a Connection has a specified backend, that is not MSL, that Backend is used.
  2. If the Connection has the appropriate manufacturer and model values for one of the Resources, that Resource is used.
  3. If the Connection has an address that is supported by one of the Interfaces, that Interface is used.
Source code in src/msl/equipment/schema.py
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
def connect(self) -> _Any:  # noqa: ANN401
    """Connect to the equipment for computer control.

    The following sequence is used to decide how the connection is established.

    1. If a [Connection][] has a specified [backend][msl.equipment.schema.Connection.backend],
       that is not `MSL`, that [Backend][connections-backend] is used.
    2. If the [Connection][] has the appropriate [manufacturer][msl.equipment.schema.Connection.manufacturer]
       and [model][msl.equipment.schema.Connection.model] values for one of the [Resources][],
       that Resource is used.
    3. If the [Connection][] has an [address][msl.equipment.schema.Connection.address]
       that is supported by one of the [Interfaces][connections-interfaces], that Interface is used.
    """
    equipment = Equipment(
        id=self.eid,
        manufacturer=self.manufacturer,
        model=self.model,
        serial=self.serial,
        connection=self,
    )
    return equipment.connect()