Coverting word to bit status

What do you suggest I use in a workflow too convert a word to bit values?
For example 8 would be 0000 1000, and 12 would be 0000 1100, and so on?

Each bit would mean different alarms going on /off.

This is a common way to relay alarm information from PLC’s.

1 Like

At the moment, I think you would need to use a Function node, and write custom javascript to extract those values (take a look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators). But you are right, this is not an uncommon thing to need to do, and we should add some features around this into the workflow engine!

We do this a lot.

I usually have a data table with the bits defined along with the messages. For instance converting NFPA codes on a genset.

So I use the following to unpick the bits,

    payload.data.nfpa = []

    function intToUint(int, nbit) {
        var u = new Uint32Array(1);
        nbit = +nbit || 32;
        if (nbit > 32) throw new RangeError('intToUint only supports ints up to 32 bits');
        u[0] = int;
        if (nbit < 32) { // don't accidentally sign again
            int = Math.pow(2, nbit) - 1;
            return u[0] & int;
        } else {
            return u[0];
        }
    }

    payload.data.state_bits = intToUint(payload.data.running_state,16).toString(2).split("").reverse().join("");

Then will loop of state_bits using each item in the loop as the key for the item in the datatable.

A simple node to at least unpick the bits would be good.

I can build this in a custom node, but would prefer to run this on the agent, and custom nodes aren’t supported on agents. yet.

T

I don’t need it on the agent this time, so a custom node would work.

Any features around this yet?

Hey @Lars_Andersson,

Nothing yet. But, we just enabled voting on the feature request here in the forums. You should give this a vote!