Having a random timeout problem with Keithley 2400 that is driving me nuts and became a challenge.
In the experiment the constant voltage is sourced, and I only read current. I need to do it for as long as I can continuously.
Does not matter fast or slow and how many timeouts and error catchers are implemented.
This is my code. Managed to capture the visa timeout error (by 'try' first and re-establish connection after an exception was raised) but now a new problem.
The firmware is C32 from October 14, 2010. I have three of these Keithleys and they behave the same.
It looks to me like sometimes the instrument throws a strange message that cannot be interpreted.
Using serial RS232 protocol and 'pymeasure' that is based on 'pyvisa'.
Re-starting the script solves the problem, sometimes with an error about header.
---------------------------------------------------------------------------
VisaIOError Traceback (most recent call last)
Cell In [9], line 64
63 try:
---> 64 keithley.measure_current(nplc=0.01, current=10e-6, auto_range=False)
65 time.sleep(0.1)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/keithley/keithley2400.py:434, in Keithley2400.measure_current(self, nplc, current, auto_range)
433 self.current_range = current
--> 434 self.check_errors()
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/keithley/keithley2400.py:524, in Keithley2400.check_errors(self)
522 """ Logs any system errors reported by the instrument.
523 """
--> 524 code, message = self.error
525 while code != 0:
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/instrument.py:211, in Instrument.__getattribute__(self, name)
209 raise AttributeError(
210 f"{name} is a reserved variable name and it cannot be read")
--> 211 return super().__getattribute__(name)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/keithley/keithley2400.py:514, in Keithley2400.error(self)
512 """ Returns a tuple of an error code and message from a
513 single error. """
--> 514 err = self.values(":system:error?")
515 if len(err) < 2:
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/instrument.py:317, in Instrument.values(self, command, separator, cast, preprocess_reply)
306 """ Writes a command to the instrument and returns a list of formatted
307 values from the result.
308
(...)
315 :returns: A list of the desired type, or strings where the casting fails
316 """
--> 317 results = str(self.ask(command)).strip()
318 if callable(preprocess_reply):
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/instrument.py:303, in Instrument.ask(self, command, query_delay)
302 self.wait_for(query_delay)
--> 303 return self.read()
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/instrument.py:263, in Instrument.read(self, **kwargs)
262 """Read up to (excluding) `read_termination` or the whole read buffer."""
--> 263 return self.adapter.read(**kwargs)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/adapters/adapter.py:107, in Adapter.read(self, **kwargs)
100 """Read up to (excluding) `read_termination` or the whole read buffer.
101
102 Do not override in a subclass!
(...)
105 :returns str: ASCII response of the instrument (excluding read_termination).
106 """
--> 107 read = self._read(**kwargs)
108 self.log.debug("READ:%s", read)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/adapters/visa.py:150, in VISAAdapter._read(self, **kwargs)
145 """Read up to (excluding) `read_termination` or the whole read buffer.
146
147 :param kwargs: Keyword arguments for the connection itself.
148 :returns str: ASCII response of the instrument (excluding read_termination).
149 """
--> 150 return self.connection.read(**kwargs)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pyvisa/resources/messagebased.py:486, in MessageBasedResource.read(self, termination, encoding)
485 termination = self._read_termination
--> 486 message = self._read_raw().decode(enco)
487 else:
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pyvisa/resources/messagebased.py:442, in MessageBasedResource._read_raw(self, size)
436 logger.debug(
437 "%s - reading %d bytes (last status %r)",
438 self._resource_name,
439 size,
440 status,
441 )
--> 442 chunk, status = self.visalib.read(self.session, size)
443 ret.extend(chunk)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pyvisa/ctwrapper/functions.py:2337, in read(library, session, count)
2336 return_count = ViUInt32()
-> 2337 ret = library.viRead(session, buffer, count, byref(return_count))
2338 return buffer.raw[: return_count.value], ret
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pyvisa/ctwrapper/highlevel.py:226, in IVIVisaLibrary._return_handler(self, ret_value, func, arguments)
224 session = None
--> 226 return self.handle_return_value(session, ret_value)
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pyvisa/highlevel.py:251, in VisaLibraryBase.handle_return_value(self, session, status_code)
250 if rv < 0:
--> 251 raise errors.VisaIOError(rv)
253 if rv in self.issue_warning_on:
VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In [9], line 105
102 keithley.write_timeout = None
103 del keithley.timeout
--> 105 keithley.measure_current(nplc=0.01, current=10e-6, auto_range=False)
106 time.sleep(0.1)
108 keithley.stop_buffer()
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/keithley/keithley2400.py:434, in Keithley2400.measure_current(self, nplc, current, auto_range)
432 else:
433 self.current_range = current
--> 434 self.check_errors()
File /Applications/xapps/miniconda3/envs/scipy/lib/python3.9/site-packages/pymeasure/instruments/keithley/keithley2400.py:527, in Keithley2400.check_errors(self)
525 while code != 0:
526 t = time.time()
--> 527 log.info("Keithley 2400 reported error: %d, %s" % (code, message))
528 code, message = self.error
529 if (time.time() - t) > 10:
TypeError: %d format: a number is required, not str