Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sebma opened this issue Aug 29, 2017 · 3 comments
Labels

Comments

@sebma
Copy link

sebma commented Aug 29, 2017

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 sebma changed the title ps2000.PS2000() and ps3000.PS3000() should raise the same exception when no picoscope is connected ps2000.PS2000() and ps3000.PS3000() should raise the same exception as ps2000a.PS2000a() when no picoscope is connected Aug 29, 2017
@hmaarrfk
Copy link
Collaborator

Unfortunately, it seems that there was a API change.
I'm not going to change this unless somebody with a ps2000 or ps3000 is able to test the changes.

TLDR:
Basically, do not use the non A API if you don't need to. If you have a reason to use them, please let me know. If you want me to implement some changes, please include the PDF of the API and refer to the page containing the OpenUnit function so I can review your proposed changes.

Long version:
The ps2000 uses this to open the picoscope

 m = self.lib.ps2000_open_unit()

In this case, m is the handle to the scope. There is no explicit way to test for errors correctly

The ps2000a uses this

 m = self.lib.ps2000aOpenUnit(byref(c_handle), serialNullTermStr)

where c_handle is the handle, serialNullTermStr is the serial number you want to open, and m is a variable containing the relevant error codes. This makes it easy to identify errors.

The ps3000 uses something similar.
I don't have time in the immediate future to go through the picotech API to explicitly read their documentation to find what is the correct way to go about this.

@sebma
Copy link
Author

sebma commented Aug 29, 2017

@hmaarrfk I understand

@hmaarrfk
Copy link
Collaborator

Hi @sebma, did you find a way to test for this? Did you want to submit a PR?

@hmaarrfk hmaarrfk changed the title ps2000.PS2000() and ps3000.PS3000() should raise the same exception as ps2000a.PS2000a() when no picoscope is connected PS2000 and PS3000 should raise better exceptions when no picoscope is connected Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants