I have been trying to simulate values in Historian without great success. I'm very new to both the environment and VBscript itself.
I'm trying to simulate simple 1's and 0's. My goal is to make it run for 1-2 minutes, returning 1's. Then going down for 15-30 seconds; returns 0's. Both being random in amount of uptime and downtime.
If I understand the program correctly it will just fire the script every second. Meaning, I can't have sort of a global value which remembers, making it difficult to program... I've already tried playing with pronbabilities, like:
dim r
r = (int(rnd*100)+1)*10
IF r >= 35 THEN
Result = 1
ELSE
Result = 0
END IF
But this only takes into consideration for the uptime. When the downtime is registered, it is only registered for 1 second... :/
Does anyone have any experience or any ideas on how to implement a simple simulation code? Thanks!
Edit: I've been testing the inbuilt functions, trying to solve the problem with a counter that I could use to reset every time it hits a number. But I cannot get it to completely work:
pre = PreviousValue("TAG1","Now - 1Second")
IF PreviousQuality("TAG1","Now - 1Second") OR pre = -1 THEN
result = 0
END IF
IF pre >= 10 THEN
result = 0
ELSEIF pre < 10 THEN
result = AddData("TAG1",pre+1,"Now",100)
ELSE
result = -1
END IF
I just cannot get it to work... been starring myself blind.. :/
Edit 2: Seems like a daily journal by now.. :P But I managed to make a counter out of the code above with a tweak to it. Thought I only had to make another tag that then would return values 1s and 0s for a period of time. Apparently, Historian cannot keep up and spit out values while reading another tag...