Products > Test Equipment

Open source EEZ Studio for accessing your (SCPI) instruments

<< < (21/32) > >>

mvladic:
Can you send me the part of the script with fields definition and "await input", basically everything between "storage.getItem" and "storage.setItem".

Pjoms:
You are so welcome.
It is practically a plain copy of the start of the "Dlog start" script.



--- Code: ---var defaultValues = storage.getItem("LiPoChargeValues", {
    startCurrent: 1.5,
    stopCurrent: 0.1,
    maxChargeTime: 10,
});

var values = await input({
    title: "Start Dlog",
    fields: [
        {
            name: "startCurrent",
            displayName: "Charging current",
            unit: "current",
            validators: [validators.rangeInclusive(0.1, 5)]
        },
        {
            name: "stopCurrent",
            displayName: "End ocf charge current",
            unit: "current",
            validators: [validators.rangeInclusive(0.01, 0.5)]
        },
        {
            name: "maxChargeTime",
            displayName: "Max charging time",
            unit: "time",
            validators: [validators.rangeInclusive(1, 86400000)]
        }
    ]
}, defaultValues);

if (!values) {
    session.deleteScriptLogEntry();
    return;
}

storage.setItem("LiPoChargeValues", values);

session.scriptParameters = values;


--- End code ---

mvladic:
Let me give you some explanations first (sorry if you already know this):

The purpose of "storage.getItem" and "storage.setItem" is to remember (inside local storage which is kept even after Studio restarts) the last parameters that you entered, so when you start script again you will be greeted with same parameters you used last time. If you don't need this feature you can remove it, so your script can look like this:


--- Code: ---var defaultValues = {
    startCurrent: 1.5,
    stopCurrent: 0.1,
    maxChargeTime: 10,
};

var values = await input({
    title: "Start Dlog",
    fields: [
        {
            name: "startCurrent",
            displayName: "Charging current",
            unit: "current",
            validators: [validators.rangeInclusive(0.1, 5)]
        },
        {
            name: "stopCurrent",
            displayName: "End ocf charge current",
            unit: "current",
            validators: [validators.rangeInclusive(0.01, 0.5)]
        },
        {
            name: "maxChargeTime",
            displayName: "Max charging time",
            unit: "time",
            validators: [validators.rangeInclusive(1, 86400000)]
        }
    ]
}, defaultValues);

if (!values) {
    session.deleteScriptLogEntry();
    return;
}

session.scriptParameters = values;

--- End code ---

Also, to answer your question, any script can access this local storage items with "storage.getItem". Check this: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Now, If I start the script code you send me everything works fine on my computer. But, If I change the script slightly I can see the same error as you. This is changed script:


--- Code: ---var defaultValues = storage.getItem("LiPoChargeValues", {
    startCurrent: 1.5,
    stopCurrent: 0.1,
    maxChargeTime: 10,
});

var values = await input({
    title: "Start Dlog",
    fields: [
        {
            name: "startCurrent1", // "startCurrent" renamed to "startCurrent1"
            displayName: "Charging current",
            unit: "current",
            validators: [validators.rangeInclusive(0.1, 5)]
        },
        {
            name: "stopCurrent",
            displayName: "End ocf charge current",
            unit: "current",
            validators: [validators.rangeInclusive(0.01, 0.5)]
        },
        {
            name: "maxChargeTime",
            displayName: "Max charging time",
            unit: "time",
            validators: [validators.rangeInclusive(1, 86400000)]
        }
    ]
}, defaultValues);

--- End code ---

I changed "startCurrent" to "startCurrent1". The error is because defaultValues doesn't contain the value for "startCurrent1". But if I put "startCurrent1" inside defaultValues, everything is ok again:


--- Code: ---var defaultValues = storage.getItem("LiPoChargeValues", {
    startCurrent1: 1.5, // now, we have the value for "startCurrent1"
    stopCurrent: 0.1,
    maxChargeTime: 10,
});

var values = await input({
    title: "Start Dlog",
    fields: [
        {
            name: "startCurrent1",
            displayName: "Charging current",
            unit: "current",
            validators: [validators.rangeInclusive(0.1, 5)]
        },
        {
            name: "stopCurrent",
            displayName: "End ocf charge current",
            unit: "current",
            validators: [validators.rangeInclusive(0.01, 0.5)]
        },
        {
            name: "maxChargeTime",
            displayName: "Max charging time",
            unit: "time",
            validators: [validators.rangeInclusive(1, 86400000)]
        }
    ]
}, defaultValues);

--- End code ---

Maybe you also changed the fields definition for the input, but forget to change defaultValues?

Pjoms:
Thanks, that clarify and confirm a lot of what I was assuming.
But I'm afraid I'm still banging my head pretty hard here...  |O

I have tried some more, and from what I can understand it looks like the deal breaker here is if I chose Cancel or Ok in the dialog box!
As long as I click Cancel in the dialog box then I run the script the storage seems still undefined and I can change anything. But as soon I click Ok the values stores and that storage structure seems unable to be changed by modifying the input variabels, eg. change startCurrent to startCurrent1.

If I choose a new name for the storage, eg. change LiPoChargeValues to LiPoChargeValues1, it works again with the new variables.

I tried to remove the stored values, but width no luck... "storage.removeItem is not a function)
storage.removeItem('LiPoChargeValues');

I hope you can follow me here...

mvladic:
Which version of Studio do you use? Just to be sure we are on the same version.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod