Write parameter values from a dashboard
Цей контент ще не доступний вашою мовою.
This guide adds writes to a dashboard you develop locally. The write API is described in
Live data in dashboards, and the write controls
in Dashboard UI and forms. Writing needs the
operator role or higher.
Offer a write only where it can succeed
Section titled “Offer a write only where it can succeed”- Check the parameter’s metadata with
isParameterValueWritable(parameter)before you offer an edit or a command. - Offer the edit only while the value it changes is current (
isCurrentParameterValue). - Offer a command only while the device will act on it. To turn a command off while the device is
disconnected, pass
disabledand keep the control mounted, so a command already being sent still reports its result.
Choose one write model per editor
Section titled “Choose one write model per editor”Pick one model for every control in an editor. Do not mix them.
- Drafts and Apply, usual for device editors with several fields: fields stay uncommitted until Apply sends the changed fields. Live tiles keep showing the device’s values from reads, not the drafts.
- Immediate write: every control writes when it changes. The editor then has no Apply or submit button.
Send confirmed changes in one batch
Section titled “Send confirmed changes in one batch”- Collect the fields the operator confirmed and send them with one
writeValuescall fromuseParameterValueActions(). It follows the writes with a targeted read. - Before a change of several fields, open a confirmation dialog that lists only the changed fields
as old value to new value.
ParameterWriteReviewDialogdoes this and returns the keys of the failed changes; mark the matching form fields with them. - Handle each
output.results[paramId]separately. Writes are not a transaction:- Commit the successful fields at once.
- Keep the failed drafts and show each error on its field.
- Do not roll back successful siblings.
- Show a failure of the whole request in the form banner.
- Show each failure where the operator is looking, inside an open confirmation too. Let the operator cancel or try again, even if trying again means reopening the dialog. Cancelling must not make the failed write look applied. The write controls already do this.
- Keep the operator’s unsaved drafts while new readings arrive.
- Show write errors inline, in the dashboard’s language, built from
codeandreason(such aswrite_value_below_min). Never show the Englishmessage. A success toast is optional. - A write acknowledgement is not the device’s physical result. Where the device has a feedback parameter, read it before you tell the operator that the command took effect.
When the fields are part of a form that saves through the API, build it as described in Build a form that saves through the API.
Write in a fixed order
Section titled “Write in a fixed order”One writeValues batch does not guarantee the order in which the device applies the writes. When a
device needs an order, such as a password before a command:
- Use
ParameterWriteSequenceDialog. It writes one step at a time, stops at the first step that is not acknowledged, and names that step. - For a single command button, use
DeviceCommandButton, which wraps the dialog. - For a section of device settings, use
DeviceSettingsSectionwith a writeplan; see Build a dashboard for one device model. - When a step’s value must be current at the time of writing, such as a clock set to the time of
sending, pass
stepsas a function.
With your own interface on executeParameterWriteSequence, check permissions and ask for
confirmation yourself; the function does neither.
Ask for a device password
Section titled “Ask for a device password”- Pass
secrettoParameterWriteSequenceDialog, orunlocktoDeviceCommandButtonorDeviceSettingsSection. The dialog shows a masked field and writes the typed password in a step before the others, without reading it back. - When the device may already be unlocked on HMI’s connection, set
optional. - To offer the last password that worked while the page is open, keep it in component state from
onSentand pass it back asinitialValue. - Never put a password in
steps, in the dashboard configuration, or in browser storage.
Write without an operator action
Section titled “Write without an operator action”A dashboard can call writeValues from its own code when readings change, with nobody pressing
anything. For example, it starts a pump when the tank level reaches a start mark, stops it at a
stop mark, or sends a controller a stricter start limit while a temperature is too high. This code
runs only while the dashboard is open in a browser.
Each such command depends on some readings: the start condition, such as a level or a temperature, and the equipment’s own feedback, such as a running relay.
- Check those readings per command with
isCurrentParameterValueor a reader with{ current: true }. Treat anullfromevaluateParameterConditionas unknown, not as false. - Decide for each command what it does when one of its readings is not current:
- A reading that is not current never starts equipment.
- It does not block the writes that make equipment safer, or stops whose own readings are current.
- Do not use a single check that skips every write unless all readings are current. It breaks the second rule: if the temperature stops updating, the stricter start limit is never sent and the controller keeps the looser one, and a second pump with a current level and relay reading never gets its normal stop.
- Keep equipment protection in the controller. Closing the dashboard stops these commands without sending a final stop, and limits already written stay on the controller.
Test automatic writes
Section titled “Test automatic writes”- Run the code with made-up readings and record the writes it requests instead of sending them.
- Compare those writes with the ones you expect in each of these cases:
- a start condition reading goes stale, is still loading, fails, or is missing;
- another pump reaches its stop mark meanwhile;
- a reading equals a start or stop mark exactly;
- readings recover;
- manual mode, where nothing is written automatically;
- after the dashboard closes, when nothing more is written.