Toggle GP0 on current and voltage condition

Hi everybody,

I would like to modify the downsample_logging.py script and act on the value of v and i
for example :
if v > Vthrehold and i <Ithreshold:
device.parameter_set(‘gpo0’,‘1’)
else :
device.parameter_set(‘gpo0’,‘0’)

i tried to put it in the on_statistics, which kind of work but i keep getting this messages:
WARNING API command u/js220/001101/s/gpo/+/!set invoked on jsdrv thread with timeout. Forcing timeout=0.
and eventually the script crashes.
Does anyone knows where to implement this condition?

Hi @guillermoasonlidtech and welcome to the Joulescope forum!

The on_statistics method is invoked from the underlying Joulescope driver thread. That warning indicates that it converted the parameter_set command from blocking to non-blocking. If I remember correctly, your changes should still work and not crash.

  1. Does the crash display any additional information?

  2. Do you see any difference if you directly call publish? Make these replacements:
    device.parameter_set(‘gpo0’,‘1’)device.publish('s/gpo/+/!set', 1, timeout=0)
    device.parameter_set(‘gpo0’,‘0’)device.publish('s/gpo/+/!clr', 1, timeout=0)

  3. Have you changed the statistics frequency? If you have significantly increased the frequency, then this could be unintentionally spamming the device. You really should only call set/clr when the value changes. On line 417, add self._gpi = False. Then in on_statistics:

[edited based upon @guillermoasonlidtech’s reply below]

gpi = (v > Vthrehold) and (i < Ithreshold)
if gpi == self._gpi:
    pass  # keep the same state
elif gpi:
    self._device.publish('s/gpo/+/!set', 1, timeout=0)
else:
    self._device.publish('s/gpo/+/!clr', 1, timeout=0)
self._gpi = gpi

Does this help?

Hi,

Many thanks for the promt answer!

it did work, for those trying to replicate instead of device use self._device

gpi = (v > Vthreshold) and ( i < Ithreshold)
if gpi == self._gpi:
    pass  # keep the same state
elif gpi:
    self._device.publish('s/gpo/+/!set', 1, timeout=0)
else:
    self._device.publish('s/gpo/+/!clr', 1, timeout=0)
self._gpi = gpi

Thank you

1 Like