pico-python icon indicating copy to clipboard operation
pico-python copied to clipboard

PS2000 and PS3000 should raise better exceptions when no picoscope is connected

Open sebma opened this issue 6 years ago • 3 comments

Hi,

When no picoscope is connected, ps2000a.PS2000a() raises IOError: Error calling _lowLevelOpenUnit: PICO_NOT_FOUND (No PicoScope XXXX could be found.) which is perfectly normal :

$ python2
Python 2.7.13 (default, Jul 18 2017, 09:17:00)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from picoscope import ps2000, ps2000a, ps3000, ps3000a, ps4000, ps4000a, ps5000a, ps6000, __path__ as picoscopePATHS
>>> ps2000a.PS2000a()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/xyztxyzt/src/pico-python/picoscope/ps2000a.py", line 154, in __init__
    super(PS2000a, self).__init__(serialNumber, connect)
  File "/Users/xyztxyzt/src/pico-python/picoscope/picobase.py", line 134, in __init__
    self.open(serialNumber)
  File "/Users/xyztxyzt/src/pico-python/picoscope/picobase.py", line 798, in open
    self._lowLevelOpenUnit(serialNumber)
  File "/Users/xyztxyzt/src/pico-python/picoscope/ps2000a.py", line 164, in _lowLevelOpenUnit
    self.checkResult(m)
  File "/Users/xyztxyzt/src/pico-python/picoscope/picobase.py", line 840, in checkResult
    raise IOError('Error calling %s: %s (%s)' % (str(inspect.stack()[1][3]), ecName, ecDesc))
IOError: Error calling _lowLevelOpenUnit: PICO_NOT_FOUND (No PicoScope XXXX could be found.)

But ps2000.PS2000() does not raise any exception :

>>> ps2000.PS2000()
>>>

and ps3000.PS3000() raises an exception with an unclear error message :

>>> ps3000.PS3000()
Exception IOError: IOError(u'Error calling _lowLevelCloseUnit',) in <bound method PS2000.__del__ of <picoscope.ps2000.PS2000 object at 0x108882250>> ignored
>>>

All ps2000a, ps3000a, ps4000, ps4000a, ps5000a, ps6000 raise the same exception when no picoscope is connected :

IOError: Error calling _lowLevelOpenUnit: PICO_NOT_FOUND (No PicoScope XXXX could be found.)

Can you please fix this and raise the same exception (as the other modules) for ps2000 and ps3000 modules (when no picoscope is connected) ?

sebma avatar Aug 29 '17 10:08 sebma