Repository: pymeasure/pymeasure

Issue:
Migrating Prologix / AR488 from 0.10. to 0.11. VI_ERROR_RSRC_NFOUND 
Hi, I'm having an issue after updating to 0.11, I understand that the implementation of the PrologixAdapter has changed, previously I was creating an adapter with this code:

`adapter = PrologixAdapter(port='/dev/cu.usbserial-AC008NYI',baudrate=115200,serial_timeout=1)`
now this doesn't work anymore and as far as I understand from the tutorial it should be updated to:
`adapter = PrologixAdapter('/dev/cu.usbserial-AC008NYI')`

This doesn't work and cannot find a solution, this is the error that I get:
`---------------------------------------------------------------------------
VisaIOError                               Traceback (most recent call last)
/var/folders/s_/k_qsdmpn09ng7xgzq1lrkjbm0000gn/T/ipykernel_13441/652802221.py in <module>
      6 import math
      7 import time
----> 8 adapter = PrologixAdapter('/dev/cu.usbserial-AC008NYI')
      9 #adapter = PrologixAdapter(port='/dev/cu.usbserial-AC008NYI',baudrate=115200,serial_timeout=1)
     10 sourcemeter = Keithley2000(adapter.gpib(16))

~/opt/anaconda3/lib/python3.9/site-packages/pymeasure/adapters/prologix.py in __init__(self, resource_name, address, rw_delay, serial_timeout, preprocess_reply, **kwargs)
     82             warn("Use 'timeout' in ms instead", FutureWarning)
     83             kwargs['timeout'] = serial_timeout
---> 84         super().__init__(resource_name,
     85                          asrl={
     86                              'timeout': 500,

~/opt/anaconda3/lib/python3.9/site-packages/pymeasure/adapters/visa.py in __init__(self, resource_name, visa_library, preprocess_reply, query_delay, log, **kwargs)
    106 
    107         # Clean up kwargs considering the interface type matching resource_name
--> 108         if_type = self.manager.resource_info(self.resource_name).interface_type
    109         for key in list(kwargs.keys()):  # iterate over a copy of the keys as we modify kwargs
    110             # Remove all interface-specific kwargs:

~/opt/anaconda3/lib/python3.9/site-packages/pyvisa/highlevel.py in resource_info(self, resource_name, extended)
   3172 
   3173         if extended:
-> 3174             ret, err = self.visalib.parse_resource_extended(self.session, resource_name)
   3175         else:
   3176             ret, err = self.visalib.parse_resource(self.session, resource_name)

~/opt/anaconda3/lib/python3.9/site-packages/pyvisa/ctwrapper/functions.py in parse_resource_extended(library, session, resource_name)
   2075     # [ViSession, ViRsrc, ViPUInt16, ViPUInt16, ViAChar, ViAChar, ViAChar]
   2076     # ViRsrc converts from (str, unicode, bytes) to bytes
-> 2077     ret = library.viParseRsrcEx(
   2078         session,
   2079         resource_name,

~/opt/anaconda3/lib/python3.9/site-packages/pyvisa/ctwrapper/highlevel.py in _return_handler(self, ret_value, func, arguments)
    224                 session = None
    225 
--> 226         return self.handle_return_value(session, ret_value)  # type: ignore
    227 
    228     def list_resources(

~/opt/anaconda3/lib/python3.9/site-packages/pyvisa/highlevel.py in handle_return_value(self, session, status_code)
    249 
    250         if rv < 0:
--> 251             raise errors.VisaIOError(rv)
    252 
    253         if rv in self.issue_warning_on:

VisaIOError: VI_ERROR_RSRC_NFOUND (-1073807343): Insufficient location information or the requested device or resource is not present in the system.`

Thanks for the help! 


Discussion:
In 0.11 Prologix is now inherited from pyvisa, your original code should work with following comments:
- `baudrate` should be renamed `baud_rate`
- instrument address should be conform to pyvisa addressing names

I think you are facing the second problem at the moment. Are you able to list pyvisa resources in your system?


Hi, if I run pymeasure.instruments.list_resources()
this is what I get:
`0 : ASRL1::INSTR : Not known`
it might be the first time I actually try to use a VISA resource since before I was using the previous implementation
Should a com port appear there or do I need to add it manually? 
Thanks 

