We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Keithley6500 does not set mode correctly
###
The Keithley6500 driver does not set the mode correctly.

### Steps to reproduce
```python
from qcodes.instrument_drivers.tektronix.Keithley_6500 import Keithley_6500
keithley_1 = Keithley_6500("keithley_1", address="TCPIP0::192.168.2.105::inst0::INSTR")
keithley_1.mode('dc voltage')
```

### Expected behaviour
The mode on the instrument to be set to DC voltage

### Actual behaviour
The instrument shows a message on the front panel that the parameter value should be specified as a string. In Python, the commands are executed without exception.

### System
Windows 10

If you are using a released version of qcodes (recommended):
0.31.0

###
Following the manual:
https://download.tek.com/manual/DMM6500-901-01B_Sept_2019_Ref.pdf
the solution is simply to add quotes around the mode value in the command. 

Related to #1541

I will add a PR shortly.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `qcodes/instrument_drivers/tektronix/Keithley_6500.py`
Content:
```
1 from typing import Any, TypeVar, Callable
2 from functools import partial
3 from typing import Union
4 
5 from qcodes import VisaInstrument
6 from qcodes.utils.validators import Bool, Enum, Ints, MultiType, Numbers
7 
8 T = TypeVar("T")
9 
10 
11 def _parse_output_string(string_value: str) -> str:
12     """ Parses and cleans string output of the multimeter. Removes the surrounding
13         whitespace, newline characters and quotes from the parsed data. Some results
14         are converted for readablitity (e.g. mov changes to moving).
15 
16     Args:
17         string_value: The data returned from the multimeter reading commands.
18 
19     Returns:
20         The cleaned-up output of the multimeter.
21     """
22     s = string_value.strip().lower()
23     if (s[0] == s[-1]) and s.startswith(("'", '"')):
24         s = s[1:-1]
25 
26     conversions = {'mov': 'moving', 'rep': 'repeat'}
27     if s in conversions.keys():
28         s = conversions[s]
29     return s
30 
31 
32 def _parse_output_bool(numeric_value: float) -> bool:
33     """ Parses and converts the value to boolean type. True is 1.
34 
35     Args:
36         numeric_value: The numerical value to convert.
37 
38     Returns:
39         The boolean representation of the numeric value.
40     """
41     return bool(numeric_value)
42 
43 
44 class CommandSetError(Exception):
45     pass
46 
47 
48 class Keithley_6500(VisaInstrument):
49 
50     def __init__(
51             self,
52             name: str,
53             address: str,
54             reset_device: bool = False,
55             **kwargs: Any):
56         """ Driver for the Keithley 6500 multimeter. Based on the Keithley 2000 driver,
57             commands have been adapted for the Keithley 6500. This driver does not contain
58             all commands available, but only the ones most commonly used.
59 
60             Status: beta-version.
61 
62         Args:
63             name (str): The name used internally by QCoDeS in the DataSet.
64             address (str): The VISA device address.
65             reset_device (bool): Reset the device on startup if true.
66         """
67         super().__init__(name, address, terminator='\n', **kwargs)
68 
69         command_set = self.ask('*LANG?')
70         if command_set != 'SCPI':
71             error_msg = "This driver only compatible with the 'SCPI' command " \
72                         "set, not '{}' set".format(command_set)
73             raise CommandSetError(error_msg)
74 
75         self._trigger_sent = False
76 
77         self._mode_map = {'ac current': 'CURR:AC', 'dc current': 'CURR:DC', 'ac voltage': 'VOLT:AC',
78                           'dc voltage': 'VOLT:DC', '2w resistance': 'RES', '4w resistance': 'FRES',
79                           'temperature': 'TEMP', 'frequency': 'FREQ'}
80 
81         self.add_parameter('mode',
82                            get_cmd='SENS:FUNC?',
83                            set_cmd="SENS:FUNC {}",
84                            val_mapping=self._mode_map)
85 
86         self.add_parameter('nplc',
87                            get_cmd=partial(
88                                self._get_mode_param, 'NPLC', float),
89                            set_cmd=partial(self._set_mode_param, 'NPLC'),
90                            vals=Numbers(min_value=0.01, max_value=10))
91 
92         #  TODO: validator, this one is more difficult since different modes
93         #  require different validation ranges.
94         self.add_parameter('range',
95                            get_cmd=partial(
96                                self._get_mode_param, 'RANG', float),
97                            set_cmd=partial(self._set_mode_param, 'RANG'),
98                            vals=Numbers())
99 
100         self.add_parameter('auto_range_enabled',
101                            get_cmd=partial(self._get_mode_param,
102                                            'RANG:AUTO', _parse_output_bool),
103                            set_cmd=partial(self._set_mode_param, 'RANG:AUTO'),
104                            vals=Bool())
105 
106         self.add_parameter('digits',
107                            get_cmd='DISP:VOLT:DC:DIG?', get_parser=int,
108                            set_cmd='DISP:VOLT:DC:DIG? {}',
109                            vals=Ints(min_value=4, max_value=7))
110 
111         self.add_parameter('averaging_type',
112                            get_cmd=partial(self._get_mode_param,
113                                            'AVER:TCON', _parse_output_string),
114                            set_cmd=partial(self._set_mode_param, 'AVER:TCON'),
115                            vals=Enum('moving', 'repeat'))
116 
117         self.add_parameter('averaging_count',
118                            get_cmd=partial(self._get_mode_param,
119                                            'AVER:COUN', int),
120                            set_cmd=partial(self._set_mode_param, 'AVER:COUN'),
121                            vals=Ints(min_value=1, max_value=100))
122 
123         self.add_parameter('averaging_enabled',
124                            get_cmd=partial(self._get_mode_param,
125                                            'AVER:STAT', _parse_output_bool),
126                            set_cmd=partial(self._set_mode_param, 'AVER:STAT'),
127                            vals=Bool())
128 
129         # Global parameters
130         self.add_parameter('display_backlight',
131                            docstring='Control the brightness of the display '
132                                      'backligt. Off turns the display off and'
133                                      'Blackout also turns off indicators and '
134                                      'key lights on the device.',
135                            get_cmd='DISP:LIGH:STAT?',
136                            set_cmd='DISP:LIGH:STAT {}',
137                            val_mapping={'On 100': 'ON100',
138                                         'On 75': 'ON75',
139                                         'On 50': 'ON50',
140                                         'On 25': 'ON25',
141                                         'Off': 'OFF',
142                                         'Blackout': 'BLACkout'})
143 
144         self.add_parameter('trigger_count',
145                            get_parser=int,
146                            get_cmd='ROUT:SCAN:COUN:SCAN?',
147                            set_cmd='ROUT:SCAN:COUN:SCAN {}',
148                            vals=MultiType(Ints(min_value=1, max_value=9999),
149                                           Enum('inf', 'default', 'minimum', 'maximum')))
150 
151         for trigger in range(1, 5):
152             self.add_parameter('trigger%i_delay' % trigger,
153                                docstring='Set and read trigger delay for '
154                                          'timer %i.' % trigger,
155                                get_parser=float,
156                                get_cmd='TRIG:TIM%i:DEL?' % trigger,
157                                set_cmd='TRIG:TIM%i:DEL {}' % trigger,
158                                unit='s', vals=Numbers(min_value=0,
159                                                       max_value=999999.999))
160 
161             self.add_parameter('trigger%i_source' % trigger,
162                                docstring='Set the trigger source for '
163                                          'timer %i.' % trigger,
164                                get_cmd='TRIG:TIM%i:STAR:STIM?' % trigger,
165                                set_cmd='TRIG:TIM%i:STAR:STIM {}' % trigger,
166                                val_mapping={'immediate': 'NONE',
167                                             'timer1': 'TIM1',
168                                             'timer2': 'TIM2',
169                                             'timer3': 'TIM3',
170                                             'timer4': 'TIM4',
171                                             'notify1': 'NOT1',
172                                             'notify2': 'NOT2',
173                                             'notify3': 'NOT3',
174                                             'front-panel': 'DISP',
175                                             'bus': 'COMM',
176                                             'external': 'EXT'})
177 
178         # Control interval between scans; the default value from the instrument is 0,
179         # hence 0 is included in the validator's range of this parameter.
180         self.add_parameter('trigger_timer',
181                            get_parser=float,
182                            get_cmd='ROUT:SCAN:INT?',
183                            set_cmd='ROUT:SCAN:INT {}',
184                            unit='s', vals=Numbers(min_value=0, max_value=999999.999))
185 
186         self.add_parameter('amplitude',
187                            get_cmd=self._read_next_value,
188                            set_cmd=False,
189                            unit='a.u.')
190 
191         if reset_device:
192             self.reset()
193         self.write('FORM:DATA ASCII')
194         self.connect_message()
195 
196     def reset(self) -> None:
197         """ Reset the device """
198         self.write('*RST')
199 
200     def _read_next_value(self) -> float:
201         return float(self.ask('READ?'))
202 
203     def _get_mode_param(self, parameter: str, parser: Callable[[str], T]) -> T:
204         """ Reads the current mode of the multimeter and ask for the given parameter.
205 
206         Args:
207             parameter: The asked parameter after getting the current mode.
208             parser: A function that parses the input buffer read.
209 
210         Returns:
211             Any: the parsed ask command. The parser determines the return data-type.
212         """
213         mode = _parse_output_string(self._mode_map[self.mode()])
214         cmd = f'{mode}:{parameter}?'
215         return parser(self.ask(cmd))
216 
217     def _set_mode_param(self, parameter: str, value: Union[str, float, bool]) -> None:
218         """ Gets the current mode of the multimeter and sets the given parameter.
219 
220         Args:
221             parameter: The set parameter after getting the current mode.
222             value: Value to set
223         """
224         if isinstance(value, bool):
225             value = int(value)
226 
227         mode = _parse_output_string(self._mode_map[self.mode()])
228         cmd = f'{mode}:{parameter} {value}'
229         self.write(cmd)
230
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/qcodes/instrument_drivers/tektronix/Keithley_6500.py b/qcodes/instrument_drivers/tektronix/Keithley_6500.py
--- a/qcodes/instrument_drivers/tektronix/Keithley_6500.py
+++ b/qcodes/instrument_drivers/tektronix/Keithley_6500.py
@@ -1,6 +1,5 @@
-from typing import Any, TypeVar, Callable
 from functools import partial
-from typing import Union
+from typing import Any, Callable, TypeVar, Union
 
 from qcodes import VisaInstrument
 from qcodes.utils.validators import Bool, Enum, Ints, MultiType, Numbers
@@ -78,10 +77,12 @@
                           'dc voltage': 'VOLT:DC', '2w resistance': 'RES', '4w resistance': 'FRES',
                           'temperature': 'TEMP', 'frequency': 'FREQ'}
 
-        self.add_parameter('mode',
-                           get_cmd='SENS:FUNC?',
-                           set_cmd="SENS:FUNC {}",
-                           val_mapping=self._mode_map)
+        self.add_parameter(
+            "mode",
+            get_cmd="SENS:FUNC?",
+            set_cmd="SENS:FUNC '{}'",
+            val_mapping=self._mode_map,
+        )
 
         self.add_parameter('nplc',
                            get_cmd=partial(

{"golden_diff": "diff --git a/qcodes/instrument_drivers/tektronix/Keithley_6500.py b/qcodes/instrument_drivers/tektronix/Keithley_6500.py\n--- a/qcodes/instrument_drivers/tektronix/Keithley_6500.py\n+++ b/qcodes/instrument_drivers/tektronix/Keithley_6500.py\n@@ -1,6 +1,5 @@\n-from typing import Any, TypeVar, Callable\n from functools import partial\n-from typing import Union\n+from typing import Any, Callable, TypeVar, Union\n \n from qcodes import VisaInstrument\n from qcodes.utils.validators import Bool, Enum, Ints, MultiType, Numbers\n@@ -78,10 +77,12 @@\n                           'dc voltage': 'VOLT:DC', '2w resistance': 'RES', '4w resistance': 'FRES',\n                           'temperature': 'TEMP', 'frequency': 'FREQ'}\n \n-        self.add_parameter('mode',\n-                           get_cmd='SENS:FUNC?',\n-                           set_cmd=\"SENS:FUNC {}\",\n-                           val_mapping=self._mode_map)\n+        self.add_parameter(\n+            \"mode\",\n+            get_cmd=\"SENS:FUNC?\",\n+            set_cmd=\"SENS:FUNC '{}'\",\n+            val_mapping=self._mode_map,\n+        )\n \n         self.add_parameter('nplc',\n                            get_cmd=partial(\n", "issue": "Keithley6500 does not set mode correctly\n###\r\nThe Keithley6500 driver does not set the mode correctly.\r\n\r\n### Steps to reproduce\r\n```python\r\nfrom qcodes.instrument_drivers.tektronix.Keithley_6500 import Keithley_6500\r\nkeithley_1 = Keithley_6500(\"keithley_1\", address=\"TCPIP0::192.168.2.105::inst0::INSTR\")\r\nkeithley_1.mode('dc voltage')\r\n```\r\n\r\n### Expected behaviour\r\nThe mode on the instrument to be set to DC voltage\r\n\r\n### Actual behaviour\r\nThe instrument shows a message on the front panel that the parameter value should be specified as a string. In Python, the commands are executed without exception.\r\n\r\n### System\r\nWindows 10\r\n\r\nIf you are using a released version of qcodes (recommended):\r\n0.31.0\r\n\r\n###\r\nFollowing the manual:\r\nhttps://download.tek.com/manual/DMM6500-901-01B_Sept_2019_Ref.pdf\r\nthe solution is simply to add quotes around the mode value in the command. \r\n\r\nRelated to #1541\r\n\r\nI will add a PR shortly.\n", "before_files": [{"content": "from typing import Any, TypeVar, Callable\nfrom functools import partial\nfrom typing import Union\n\nfrom qcodes import VisaInstrument\nfrom qcodes.utils.validators import Bool, Enum, Ints, MultiType, Numbers\n\nT = TypeVar(\"T\")\n\n\ndef _parse_output_string(string_value: str) -> str:\n    \"\"\" Parses and cleans string output of the multimeter. Removes the surrounding\n        whitespace, newline characters and quotes from the parsed data. Some results\n        are converted for readablitity (e.g. mov changes to moving).\n\n    Args:\n        string_value: The data returned from the multimeter reading commands.\n\n    Returns:\n        The cleaned-up output of the multimeter.\n    \"\"\"\n    s = string_value.strip().lower()\n    if (s[0] == s[-1]) and s.startswith((\"'\", '\"')):\n        s = s[1:-1]\n\n    conversions = {'mov': 'moving', 'rep': 'repeat'}\n    if s in conversions.keys():\n        s = conversions[s]\n    return s\n\n\ndef _parse_output_bool(numeric_value: float) -> bool:\n    \"\"\" Parses and converts the value to boolean type. True is 1.\n\n    Args:\n        numeric_value: The numerical value to convert.\n\n    Returns:\n        The boolean representation of the numeric value.\n    \"\"\"\n    return bool(numeric_value)\n\n\nclass CommandSetError(Exception):\n    pass\n\n\nclass Keithley_6500(VisaInstrument):\n\n    def __init__(\n            self,\n            name: str,\n            address: str,\n            reset_device: bool = False,\n            **kwargs: Any):\n        \"\"\" Driver for the Keithley 6500 multimeter. Based on the Keithley 2000 driver,\n            commands have been adapted for the Keithley 6500. This driver does not contain\n            all commands available, but only the ones most commonly used.\n\n            Status: beta-version.\n\n        Args:\n            name (str): The name used internally by QCoDeS in the DataSet.\n            address (str): The VISA device address.\n            reset_device (bool): Reset the device on startup if true.\n        \"\"\"\n        super().__init__(name, address, terminator='\\n', **kwargs)\n\n        command_set = self.ask('*LANG?')\n        if command_set != 'SCPI':\n            error_msg = \"This driver only compatible with the 'SCPI' command \" \\\n                        \"set, not '{}' set\".format(command_set)\n            raise CommandSetError(error_msg)\n\n        self._trigger_sent = False\n\n        self._mode_map = {'ac current': 'CURR:AC', 'dc current': 'CURR:DC', 'ac voltage': 'VOLT:AC',\n                          'dc voltage': 'VOLT:DC', '2w resistance': 'RES', '4w resistance': 'FRES',\n                          'temperature': 'TEMP', 'frequency': 'FREQ'}\n\n        self.add_parameter('mode',\n                           get_cmd='SENS:FUNC?',\n                           set_cmd=\"SENS:FUNC {}\",\n                           val_mapping=self._mode_map)\n\n        self.add_parameter('nplc',\n                           get_cmd=partial(\n                               self._get_mode_param, 'NPLC', float),\n                           set_cmd=partial(self._set_mode_param, 'NPLC'),\n                           vals=Numbers(min_value=0.01, max_value=10))\n\n        #  TODO: validator, this one is more difficult since different modes\n        #  require different validation ranges.\n        self.add_parameter('range',\n                           get_cmd=partial(\n                               self._get_mode_param, 'RANG', float),\n                           set_cmd=partial(self._set_mode_param, 'RANG'),\n                           vals=Numbers())\n\n        self.add_parameter('auto_range_enabled',\n                           get_cmd=partial(self._get_mode_param,\n                                           'RANG:AUTO', _parse_output_bool),\n                           set_cmd=partial(self._set_mode_param, 'RANG:AUTO'),\n                           vals=Bool())\n\n        self.add_parameter('digits',\n                           get_cmd='DISP:VOLT:DC:DIG?', get_parser=int,\n                           set_cmd='DISP:VOLT:DC:DIG? {}',\n                           vals=Ints(min_value=4, max_value=7))\n\n        self.add_parameter('averaging_type',\n                           get_cmd=partial(self._get_mode_param,\n                                           'AVER:TCON', _parse_output_string),\n                           set_cmd=partial(self._set_mode_param, 'AVER:TCON'),\n                           vals=Enum('moving', 'repeat'))\n\n        self.add_parameter('averaging_count',\n                           get_cmd=partial(self._get_mode_param,\n                                           'AVER:COUN', int),\n                           set_cmd=partial(self._set_mode_param, 'AVER:COUN'),\n                           vals=Ints(min_value=1, max_value=100))\n\n        self.add_parameter('averaging_enabled',\n                           get_cmd=partial(self._get_mode_param,\n                                           'AVER:STAT', _parse_output_bool),\n                           set_cmd=partial(self._set_mode_param, 'AVER:STAT'),\n                           vals=Bool())\n\n        # Global parameters\n        self.add_parameter('display_backlight',\n                           docstring='Control the brightness of the display '\n                                     'backligt. Off turns the display off and'\n                                     'Blackout also turns off indicators and '\n                                     'key lights on the device.',\n                           get_cmd='DISP:LIGH:STAT?',\n                           set_cmd='DISP:LIGH:STAT {}',\n                           val_mapping={'On 100': 'ON100',\n                                        'On 75': 'ON75',\n                                        'On 50': 'ON50',\n                                        'On 25': 'ON25',\n                                        'Off': 'OFF',\n                                        'Blackout': 'BLACkout'})\n\n        self.add_parameter('trigger_count',\n                           get_parser=int,\n                           get_cmd='ROUT:SCAN:COUN:SCAN?',\n                           set_cmd='ROUT:SCAN:COUN:SCAN {}',\n                           vals=MultiType(Ints(min_value=1, max_value=9999),\n                                          Enum('inf', 'default', 'minimum', 'maximum')))\n\n        for trigger in range(1, 5):\n            self.add_parameter('trigger%i_delay' % trigger,\n                               docstring='Set and read trigger delay for '\n                                         'timer %i.' % trigger,\n                               get_parser=float,\n                               get_cmd='TRIG:TIM%i:DEL?' % trigger,\n                               set_cmd='TRIG:TIM%i:DEL {}' % trigger,\n                               unit='s', vals=Numbers(min_value=0,\n                                                      max_value=999999.999))\n\n            self.add_parameter('trigger%i_source' % trigger,\n                               docstring='Set the trigger source for '\n                                         'timer %i.' % trigger,\n                               get_cmd='TRIG:TIM%i:STAR:STIM?' % trigger,\n                               set_cmd='TRIG:TIM%i:STAR:STIM {}' % trigger,\n                               val_mapping={'immediate': 'NONE',\n                                            'timer1': 'TIM1',\n                                            'timer2': 'TIM2',\n                                            'timer3': 'TIM3',\n                                            'timer4': 'TIM4',\n                                            'notify1': 'NOT1',\n                                            'notify2': 'NOT2',\n                                            'notify3': 'NOT3',\n                                            'front-panel': 'DISP',\n                                            'bus': 'COMM',\n                                            'external': 'EXT'})\n\n        # Control interval between scans; the default value from the instrument is 0,\n        # hence 0 is included in the validator's range of this parameter.\n        self.add_parameter('trigger_timer',\n                           get_parser=float,\n                           get_cmd='ROUT:SCAN:INT?',\n                           set_cmd='ROUT:SCAN:INT {}',\n                           unit='s', vals=Numbers(min_value=0, max_value=999999.999))\n\n        self.add_parameter('amplitude',\n                           get_cmd=self._read_next_value,\n                           set_cmd=False,\n                           unit='a.u.')\n\n        if reset_device:\n            self.reset()\n        self.write('FORM:DATA ASCII')\n        self.connect_message()\n\n    def reset(self) -> None:\n        \"\"\" Reset the device \"\"\"\n        self.write('*RST')\n\n    def _read_next_value(self) -> float:\n        return float(self.ask('READ?'))\n\n    def _get_mode_param(self, parameter: str, parser: Callable[[str], T]) -> T:\n        \"\"\" Reads the current mode of the multimeter and ask for the given parameter.\n\n        Args:\n            parameter: The asked parameter after getting the current mode.\n            parser: A function that parses the input buffer read.\n\n        Returns:\n            Any: the parsed ask command. The parser determines the return data-type.\n        \"\"\"\n        mode = _parse_output_string(self._mode_map[self.mode()])\n        cmd = f'{mode}:{parameter}?'\n        return parser(self.ask(cmd))\n\n    def _set_mode_param(self, parameter: str, value: Union[str, float, bool]) -> None:\n        \"\"\" Gets the current mode of the multimeter and sets the given parameter.\n\n        Args:\n            parameter: The set parameter after getting the current mode.\n            value: Value to set\n        \"\"\"\n        if isinstance(value, bool):\n            value = int(value)\n\n        mode = _parse_output_string(self._mode_map[self.mode()])\n        cmd = f'{mode}:{parameter} {value}'\n        self.write(cmd)\n", "path": "qcodes/instrument_drivers/tektronix/Keithley_6500.py"}], "after_files": [{"content": "from functools import partial\nfrom typing import Any, Callable, TypeVar, Union\n\nfrom qcodes import VisaInstrument\nfrom qcodes.utils.validators import Bool, Enum, Ints, MultiType, Numbers\n\nT = TypeVar(\"T\")\n\n\ndef _parse_output_string(string_value: str) -> str:\n    \"\"\" Parses and cleans string output of the multimeter. Removes the surrounding\n        whitespace, newline characters and quotes from the parsed data. Some results\n        are converted for readablitity (e.g. mov changes to moving).\n\n    Args:\n        string_value: The data returned from the multimeter reading commands.\n\n    Returns:\n        The cleaned-up output of the multimeter.\n    \"\"\"\n    s = string_value.strip().lower()\n    if (s[0] == s[-1]) and s.startswith((\"'\", '\"')):\n        s = s[1:-1]\n\n    conversions = {'mov': 'moving', 'rep': 'repeat'}\n    if s in conversions.keys():\n        s = conversions[s]\n    return s\n\n\ndef _parse_output_bool(numeric_value: float) -> bool:\n    \"\"\" Parses and converts the value to boolean type. True is 1.\n\n    Args:\n        numeric_value: The numerical value to convert.\n\n    Returns:\n        The boolean representation of the numeric value.\n    \"\"\"\n    return bool(numeric_value)\n\n\nclass CommandSetError(Exception):\n    pass\n\n\nclass Keithley_6500(VisaInstrument):\n\n    def __init__(\n            self,\n            name: str,\n            address: str,\n            reset_device: bool = False,\n            **kwargs: Any):\n        \"\"\" Driver for the Keithley 6500 multimeter. Based on the Keithley 2000 driver,\n            commands have been adapted for the Keithley 6500. This driver does not contain\n            all commands available, but only the ones most commonly used.\n\n            Status: beta-version.\n\n        Args:\n            name (str): The name used internally by QCoDeS in the DataSet.\n            address (str): The VISA device address.\n            reset_device (bool): Reset the device on startup if true.\n        \"\"\"\n        super().__init__(name, address, terminator='\\n', **kwargs)\n\n        command_set = self.ask('*LANG?')\n        if command_set != 'SCPI':\n            error_msg = \"This driver only compatible with the 'SCPI' command \" \\\n                        \"set, not '{}' set\".format(command_set)\n            raise CommandSetError(error_msg)\n\n        self._trigger_sent = False\n\n        self._mode_map = {'ac current': 'CURR:AC', 'dc current': 'CURR:DC', 'ac voltage': 'VOLT:AC',\n                          'dc voltage': 'VOLT:DC', '2w resistance': 'RES', '4w resistance': 'FRES',\n                          'temperature': 'TEMP', 'frequency': 'FREQ'}\n\n        self.add_parameter(\n            \"mode\",\n            get_cmd=\"SENS:FUNC?\",\n            set_cmd=\"SENS:FUNC '{}'\",\n            val_mapping=self._mode_map,\n        )\n\n        self.add_parameter('nplc',\n                           get_cmd=partial(\n                               self._get_mode_param, 'NPLC', float),\n                           set_cmd=partial(self._set_mode_param, 'NPLC'),\n                           vals=Numbers(min_value=0.01, max_value=10))\n\n        #  TODO: validator, this one is more difficult since different modes\n        #  require different validation ranges.\n        self.add_parameter('range',\n                           get_cmd=partial(\n                               self._get_mode_param, 'RANG', float),\n                           set_cmd=partial(self._set_mode_param, 'RANG'),\n                           vals=Numbers())\n\n        self.add_parameter('auto_range_enabled',\n                           get_cmd=partial(self._get_mode_param,\n                                           'RANG:AUTO', _parse_output_bool),\n                           set_cmd=partial(self._set_mode_param, 'RANG:AUTO'),\n                           vals=Bool())\n\n        self.add_parameter('digits',\n                           get_cmd='DISP:VOLT:DC:DIG?', get_parser=int,\n                           set_cmd='DISP:VOLT:DC:DIG? {}',\n                           vals=Ints(min_value=4, max_value=7))\n\n        self.add_parameter('averaging_type',\n                           get_cmd=partial(self._get_mode_param,\n                                           'AVER:TCON', _parse_output_string),\n                           set_cmd=partial(self._set_mode_param, 'AVER:TCON'),\n                           vals=Enum('moving', 'repeat'))\n\n        self.add_parameter('averaging_count',\n                           get_cmd=partial(self._get_mode_param,\n                                           'AVER:COUN', int),\n                           set_cmd=partial(self._set_mode_param, 'AVER:COUN'),\n                           vals=Ints(min_value=1, max_value=100))\n\n        self.add_parameter('averaging_enabled',\n                           get_cmd=partial(self._get_mode_param,\n                                           'AVER:STAT', _parse_output_bool),\n                           set_cmd=partial(self._set_mode_param, 'AVER:STAT'),\n                           vals=Bool())\n\n        # Global parameters\n        self.add_parameter('display_backlight',\n                           docstring='Control the brightness of the display '\n                                     'backligt. Off turns the display off and'\n                                     'Blackout also turns off indicators and '\n                                     'key lights on the device.',\n                           get_cmd='DISP:LIGH:STAT?',\n                           set_cmd='DISP:LIGH:STAT {}',\n                           val_mapping={'On 100': 'ON100',\n                                        'On 75': 'ON75',\n                                        'On 50': 'ON50',\n                                        'On 25': 'ON25',\n                                        'Off': 'OFF',\n                                        'Blackout': 'BLACkout'})\n\n        self.add_parameter('trigger_count',\n                           get_parser=int,\n                           get_cmd='ROUT:SCAN:COUN:SCAN?',\n                           set_cmd='ROUT:SCAN:COUN:SCAN {}',\n                           vals=MultiType(Ints(min_value=1, max_value=9999),\n                                          Enum('inf', 'default', 'minimum', 'maximum')))\n\n        for trigger in range(1, 5):\n            self.add_parameter('trigger%i_delay' % trigger,\n                               docstring='Set and read trigger delay for '\n                                         'timer %i.' % trigger,\n                               get_parser=float,\n                               get_cmd='TRIG:TIM%i:DEL?' % trigger,\n                               set_cmd='TRIG:TIM%i:DEL {}' % trigger,\n                               unit='s', vals=Numbers(min_value=0,\n                                                      max_value=999999.999))\n\n            self.add_parameter('trigger%i_source' % trigger,\n                               docstring='Set the trigger source for '\n                                         'timer %i.' % trigger,\n                               get_cmd='TRIG:TIM%i:STAR:STIM?' % trigger,\n                               set_cmd='TRIG:TIM%i:STAR:STIM {}' % trigger,\n                               val_mapping={'immediate': 'NONE',\n                                            'timer1': 'TIM1',\n                                            'timer2': 'TIM2',\n                                            'timer3': 'TIM3',\n                                            'timer4': 'TIM4',\n                                            'notify1': 'NOT1',\n                                            'notify2': 'NOT2',\n                                            'notify3': 'NOT3',\n                                            'front-panel': 'DISP',\n                                            'bus': 'COMM',\n                                            'external': 'EXT'})\n\n        # Control interval between scans; the default value from the instrument is 0,\n        # hence 0 is included in the validator's range of this parameter.\n        self.add_parameter('trigger_timer',\n                           get_parser=float,\n                           get_cmd='ROUT:SCAN:INT?',\n                           set_cmd='ROUT:SCAN:INT {}',\n                           unit='s', vals=Numbers(min_value=0, max_value=999999.999))\n\n        self.add_parameter('amplitude',\n                           get_cmd=self._read_next_value,\n                           set_cmd=False,\n                           unit='a.u.')\n\n        if reset_device:\n            self.reset()\n        self.write('FORM:DATA ASCII')\n        self.connect_message()\n\n    def reset(self) -> None:\n        \"\"\" Reset the device \"\"\"\n        self.write('*RST')\n\n    def _read_next_value(self) -> float:\n        return float(self.ask('READ?'))\n\n    def _get_mode_param(self, parameter: str, parser: Callable[[str], T]) -> T:\n        \"\"\" Reads the current mode of the multimeter and ask for the given parameter.\n\n        Args:\n            parameter: The asked parameter after getting the current mode.\n            parser: A function that parses the input buffer read.\n\n        Returns:\n            Any: the parsed ask command. The parser determines the return data-type.\n        \"\"\"\n        mode = _parse_output_string(self._mode_map[self.mode()])\n        cmd = f'{mode}:{parameter}?'\n        return parser(self.ask(cmd))\n\n    def _set_mode_param(self, parameter: str, value: Union[str, float, bool]) -> None:\n        \"\"\" Gets the current mode of the multimeter and sets the given parameter.\n\n        Args:\n            parameter: The set parameter after getting the current mode.\n            value: Value to set\n        \"\"\"\n        if isinstance(value, bool):\n            value = int(value)\n\n        mode = _parse_output_string(self._mode_map[self.mode()])\n        cmd = f'{mode}:{parameter} {value}'\n        self.write(cmd)\n", "path": "qcodes/instrument_drivers/tektronix/Keithley_6500.py"}]}