Event detector with JS220

I am developing an event detector, it studies current levels and for now will print to console when a specific current range, limits duration conditions are met.

I have based my detector of the ‘detector.py’ example in Joulescope Scripting examples, I set current range mode parameters etc, and sampling frequency, subscribe to current data, and tie my callback to the current data being available.

My issue is that the ‘data_callback’ is triggered always at 50ms, and this appears to be fixed regardless of sample rate.

So if I set the sample rate is set to 1,000,000, data_callback() runs when 50,022 samples are available.

Then if I set the sample rate to 10,000, data_callback() runs when 500 samples are available.

Is there a way to control how this callback is generated, at present it seems fixed to 50ms duration is that as expected? For my detection logic (without getting into the detail) it would be much simplified if I could set this to approx 20ms interval

I have attached a condensed version of my detector script here:

P.S. First time poster here, but have been using the Joulescope since april 2025, really this is an excellent bit of kit! Congratulations to the Joulescope team on a great product!

js220_data.py (1.9 KB)

1 Like

Hi @hjw and welcome to the Joulescope forum!

The Joulescope JS220 delivers samples in chunks for two reasons:

  1. Samples are placed into USB Bulk frames, which are 512 bytes in size.
  2. USB Bulk frames are combined to reduce the host-side processing burden. See handle_stream_in_port, especially the end which determines when to send the (possibly) combined frame.

There is nothing we can do to change the behavior of (1), but we definitely have control over (2). The existing 20 Hz rate is somewhat arbitrary.

Rather than guide you through hacking the code, I created 1.12.0 which adds a new topic {device}/h/fp. This topic sets the approximate sample publish rate.

First, get the latest version:

python -m pip install -U pyjoulescope_driver

And then add this line to your code after publishing {device}/h/fs:

d.publish(f'{device}/h/fp', 50)

When you run the script, you should now see:

Length of Data Received: 20034

See commit a113037 for what changed to add this feature.

Does this work for you?

1 Like

Installed the latest pyjoulescope_driver and that works for me!

Thank you very much for the solution and the explanation.

1 Like