Python automation script

Hi, I’m in the process of building the framework for collecting data from Joulescope. I tried to use the example scripts that you have posted but ran into this issue. I’m using linux Ubuntu OS and Joulescope is connected with USB port. Below is my issue. Can you please give me a pointer where I should look at first? Thank you.

File “capture_simple.py”, line 33, in
run()
File “capture_simple.py”, line 24, in run
device = scan_require_one(config=‘usb’)
File “/home/lab/.local/lib/python3.6/site-packages/joulescope/driver.py”, line 1118, in scan_require_one
raise RuntimeError(“no devices found”)
RuntimeError: no devices found

1 Like

Hi @atmosic and welcome to the forum! With linux, you first need to ensure that you have proper permissions to access the device. Check out this discussion.

You need to issue two commands:

$ lsusb -d 16d0:0e88
$ ls -al /dev/bus/usb/{bus}/{device}

Replacing {bus} and {device} with the values returned by lsusb. On my system, I see:

$ lsusb -d 16d0:0e88
Bus 002 Device 021: ID 16d0:0e88 MCS
$ ls -al /dev/bus/usb/002/021
crw-rw-rw- 1 root root 189, 148 Jun 26 19:07 /dev/bus/usb/002/021

If you don’t have sufficient permissions, you need to add a udev rule.

It looks like libusb was found, but just in case also do this:

sudo apt install libusb-1.0-0-dev

You should then be able to install the joulescope package (which you probably already have done):

pip3 install joulescope

Then try:

python3 -m joulescope gpo_demo

Here is the expected output:

INFO:joulescope.usb.libusb.device:scan found ['16d0/0e88/000416']
INFO:joulescope.usb.device_thread:open
INFO:joulescope.usb.device_thread:DeviceThread.run start
INFO:joulescope.usb.libusb.device:close
INFO:joulescope.usb.libusb.device:open: start 16d0/0e88/000416
INFO:joulescope.usb.libusb.device:open: success
INFO:joulescope.usb.libusb.device:open: configure device
INFO:joulescope.usb.libusb.device:open: done
INFO:joulescope.driver:info:
{
  "type": "info",
  "ver": 1,
  "ctl": {
    "mfg": {
      "country": "USA",
      "location": "MD_01",
      "lot": "201927_00"
    },
    "hw": {
      "rev": "H",
      "sn_mcu": "820A303182C45FAA8EE51A954091005F",
      "sn_mfg": "000416"
    },
    "fw": {
      "ver": "1.1.0"
    },
    "fpga": {
      "ver": "0.2.0",
      "prod_id": "0x9314acf2"
    }
  },
  "sensor": {}
}
INFO:joulescope.driver:serial number = 28a00313284cf5aae85ea159041900f5
INFO:joulescope.driver:stop : streaming=False
INFO:joulescope.usb.device_thread:close
INFO:joulescope.usb.libusb.device:close
INFO:joulescope.usb.libusb.device:ControlTransferAsync.close 0
INFO:joulescope.usb.device_thread:DeviceThread._cmd_process_all close
INFO:joulescope.usb.device_thread:DeviceThread.run flush
INFO:joulescope.usb.device_thread:DeviceThread.run done

Please post with what you see on your machine. Thanks!

Hi mliberty, the steps are right on the dot. it works for me now. thanks.

1 Like

Matt, I have another question about pyjoulescope examples/bin/current_range_extract.py

When I run this file: python3 current_range_extract.py test.jls --plot

I’m getting this traceback message below, do you have any idea how to go about to fix this issue? Also is there a pyjoulescope script to capture data for a duration and save it as jls file?
Thanks in advance for your assistance.

DataReader 41.63 seconds (83252736 samples)
sampling_frequency = 2000000.0
samples_per_reduction = 20000
samples_per_tlv = 400000
samples_per_block = 2000000
Traceback (most recent call last):
File “current_range_extract.py”, line 114, in
sys.exit(run())
File “current_range_extract.py”, line 90, in run
current_range = load_current_range(args.filename)
File “current_range_extract.py”, line 77, in load_current_range
data = r.raw()
AttributeError: ‘DataReader’ object has no attribute ‘raw’

Yes! This script is actually part of the joulescope package. Unfortunately, I just tried it and it was not fully updated for the most recent 0.8.3 changes. I just fixed it in the develop branch.

If you get the “develop” branch from GitHub, you can try this:

python3 -m joulescope capture --help

Otherwise, I plan to release the next version this week.

I will take a look at the current_range_extract script and see what’s up.

If I used an older ver 0.7.0, does the current capture.py work? Thanks

Yes, and it’s pretty easy:

pip3 install joulescope==0.7.0
python3 -m joulescope capture --contiguous 1.0 out.jls

When you are done and want the latest, you can use:

pip3 install -U joulescope

That works for 0.7.0. Thanks for the help. Now, if I’d like to extract a mean value of current A from the captured sample file for that duration (let’s say 5 secs), is there such a script available today?

I just fixed current_range_extract.py in the “develop” branch. It now works with 0.8.3.

It also contains a good snippet that be modified for your purpose, something like this:

def load_average_current(filename):
    r = DataReader().open(filename)
    try:
        print(r.summary_string())
        r_start, r_stop = r.sample_id_range
        if r_stop - r_start > MAX_SAMPLES:
            print('file too big')
            return 1
        d = r.samples_get(fields=['current'])
        return np.mean(d['signals']['current']['value'])
    finally:
        r.close()

I’m getting this issue when I tried to run your updated script.

$ python3 current_range_extract_1.py ~/joulescope/out.jls --out out.txt
DataReader 4.80 seconds (9600000 samples)
sampling_frequency = 2000000
samples_per_reduction = 20000
samples_per_tlv = 400000
samples_per_block = 2000000
Traceback (most recent call last):
File “current_range_extract_1.py”, line 107, in
sys.exit(run())
File “current_range_extract_1.py”, line 83, in run
current_range = load_current_range(args.filename)
File “current_range_extract_1.py”, line 74, in load_current_range
d = r.samples_get(fields=[‘current_range’])
File “/home/lab/.local/lib/python3.6/site-packages/joulescope/data_recorder.py”, line 1011, in samples_get
t1, t2 = start / self.sampling_frequency, stop / self.sampling_frequency
TypeError: unsupported operand type(s) for /: ‘NoneType’ and ‘float’

You are right, it does not work with 0.8.3. It works with the in-progress 0.8.5 code :frowning_face:.

I will be working on getting the 0.8.5 release out tomorrow. You can either go back to 0.7.0, or just wait until then. Sorry for the delay!

With 0.7.0, I am getting this error: AttributeError: ‘DataReader’ object has no attribute ‘samples_get’ .
At this point, I’ll wait until tomorrow for 8.5 release. Thanks

You can now download pyjoulescope 0.8.6 using pip:

pip install joulescope

You will also need to “git pull” to the latest pyjoulescope_examples. I tried current_range_extract.py just to be sure:

> python3 bin\current_range_extract.py 20200227_000302.jls --plot
DataReader 7.40 seconds (14805504 samples)
sampling_frequency = 2000000.0
samples_per_reduction = 20000
samples_per_tlv = 400000
samples_per_block = 2000000

and here is what I see:

Your image will vary based upon the actual data file.

I apologize for the difficulty in getting this running. We have also tested and fixed all the examples to run with 0.8.6, so you should be good to bo. Please let me know if you run into any futher issues!

I’m getting this syntax error when I use pip install joulescope command:

Collecting joulescope
Using cached https://files.pythonhosted.org/packages/3a/ae/0bac2317245a9aa51b6bf287dbb38f1dfc44989e465b1bcdd8eec78659b9/joulescope-0.4.6.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File “”, line 1, in
File “/tmp/pip-build-Je9FC_/joulescope/setup.py”, line 42
fv.write(f’VERSION = “{VERSION}”\n’)
^
SyntaxError: invalid syntax

Woah, 0.4.6 is an old version (July 15, 2019) of the joulescope python package. Try this:

pip install -U joulescope

You should get 0.8.6.

Thanks for the info and I was able to install 0.8.6 now. I have another question. When I run the script to capture, it seems like joulescope restarts the power supply to the device under test. As a result, it causes a reset on DUT and I can’t read accurate measurements. Is this a known issue? If so, are there a workaround?

Hi @atmosic
Which capture script are you running? Are you doing something like:

python -m joulescope capture --contiguous 1.0 ..\out.jls

Your Joulescope can turn power on and off to the target, but the default settings should keep it on. For example, joulescope/entry_points/capture.py uses:

device = scan_require_one(name='Joulescope', config='auto')