Transformations when reading Modbus data

Thanks for posting! This is a good example for how to pass values to a script transform (note it works for all the languages, not just JS Scripting).

You can go one step further and use an inline JS transform.

JS( | parseFloat(inputData) / 10 )

No separate .js file or transform needs to be defined at all. This is obviously better for one-off transforms than when you need to do it a lot of times.

Also, don’t forget that the Modbus add-on comes with an Offset Profile which can add/subtract/multiply/divide the value by a constant and append a unit where needed.

I’ve also slowly come to the conclusion that this wrapping is unnecessary. The transform scripts are being executed pretty much in isolation. The only global area it can pollute is for this one script in which case, who cares if the variables are global? Nothing but this one script is going to see them.

1 Like