I think you could try using address "ASRL1::INSTR" and baud_rate=115200 and this should work, if ASLR1 is the address of your instrument.
adapter = PrologixAdapter("ASRL1::INSTR",baud_rate=115200, timeout=1000)
worked
but then gave me this error 
`---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/s_/k_qsdmpn09ng7xgzq1lrkjbm0000gn/T/ipykernel_14345/225292594.py in <module>
     11 #adapter = PrologixAdapter('ASRL/dev/tty.usbserial-AC008NYI', 4)
     12 adapter = PrologixAdapter("ASRL1::INSTR",baud_rate=115200, timeout=1000)
---> 13 sourcemeter = Keithley2000(adapter.gpib(16))
     14 generator = Instrument(adapter.gpib(4),"PH5190")
     15 time.sleep(1)

~/opt/anaconda3/lib/python3.9/site-packages/pymeasure/adapters/prologix.py in gpib(self, address, **kwargs)
    189         :returns: PrologixAdapter for specific GPIB address
    190         """
--> 191         return PrologixAdapter(self, address, **kwargs)
    192 
    193     def _check_for_srq(self):

~/opt/anaconda3/lib/python3.9/site-packages/pymeasure/adapters/prologix.py in __init__(self, resource_name, address, rw_delay, serial_timeout, preprocess_reply, **kwargs)
     82             warn("Use 'timeout' in ms instead", FutureWarning)
     83             kwargs['timeout'] = serial_timeout
---> 84         super().__init__(resource_name,
     85                          asrl={
     86                              'timeout': 500,

~/opt/anaconda3/lib/python3.9/site-packages/pymeasure/adapters/visa.py in __init__(self, resource_name, visa_library, preprocess_reply, query_delay, log, **kwargs)
     98             self.resource_name = getattr(resource_name, "resource_name", None)
     99             self.connection = resource_name.connection
--> 100             self.query_delay = resource_name.query_delay
    101             return
    102         elif isinstance(resource_name, int):

AttributeError: 'PrologixAdapter' object has no attribute 'query_delay'`

if I add
`self.query_delay = rw_delay `
in  def __init__() in prologix.py 
all seems to work
could this be that as this is not a original prologix adapter (it's an arduino with https://github.com/Twilight-Logic/AR488 ) it gets recognised differently by visa (as a generic serial device)?
I think, this is linked to a problem in 0.11 described in #760. This issue is now fixed in the current code base, but it's obviously present in release 0.11. In #760, you should find also a workaround that avoids to change the pymeasure code.
Additionally, you find some alternative way of specifying address according to pyvisa needs, e.g. something like ASLR/dev/...
Finally, I don't think the problems you are facing are linked to the fact that your adapter is not a genuine Prologix, in all cases if you spot any relevant difference, you could try to customize the adapter for Arduino and possibly submit a PR in the future.
Thanks for the help, I will try the next update but now it seems to be working fine. 


I just released version 0.11.1, please check if this fixes this issue for you.
Hi, yes it works without editing prologix.py, but I think the documentations is out of date, the example for a prologix adapter still says:
```
from pymeasure.adapters import PrologixAdapter
adapter = PrologixAdapter('/dev/ttyUSB0')
```
Otherwise, thanks for the help! 
@pignoniG thanks for pointing out outdated documentation. I did not find that line in a quick search, could you please tell me, where you found that documentation?
Hi @bmoneke that particular part was in [https://pymeasure.readthedocs.io/en/latest/tutorial/connecting.html#using-adapters](url) But I think also [https://pymeasure.readthedocs.io/en/latest/api/adapters.html#prologix-adapter](url) should be updated, the parameters are still for the previous version, if I'm not mistaken. 
Thanks @pignoniG, that helps a lot. I see, we have to touch the tutorial and best the docstring as well. 

Resolving patch:
diff --git a/pymeasure/adapters/prologix.py b/pymeasure/adapters/prologix.py
--- a/pymeasure/adapters/prologix.py
+++ b/pymeasure/adapters/prologix.py
@@ -32,13 +32,16 @@ class PrologixAdapter(VISAAdapter):
     to communicate over a Prologix GPIB-USB Adapter,
     using the :class:`VISAAdapter`.
 
-    Each PrologixAdapter is constructed based on a serial port or
-    connection and the GPIB address to be communicated to.
-    Serial connection sharing is achieved by using the :meth:`.gpib`
+    Each PrologixAdapter is constructed based on a connection to the Prologix device
+    itself and the GPIB address of the instrument to be communicated to.
+    Connection sharing is achieved by using the :meth:`.gpib`
     method to spawn new PrologixAdapters for different GPIB addresses.
 
-    :param port: The Serial port name or a connection object
-    :param address: Integer GPIB address of the desired instrument
+    :param resource_name: A
+        `VISA resource string <https://pyvisa.readthedocs.io/en/latest/introduction/names.html>`__
+        that identifies the connection to the Prologix device itself, for example
+        "ASRL5" for the 5th COM port.
+    :param address: Integer GPIB address of the desired instrument.
     :param rw_delay: An optional delay to set between a write and read call for
         slow to respond instruments.
 
@@ -54,7 +57,18 @@ class PrologixAdapter(VISAAdapter):
 
     :param kwargs: Key-word arguments if constructing a new serial object
 
-    :ivar address: Integer GPIB address of the desired instrument
+    :ivar address: Integer GPIB address of the desired instrument.
+
+    Usage example:
+
+    .. code::
+
+        adapter = PrologixAdapter("ASRL5::INSTR", 7)
+        sourcemeter = Keithley2400(adapter)  # at GPIB address 7
+        # generate another instance with a different GPIB address:
+        adapter2 = adapter.gpib(9)
+        multimeter = Keithley2000(adapter2)  # at GPIB address 9
+
 
     To allow user access to the Prologix adapter in Linux, create the file:
     :code:`/etc/udev/rules.d/51-prologix.rules`, with contents:


Test patch: