How to query if joulescope device is already open

Hi all,

I’m looking for a way to query if joulescope device is already open so I won’t get the error below.
“2024-08-15 16:53:10 ERROR open_ll but already open”

Code:

     for device in dmms:
        try:
            device.active_device.open()  # try to open resource
        except:
            pass

Hi @jj110 and welcome to the Joulescope forum! That logging error message comes from the joulescope_driver C backend. Although I don’t recommend it, you can disable all logging errors from this backend:

import logging
logging.getLogger('jsdrv').setLevel(logging.CRITICAL)

The CRITICAL level will filter and reject the ERROR log message.

The Joulescope API does not have a way to detect that the device is already open without just trying to open it. You could change the log level for just this call and restore it afterwards if you really want to do this.

In my experience, it is rarely the right choice to just open the first non-open Joulescope when you have multiple Joulescopes attached. You often want to open a specific Joulescope to make a measurement rather than hoping the one you want is the first non-open Joulescope. It’s usually much better to provide a filter based on serial number using some configuration method, such as a command-line argument. You can use the serial_number attribute to get the serial number before opening the device.

Does this make sense and address the issue?

Hi @mliberty, thank you for the reply. Your answer is helpful but while debugging, I realised my real question is how to keep dut_power ON. I’m getting the error because I’m not using joulescope.close() or context manager because it’s powering down the dut. Please see the example code below

inititalize_dut()    #  slow process
time.sleep(1)

# Do test1
with js_dev:
    do_measurement1()


# dut power down here, measurement1 and measurement2 is run by pytest

# Do test2
with js_dev:
    do_measurement2()

Hi @jj110 - Your Joulescopes keep the path from Current+ to Current- enabled by default when you close the Joulescope. Here is code to demonstrate:

import joulescope
import time

device = joulescope.scan_require_one()
for i in range(10):
    print('open')
    with device:
        time.sleep(1)
    print('close')
    time.sleep(1)

I used an LED and power supply set to 10 mA limit to check that the LED remained illuminated through these cycles using both a JS110 and JS220.

Here is my platform information:

PS C:\> python -VV
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
PS C:\> pip show joulescope pyjoulescope_driver
Name: joulescope
Version: 1.1.15
Summary: Joulescope™ host driver and utilities
Home-page: https://joulescope.readthedocs.io
Author: Jetperch LLC
Author-email: joulescope-dev@jetperch.com
License: Apache 2.0
Location: C:\bin\Python3_12_4\Lib\site-packages
Requires: numpy, psutil, pyjls, pyjoulescope-driver, pymonocypher, python-dateutil, pywin32
Required-by:
---
Name: pyjoulescope_driver
Version: 1.5.4
Summary: Joulescope™ driver
Home-page: https://joulescope.readthedocs.io
Author: Jetperch LLC
Author-email: joulescope-dev@jetperch.com
License: Apache 2.0
Location: C:\bin\Python3_12_4\Lib\site-packages
Requires: numpy, psutil, pywin32, requests
Required-by: joulescope

I am not sure exactly what you are seeing. Can you provide runnable code that demonstrates the problem?

Thanks @mliberty for the script. You are right it’s a different issue. The symptom mislead my debugging. For now, I will just mask the error until I find the real culprit. Thanks for the help.

1 Like