Return a Driver with an underlying USB resource. A connected USBTMC instrument with the specified serial_number, manufacturer_id, and model_code is returned. If any of these is missing, the first USBTMC driver matching any of the provided values is returned. To spec
(cls, resource_type='INSTR', serial_number=None, manufacturer_id=None,
model_code=None, name=None, board=0, **kwargs)
| 116 | |
| 117 | @classmethod |
| 118 | def _via_usb(cls, resource_type='INSTR', serial_number=None, manufacturer_id=None, |
| 119 | model_code=None, name=None, board=0, **kwargs): |
| 120 | """Return a Driver with an underlying USB resource. |
| 121 | |
| 122 | A connected USBTMC instrument with the specified serial_number, manufacturer_id, |
| 123 | and model_code is returned. If any of these is missing, the first USBTMC driver |
| 124 | matching any of the provided values is returned. |
| 125 | |
| 126 | To specify the manufacturer id and/or the model code override the following class attributes:: |
| 127 | |
| 128 | class RigolDS1052E(MessageBasedDriver): |
| 129 | |
| 130 | MANUFACTURER_ID = '0x1AB1' |
| 131 | MODEL_CODE = '0x0588' |
| 132 | |
| 133 | :param serial_number: The serial number of the instrument. |
| 134 | :param manufacturer_id: The unique identification number of the manufacturer. |
| 135 | :param model_code: The unique identification number of the product. |
| 136 | :param name: Unique name given within Lantz to the instrument for logging purposes. |
| 137 | Defaults to one generated based on the class name if not provided. |
| 138 | :param board: USB Board to use |
| 139 | :param kwargs: keyword arguments passed to the Resource constructor on initialize. |
| 140 | |
| 141 | :rtype: MessageBasedDriver |
| 142 | """ |
| 143 | |
| 144 | manufacturer_id = manufacturer_id or cls.MANUFACTURER_ID |
| 145 | model_code = model_code or cls.MODEL_CODE |
| 146 | |
| 147 | if isinstance(model_code, (list, tuple)): |
| 148 | _models = model_code |
| 149 | model_code = '?*' |
| 150 | else: |
| 151 | _models = None |
| 152 | |
| 153 | query = 'USB%d::%s::%s::%s::%s' % (board, manufacturer_id or '?*', |
| 154 | model_code or '?*', |
| 155 | serial_number or '?*', |
| 156 | resource_type) |
| 157 | |
| 158 | rm = get_resource_manager() |
| 159 | try: |
| 160 | resource_names = rm.list_resources(query) |
| 161 | except: |
| 162 | raise ValueError('No USBTMC devices found for %s' % query) |
| 163 | |
| 164 | if _models: |
| 165 | # There are more than 1 model compatible with |
| 166 | resource_names = [r for r in resource_names |
| 167 | if r.split('::')[2] in _models] |
| 168 | |
| 169 | if not resource_names: |
| 170 | raise ValueError('No USBTMC devices found for %s ' |
| 171 | 'with model in %s' % (query, _models)) |
| 172 | |
| 173 | if len(resource_names) > 1: |
| 174 | raise ValueError('%d USBTMC devices found for %s. ' |
| 175 | 'Please specify the serial number' % (len(resource_names), query)) |
no test coverage detected