colinoflynn / pico-python

PicoScope Python Interface
Other
101 stars 80 forks source link

Correct DC50 enum: 2 -> 50 #191

Closed thennen closed 1 year ago

thennen commented 1 year ago

PS6000a range changed the enum for DC50 coupling from 2 to 50.

hmaarrfk commented 1 year ago

is this true for all firmware versions? for all library versions? maybe we need to condition on the version of the library itself before making this change.

thennen commented 1 year ago

Good question. Hard to know for sure without trying it out on every old dll/firmware. I certainly wouldn't expect them to change the enum between versions. Do you know of any other instances of that happening?

I contacted support and they didn't know either. But they are checking it out.

You can see the information in Pico Technology\SDK\inc\ directory:

in PicoDeviceEnums.h (used by ps6000aApi.h):

typedef enum enPicoCoupling
{
  PICO_AC = 0,
  PICO_DC = 1,

  PICO_DC_50OHM = 50
} PICO_COUPLING;

vs. ps6000Api.h

typedef enum enPS6000Coupling
{
  PS6000_AC,
  PS6000_DC_1M,
  PS6000_DC_50R
} PS6000_COUPLING;
hmaarrfk commented 1 year ago

maybe this is why i broke my scope like 10 years ago..

thennen commented 1 year ago

Well, AndrewA at picoscope support confirmed: "PICO_DC_50OHM enum values were never changed"

So, I think it's safe to merge.

hmaarrfk commented 1 year ago

so which one is the correct value? 2 or 50?

thennen commented 1 year ago

For reference, here is the error I ran into that is fixed by this change.

In [4]: print(ps.getAllUnitInfo())
DriverVersion                 : ps6000a Windows Driver, 1.0.116.3546
USBVersion                    : 3.0
HardwareVersion               : 1.3
VariantInfo                   : 6426E
BatchAndSerial                : JY198/0032
CalDate                       : 07Jun23
KernelVersion                 : 1.0
DigitalHardwareVersion        : 1
AnalogueHardwareVersion       : 3
PicoFirmwareVersion1          : 1.7.16.0
PicoFirmwareVersion2          : 1.1.4.0

In [5]: ps.CHANNEL_COUPLINGS['DC50'] = 2
In [6]: ps.setChannel('A', 'DC50')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[6], line 1
----> 1 ps.ps.setChannel('A', 'DC50')

File ~\Anaconda3\lib\site-packages\picoscope-0.7.20+3.gce48c63-py3.8.egg\picoscope\picobase.py:296, in _PicoscopeBase.setChannel(self, channel, coupling, VRange, VOffset, enabled, BWLimited, probeAttenuation)
    292     # 20kHz Bandwidth Limiter for PicoScope 4444
    293 else:
    294     BWLimited = 0
--> 296 self._lowLevelSetChannel(chNum, enabled, coupling,
    297                          VRangeAPI["apivalue"],
    298                          VOffset / probeAttenuation, BWLimited)
    300 # if all was successful, save the parameters
    301 self.CHRange[chNum] = VRange

File ~\Anaconda3\lib\site-packages\picoscope-0.7.20+3.gce48c63-py3.8.egg\picoscope\ps6000a.py:461, in PS6000a._lowLevelSetChannel(self, chNum, enabled, coupling, VRange, VOffset, BWLimited)
    458 else:
    459     m = self.lib.ps6000aSetChannelOff(c_int16(self.handle),
    460                                       c_enum(chNum))
--> 461 self.checkResult(m)

File ~\Anaconda3\lib\site-packages\picoscope-0.7.20+3.gce48c63-py3.8.egg\picoscope\picobase.py:1153, in _PicoscopeBase.checkResult(self, errorCode)
   1151 ecName = self.errorNumToName(errorCode)
   1152 ecDesc = self.errorNumToDesc(errorCode)
-> 1153 raise IOError('Error calling %s: %s (%s)' % (
   1154     str(inspect.stack()[1][3]), ecName, ecDesc))

OSError: Error calling _lowLevelSetChannel: PICO_INVALID_COUPLING (An invalid coupling type was specified in psXXXXSetChannel.)

In [7]: ps.CHANNEL_COUPLINGS['DC50'] = 50
In [8]: ps.setChannel('A', 'DC50')
Out[8]: 2.0
thennen commented 1 year ago

so which one is the correct value? 2 or 50?

50

hmaarrfk commented 1 year ago

What is the meaning of the return value of 2.0 in:

In [7]: ps.CHANNEL_COUPLINGS['DC50'] = 50
In [8]: ps.setChannel('A', 'DC50')
Out[8]: 2.0
thennen commented 1 year ago

That is the "Actual range of the scope as double" returned by _PicoscopeBase.setChannel.

in this case, 2.0 is the default value.

https://github.com/colinoflynn/pico-python/blob/1747100291d2c3d86eee17e90de0abc633f947e6/picoscope/picobase.py#L306C11-L306C11

hmaarrfk commented 1 year ago

I see. can you add a release note

hmaarrfk commented 1 year ago

oh we have no release notes lol

BenediktBurger commented 1 year ago

Thanks for that fix. I encountered the error as well, but did not investigate further, as I did not need it.

When I created the ps6000a file, I took the enum from ps4000a (and there the value is 2) as I expected them to have the same enum values...

Finally it is solved, thanks a lot @thennen!

hmaarrfk commented 1 year ago

amazing. thank you for the confirmation that this works!!!