Incrementing a tag

I am looking to create a tag that increments automatically by one. I would like to do so so I can simulate tank behaviors to make it look like it is filling a tank. I have seen various posts of creating a tag with a client timer. Is this the only way to create a tag to “increment” to a value that I can use to behave this way? Any suggesstions would be greatly appreciated.

If you load the Simulation driver, there are several ramp tags that would fit your needs.

Otherwise you can make a gateway script that increments a DB tag.

tag = "path.to.tag"
value = system.getTagValue(tag)
value = value + 1
system.tag.writeToTag(tag, value)

I was going to use a simulation driver. However I want to be able to manipulate the data that the counter is using. For example when it hits a certain level I would like to be able to stop the bit from counting and reset it

Do you just mean restarting the ramp, or actually setting the ramp to 0 and stopping the increment?

resetpoint = 1000
tag = "path.to.tag"

value = system.getTagValue(tag)
value = value + 1
if value >= resetpoint:
    value = 0

system.tag.writeToTag(tag, value)
enabletag = "path.to.enabletag" 
valuetag = "path.to.valuetag"
resetpoint = 1000

enabled = system.getTagValue(enabletag)
value = system.getTagValue(valuetag)
value = value + 1
if (value >= resetpoint) and (enabletag > 0):
    system.tag.writeToTag(enabletag, 0)    
    value = 0

system.tag.writeToTag(tag, value)
1 Like

I’m looking to actually reset the ramp to 0 and stop the increment

You cannot alter any of the ramp simulator tags since they are read-only.

I thought they were read-only. Are there any other ideas of what I could try? I was going to use a DB tag and attempt to increment it with a script and then reset to 0 when a certain number is reached. Does anyone have any other thoughts on what may work here?

Four ways come to mind for what you are doing.

Client Timer: quick and dirty, and lets you adjust speed and upper bounds on the fly. On the other hand, the client must be running (or the designer in preview mode) to work.

Client script: use a script like the one Mr. Buehler posted earlier. The client must actually be running for these to work.

Gateway script: same as a client script, but is always running on the gateway. Remember that any timing changes to the script must have the project saved for them to work.

Transaction group: you can do this with a transaction group running at whatever rate you wish. Not really an option on Panel Edition.