HLA Settings Default Values?

If I’m working on a new HLA, I might want to add new settings to it to enhance its behavior. Unfortunately, if I just add a new setting to the Python file and reload it in a capture session in Logic, the runtime error described in this thread (ValidationError: Missing setting...) is raised. The only workaround I’ve found is to delete the analyzer and re-add it to the capture session.

If a settings object could be instantiated with a default value, this issue could be avoided; in the absence of a setting already in the capture session, the default would be used.

The documentation for XxxxxxSettings objects is essentially nonexistent, and I can’t find the source for the Saleae HLA Python modules to figure it out myself. Is there a kwarg for the settings objects that would permit a default value to be specified?

Thanks to the inherently open-source nature of Python, I read the exception messages more carefully and realized I have the source code in Logic’s internal Python environment.

I’ve come up with a partial work-around by overriding the __new__ implementation of HighLevelAnalyzer in my subclass:

def __new__(cls, settings, *args, **kwargs):
    obj = super(HighLevelAnalyzer, cls).__new__(cls, *args, **kwargs)

    for setting in cls._get_settings():
        name = setting.name
        if name not in settings:
            if hasattr(setting, "default"):
                print(f'Using default setting for {name}: {setting.default}')
                settings[name] = setting.default
            else:
                raise ValidationError('Missing setting: ' + name)
        setting.validate(settings[name])
        setattr(obj, name, settings[name])

    return obj

The important bit is the four lines immediately following if name not in settings: which then checks if the Setting has a default attribute and, if so, uses it. Also important is that this calls HighLevelAnalyzer’s superclass __new__ (and not its own superclass) to skip over HighLevelAnalyzer’s implementation. Combine that with adding the defaults in the static initialization (whatever Python calls it):

my_new_setting = NumberSetting(min_value=0, max_value=30000, label='Interbyte Timeout (ms)')
my_new_setting.default = 150

The one drawback is that Logic doesn’t reinitialize the settings window when reloading the Extension, so those new settings won’t appear when selecting Edit. The only workaround I’ve found for that is to save the capture, then restart Logic.

Saleae Devs: Please consider adding a default= kwarg to Settings and have it function similarly to what I’ve implemented here. Also please make the settings window be reinitialized when an Extension is reloaded.

1 Like

@baebiebrian I’ve gone ahead and referenced this information in the bug report post I made below as well. Thanks for sharing that with us.

1 Like