Repository: pymeasure/pymeasure

Issue:
PyVISA keyword `delay` replaced by `query_delay`
So, since pyVISA 1.6 (quite some time ago), it seems that the `delay` kwarg needs to be replaced by `query_delay` - I think we just missed that.
https://pyvisa.readthedocs.io/en/latest/faq/migrating.html#removal-of-instrument-delay-and-added-instrument-query-delay
As we [still have](https://github.com/ralph-group/pymeasure/blob/e48f9d679d6ee970e2e875d2fc9a5679378b07aa/pymeasure/adapters/visa.py#L59) the `delay` defined as safe, we should change that to `query_delay`.
The only other place that I found (with Github) where we used that is [in an Agilent device](https://github.com/ralph-group/pymeasure/blob/07cf309b8d113931525c8cc216cc704f2b7ff413/pymeasure/instruments/agilent/agilent8257D.py#L248).
@cjermain is this something where we need to keep API consistency with other adapters beside the VISAAdapter, or do we just change those two spots and be done? I think the latter, just want to make sure.


Discussion:
Thanks for raising this @bilderbuchi. I agree that it is reasonable to replace the `delay` field with `query_delay`. It's not clear to me if the Agilent case requires the write delay, so `query_delay` is likely a good replacement. If that need does arise, we could always implement it with `time.sleep` in the adapter.

Resolving patch:
diff --git a/pymeasure/adapters/visa.py b/pymeasure/adapters/visa.py
--- a/pymeasure/adapters/visa.py
+++ b/pymeasure/adapters/visa.py
@@ -56,7 +56,7 @@ def __init__(self, resourceName, visa_library='', **kwargs):
         self.resource_name = resourceName
         self.manager = visa.ResourceManager(visa_library)
         safeKeywords = ['resource_name', 'timeout',
-                        'chunk_size', 'lock', 'delay', 'send_end',
+                        'chunk_size', 'lock', 'query_delay', 'send_end',
                         'values_format', 'read_termination', 'write_termination']
         kwargsCopy = copy.deepcopy(kwargs)
         for key in kwargsCopy:
diff --git a/pymeasure/instruments/agilent/agilent34410A.py b/pymeasure/instruments/agilent/agilent34410A.py
--- a/pymeasure/instruments/agilent/agilent34410A.py
+++ b/pymeasure/instruments/agilent/agilent34410A.py
@@ -43,7 +43,7 @@ class Agilent34410A(Instrument):
     
     resistance_4w = Instrument.measurement("MEAS:FRES? DEF,DEF", "Four-wires (remote sensing) resistance, in Ohms")
     
-    def __init__(self, adapter, delay=0.02, **kwargs):
+    def __init__(self, adapter, **kwargs):
         super(Agilent34410A, self).__init__(
             adapter, "HP/Agilent/Keysight 34410A Multimeter", **kwargs
         )
diff --git a/pymeasure/instruments/agilent/agilent8257D.py b/pymeasure/instruments/agilent/agilent8257D.py
--- a/pymeasure/instruments/agilent/agilent8257D.py
+++ b/pymeasure/instruments/agilent/agilent8257D.py
@@ -245,7 +245,7 @@ def config_low_freq_out(self, source='internal', amplitude=3):
         map_values=True
     )
 
-    def __init__(self, adapter, delay=0.02, **kwargs):
+    def __init__(self, adapter, **kwargs):
         super(Agilent8257D, self).__init__(
             adapter, "Agilent 8257D RF Signal Generator", **kwargs
         )


Test patch:
diff --git a/tests/adapters/test_visa.py b/tests/adapters/test_visa.py
--- a/tests/adapters/test_visa.py
+++ b/tests/adapters/test_visa.py
@@ -21,8 +21,23 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 # THE SOFTWARE.
 #
+import importlib.util
+
+import pytest
+from pytest import approx
 
 from pymeasure.adapters import VISAAdapter
+from pymeasure.instruments import Instrument
+
+pyvisa_sim_installed = bool(importlib.util.find_spec('pyvisa-sim'))
+
 
 def test_visa_version():
-  assert VISAAdapter.has_supported_version()
+    assert VISAAdapter.has_supported_version()
+
+
+@pytest.mark.skipif(not pyvisa_sim_installed, reason='pyvisa-sim required but not found.')
+def test_correct_visa_kwarg():
+    """Confirm that the query_delay kwargs gets passed through to the VISA connection."""
+    instr = Instrument(adapter='ASRL1::INSTR', name='delayed', query_delay=0.5, visa_library='@sim')
+    assert instr.adapter.connection.query_delay == approx(0.5)