Status Word Tag to Single State Integer

I got some integer tags which bits represents distinct states. I require to convert to an integer tag that represents its state.

Any idea how to best implement this?

My initial approach is to use expression tag, and enable history. I am afraid though this will induce runtime log?

Second approach is to implement on gateway script, and do a write query to database for history?

What do you guys think?

Expression tag if you need history. Expression in the UI otherwise.

Consider using the binEnum() function if the bits turn on only one at a time.

Ain’t Expression fall same issue with tag value change event limitation? "Tag Change" gateway event script vs "Value Changed" tag value event

Expression tags have different execution pool from tag event scripts. And expressions are much more efficient than jython. (Don't use runScript() in your expressions to minimize chances of trouble.)

1 Like

Hope I am not bothering.

What is the random integer range I need to generate, to hit the first (least significant) 16 bit of integer tag.

Background:
16 bit from PLC is stored as Integer (Tag) in Ignition.
I want to exercise, write random integer value to bit change the least 16 bit of Integer type.

Edit:
I got a quick answer from AI

random_16bit = random.randint(0, 65535)
print(random_16bit)

or

random_16bit = random.randint(-32768, 32767)
print(random_16bit)

shoot I got this.