We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Find USB device from hardware information
The COM port of virtual Com ports via USB may change from time to time.
I propose a simple helper method, which retrieves the COM port of a USB virtual port according to hardware information (vendor id, product id, serial number).
This method allows to specify the hardware information and then to connect always to the correct device, independent of the COM port number assigned at that time.

Rough idea:

~~~python
from serial.tools import list_ports

def findPort(vid: int, pid: int, sn: str) -> str:
    """Find the port name ('COM5') of the first device with the given USB information.

    :param int vid: Vendor ID.
    :param int pid: Product ID.
    :param str sn: Serial number.
    :return: Port as a string as `device` attribute returned from `list_ports.comports`.
    """
    for port in sorted(list_ports.comports()):
        if port.vid == vid and port.pid == pid and port.serial_number == str(sn):
            return port.device
    raise AttributeError("No device found for the given data.")
~~~

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pymeasure/instruments/__init__.py`
Content:
```
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2023 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 
25 from ..errors import RangeError, RangeException
26 from .channel import Channel
27 from .instrument import Instrument
28 from .resources import list_resources
29 from .validators import discreteTruncate
30 
31 from . import activetechnologies
32 from . import advantest
33 from . import agilent
34 from . import aja
35 from . import ametek
36 from . import ami
37 from . import anaheimautomation
38 from . import anapico
39 from . import andeenhagerling
40 from . import anritsu
41 from . import attocube
42 from . import bkprecision
43 from . import danfysik
44 from . import deltaelektronika
45 from . import edwards
46 from . import eurotest
47 from . import fluke
48 from . import fwbell
49 from . import hcp
50 from . import heidenhain
51 from . import hp
52 from . import ipgphotonics
53 from . import keithley
54 from . import keysight
55 from . import lakeshore
56 from . import lecroy
57 from . import mksinst
58 from . import newport
59 from . import ni
60 from . import novanta
61 from . import oxfordinstruments
62 from . import parker
63 from . import pendulum
64 from . import razorbill
65 from . import rohdeschwarz
66 from . import siglenttechnologies
67 from . import signalrecovery
68 from . import srs
69 from . import tcpowerconversion
70 from . import tektronix
71 from . import teledyne
72 from . import temptronic
73 from . import texio
74 from . import thermotron
75 from . import thorlabs
76 from . import thyracont
77 from . import toptica
78 from . import velleman
79 from . import yokogawa
80
```

Path: `pymeasure/instruments/resources.py`
Content:
```
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2023 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 
25 import pyvisa
26 
27 
28 def list_resources():
29     """
30     Prints the available resources, and returns a list of VISA resource names
31 
32     .. code-block:: python
33 
34         resources = list_resources()
35         #prints (e.g.)
36             #0 : GPIB0::22::INSTR : Agilent Technologies,34410A,******
37             #1 : GPIB0::26::INSTR : Keithley Instruments Inc., Model 2612, *****
38         dmm = Agilent34410(resources[0])
39 
40     """
41     rm = pyvisa.ResourceManager()
42     instrs = rm.list_resources()
43     for n, instr in enumerate(instrs):
44         # trying to catch errors in comunication
45         try:
46             res = rm.open_resource(instr)
47             # try to avoid errors from *idn?
48             try:
49                 # noinspection PyUnresolvedReferences
50                 idn = res.query('*idn?')[:-1]
51             except pyvisa.Error:
52                 idn = "Not known"
53             finally:
54                 res.close()
55                 print(n, ":", instr, ":", idn)
56         except pyvisa.VisaIOError as e:
57             print(n, ":", instr, ":", "Visa IO Error: check connections")
58             print(e)
59     rm.close()
60     return instrs
61
```
--- 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/pymeasure/instruments/__init__.py b/pymeasure/instruments/__init__.py
--- a/pymeasure/instruments/__init__.py
+++ b/pymeasure/instruments/__init__.py
@@ -25,7 +25,7 @@
 from ..errors import RangeError, RangeException
 from .channel import Channel
 from .instrument import Instrument
-from .resources import list_resources
+from .resources import find_serial_port, list_resources
 from .validators import discreteTruncate
 
 from . import activetechnologies
diff --git a/pymeasure/instruments/resources.py b/pymeasure/instruments/resources.py
--- a/pymeasure/instruments/resources.py
+++ b/pymeasure/instruments/resources.py
@@ -23,6 +23,7 @@
 #
 
 import pyvisa
+from serial.tools import list_ports
 
 
 def list_resources():
@@ -58,3 +59,28 @@
             print(e)
     rm.close()
     return instrs
+
+
+def find_serial_port(vendor_id=None, product_id=None, serial_number=None):
+    """Find the VISA port name of the first serial device with the given USB information.
+
+    Use `None` as a value if you do not want to check for that parameter.
+
+    .. code-block:: python
+
+        resource_name = find_serial_port(vendor_id=1256, serial_number="SN12345")
+        dmm = Agilent34410(resource_name)
+
+    :param int vid: Vendor ID.
+    :param int pid: Product ID.
+    :param str sn: Serial number.
+    :return str: Port as a VISA string for a serial device (e.g. "ASRL5" or "ASRL/dev/ttyACM5").
+    """
+    for port in sorted(list_ports.comports()):
+        if ((vendor_id is None or port.vid == vendor_id)
+                and (product_id is None or port.pid == product_id)
+                and (serial_number is None or port.serial_number == str(serial_number))):
+            # remove "COM" from windows serial port names.
+            port_name = port.device.replace("COM", "")
+            return "ASRL" + port_name
+    raise AttributeError("No device found for the given data.")

{"golden_diff": "diff --git a/pymeasure/instruments/__init__.py b/pymeasure/instruments/__init__.py\n--- a/pymeasure/instruments/__init__.py\n+++ b/pymeasure/instruments/__init__.py\n@@ -25,7 +25,7 @@\n from ..errors import RangeError, RangeException\n from .channel import Channel\n from .instrument import Instrument\n-from .resources import list_resources\n+from .resources import find_serial_port, list_resources\n from .validators import discreteTruncate\n \n from . import activetechnologies\ndiff --git a/pymeasure/instruments/resources.py b/pymeasure/instruments/resources.py\n--- a/pymeasure/instruments/resources.py\n+++ b/pymeasure/instruments/resources.py\n@@ -23,6 +23,7 @@\n #\n \n import pyvisa\n+from serial.tools import list_ports\n \n \n def list_resources():\n@@ -58,3 +59,28 @@\n             print(e)\n     rm.close()\n     return instrs\n+\n+\n+def find_serial_port(vendor_id=None, product_id=None, serial_number=None):\n+    \"\"\"Find the VISA port name of the first serial device with the given USB information.\n+\n+    Use `None` as a value if you do not want to check for that parameter.\n+\n+    .. code-block:: python\n+\n+        resource_name = find_serial_port(vendor_id=1256, serial_number=\"SN12345\")\n+        dmm = Agilent34410(resource_name)\n+\n+    :param int vid: Vendor ID.\n+    :param int pid: Product ID.\n+    :param str sn: Serial number.\n+    :return str: Port as a VISA string for a serial device (e.g. \"ASRL5\" or \"ASRL/dev/ttyACM5\").\n+    \"\"\"\n+    for port in sorted(list_ports.comports()):\n+        if ((vendor_id is None or port.vid == vendor_id)\n+                and (product_id is None or port.pid == product_id)\n+                and (serial_number is None or port.serial_number == str(serial_number))):\n+            # remove \"COM\" from windows serial port names.\n+            port_name = port.device.replace(\"COM\", \"\")\n+            return \"ASRL\" + port_name\n+    raise AttributeError(\"No device found for the given data.\")\n", "issue": "Find USB device from hardware information\nThe COM port of virtual Com ports via USB may change from time to time.\r\nI propose a simple helper method, which retrieves the COM port of a USB virtual port according to hardware information (vendor id, product id, serial number).\r\nThis method allows to specify the hardware information and then to connect always to the correct device, independent of the COM port number assigned at that time.\r\n\r\nRough idea:\r\n\r\n~~~python\r\nfrom serial.tools import list_ports\r\n\r\ndef findPort(vid: int, pid: int, sn: str) -> str:\r\n    \"\"\"Find the port name ('COM5') of the first device with the given USB information.\r\n\r\n    :param int vid: Vendor ID.\r\n    :param int pid: Product ID.\r\n    :param str sn: Serial number.\r\n    :return: Port as a string as `device` attribute returned from `list_ports.comports`.\r\n    \"\"\"\r\n    for port in sorted(list_ports.comports()):\r\n        if port.vid == vid and port.pid == pid and port.serial_number == str(sn):\r\n            return port.device\r\n    raise AttributeError(\"No device found for the given data.\")\r\n~~~\n", "before_files": [{"content": "#\n# This file is part of the PyMeasure package.\n#\n# Copyright (c) 2013-2023 PyMeasure Developers\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n# THE SOFTWARE.\n#\n\nfrom ..errors import RangeError, RangeException\nfrom .channel import Channel\nfrom .instrument import Instrument\nfrom .resources import list_resources\nfrom .validators import discreteTruncate\n\nfrom . import activetechnologies\nfrom . import advantest\nfrom . import agilent\nfrom . import aja\nfrom . import ametek\nfrom . import ami\nfrom . import anaheimautomation\nfrom . import anapico\nfrom . import andeenhagerling\nfrom . import anritsu\nfrom . import attocube\nfrom . import bkprecision\nfrom . import danfysik\nfrom . import deltaelektronika\nfrom . import edwards\nfrom . import eurotest\nfrom . import fluke\nfrom . import fwbell\nfrom . import hcp\nfrom . import heidenhain\nfrom . import hp\nfrom . import ipgphotonics\nfrom . import keithley\nfrom . import keysight\nfrom . import lakeshore\nfrom . import lecroy\nfrom . import mksinst\nfrom . import newport\nfrom . import ni\nfrom . import novanta\nfrom . import oxfordinstruments\nfrom . import parker\nfrom . import pendulum\nfrom . import razorbill\nfrom . import rohdeschwarz\nfrom . import siglenttechnologies\nfrom . import signalrecovery\nfrom . import srs\nfrom . import tcpowerconversion\nfrom . import tektronix\nfrom . import teledyne\nfrom . import temptronic\nfrom . import texio\nfrom . import thermotron\nfrom . import thorlabs\nfrom . import thyracont\nfrom . import toptica\nfrom . import velleman\nfrom . import yokogawa\n", "path": "pymeasure/instruments/__init__.py"}, {"content": "#\n# This file is part of the PyMeasure package.\n#\n# Copyright (c) 2013-2023 PyMeasure Developers\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n# THE SOFTWARE.\n#\n\nimport pyvisa\n\n\ndef list_resources():\n    \"\"\"\n    Prints the available resources, and returns a list of VISA resource names\n\n    .. code-block:: python\n\n        resources = list_resources()\n        #prints (e.g.)\n            #0 : GPIB0::22::INSTR : Agilent Technologies,34410A,******\n            #1 : GPIB0::26::INSTR : Keithley Instruments Inc., Model 2612, *****\n        dmm = Agilent34410(resources[0])\n\n    \"\"\"\n    rm = pyvisa.ResourceManager()\n    instrs = rm.list_resources()\n    for n, instr in enumerate(instrs):\n        # trying to catch errors in comunication\n        try:\n            res = rm.open_resource(instr)\n            # try to avoid errors from *idn?\n            try:\n                # noinspection PyUnresolvedReferences\n                idn = res.query('*idn?')[:-1]\n            except pyvisa.Error:\n                idn = \"Not known\"\n            finally:\n                res.close()\n                print(n, \":\", instr, \":\", idn)\n        except pyvisa.VisaIOError as e:\n            print(n, \":\", instr, \":\", \"Visa IO Error: check connections\")\n            print(e)\n    rm.close()\n    return instrs\n", "path": "pymeasure/instruments/resources.py"}], "after_files": [{"content": "#\n# This file is part of the PyMeasure package.\n#\n# Copyright (c) 2013-2023 PyMeasure Developers\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n# THE SOFTWARE.\n#\n\nfrom ..errors import RangeError, RangeException\nfrom .channel import Channel\nfrom .instrument import Instrument\nfrom .resources import find_serial_port, list_resources\nfrom .validators import discreteTruncate\n\nfrom . import activetechnologies\nfrom . import advantest\nfrom . import agilent\nfrom . import aja\nfrom . import ametek\nfrom . import ami\nfrom . import anaheimautomation\nfrom . import anapico\nfrom . import andeenhagerling\nfrom . import anritsu\nfrom . import attocube\nfrom . import bkprecision\nfrom . import danfysik\nfrom . import deltaelektronika\nfrom . import edwards\nfrom . import eurotest\nfrom . import fluke\nfrom . import fwbell\nfrom . import hcp\nfrom . import heidenhain\nfrom . import hp\nfrom . import ipgphotonics\nfrom . import keithley\nfrom . import keysight\nfrom . import lakeshore\nfrom . import lecroy\nfrom . import mksinst\nfrom . import newport\nfrom . import ni\nfrom . import novanta\nfrom . import oxfordinstruments\nfrom . import parker\nfrom . import pendulum\nfrom . import razorbill\nfrom . import rohdeschwarz\nfrom . import siglenttechnologies\nfrom . import signalrecovery\nfrom . import srs\nfrom . import tcpowerconversion\nfrom . import tektronix\nfrom . import teledyne\nfrom . import temptronic\nfrom . import texio\nfrom . import thermotron\nfrom . import thorlabs\nfrom . import thyracont\nfrom . import toptica\nfrom . import velleman\nfrom . import yokogawa\n", "path": "pymeasure/instruments/__init__.py"}, {"content": "#\n# This file is part of the PyMeasure package.\n#\n# Copyright (c) 2013-2023 PyMeasure Developers\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n# THE SOFTWARE.\n#\n\nimport pyvisa\nfrom serial.tools import list_ports\n\n\ndef list_resources():\n    \"\"\"\n    Prints the available resources, and returns a list of VISA resource names\n\n    .. code-block:: python\n\n        resources = list_resources()\n        #prints (e.g.)\n            #0 : GPIB0::22::INSTR : Agilent Technologies,34410A,******\n            #1 : GPIB0::26::INSTR : Keithley Instruments Inc., Model 2612, *****\n        dmm = Agilent34410(resources[0])\n\n    \"\"\"\n    rm = pyvisa.ResourceManager()\n    instrs = rm.list_resources()\n    for n, instr in enumerate(instrs):\n        # trying to catch errors in comunication\n        try:\n            res = rm.open_resource(instr)\n            # try to avoid errors from *idn?\n            try:\n                # noinspection PyUnresolvedReferences\n                idn = res.query('*idn?')[:-1]\n            except pyvisa.Error:\n                idn = \"Not known\"\n            finally:\n                res.close()\n                print(n, \":\", instr, \":\", idn)\n        except pyvisa.VisaIOError as e:\n            print(n, \":\", instr, \":\", \"Visa IO Error: check connections\")\n            print(e)\n    rm.close()\n    return instrs\n\n\ndef find_serial_port(vendor_id=None, product_id=None, serial_number=None):\n    \"\"\"Find the VISA port name of the first serial device with the given USB information.\n\n    Use `None` as a value if you do not want to check for that parameter.\n\n    .. code-block:: python\n\n        resource_name = find_serial_port(vendor_id=1256, serial_number=\"SN12345\")\n        dmm = Agilent34410(resource_name)\n\n    :param int vid: Vendor ID.\n    :param int pid: Product ID.\n    :param str sn: Serial number.\n    :return str: Port as a VISA string for a serial device (e.g. \"ASRL5\" or \"ASRL/dev/ttyACM5\").\n    \"\"\"\n    for port in sorted(list_ports.comports()):\n        if ((vendor_id is None or port.vid == vendor_id)\n                and (product_id is None or port.pid == product_id)\n                and (serial_number is None or port.serial_number == str(serial_number))):\n            # remove \"COM\" from windows serial port names.\n            port_name = port.device.replace(\"COM\", \"\")\n            return \"ASRL\" + port_name\n    raise AttributeError(\"No device found for the given data.\")\n", "path": "pymeasure/instruments/resources.py"}]}