Hello I have a problem with the tag change event scritp.
I have a opc tag that is giving me the controller state of one inverter in a solar plant.
I need to register this states on the table of event. The problem is that the direfent states are given in one bit of the INT2, every bit on the word have a state. So i have made a script that check the value.
That working good, the problem is that with that when the int2 tag value change just in one bit, the rest of states are save in the event table too coz you can have more of one state in the same time. So in every single change in this tag, print this state and the rest of states that are still on. and making a lot of new rows in the event table that are repeat
[color=#008000]nuevo=newValue.value
if nuevo & (1 << 0):
accion=‘Deactivation from Radio Signal’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
if nuevo & (1 << 1):
accion=‘Deactivation caused by Overvoltage during limitation from power reduction’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
.
.
.
.[/color]
I would like to do something like that:
[color=#008000]nuevo=newValue.value
viejo=oldValue.value
if nuevo & (1 << 0) and not viejo & (1 << 0):
accion=‘Deactivation from Radio Signal’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
if nuevo & (1 << 1) and not viejo & (1 << 1):
accion=‘Deactivation caused by Overvoltage during limitation from power reduction’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
if nuevo & (1 << 2) and not viejo & (1 << 2):
accion=‘Voltage level to high for activation’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
if nuevo & (1 << 3) and not viejo & (1 << 3):
accion=‘AC Power Limitation caused by over frequency’
target=‘Inverter 9 - LOCAL MVL9’
system.db.runUpdateQuery(“INSERT INTO audit_events (EVENT_TIMESTAMP, ACTOR, ACTION, ACTION_TARGET, ACTION_VALUE, STATUS_CODE,ORIGINATING_SYSTEM, ORIGINATING_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar_plant’,2)” % (accion,target,nuevo))
.
.
.
.
[/color]
But i can not find the property that give me the old value.
PD: sorry for my english