How to log data based on an event
Many times we may not want historical data to run all the time. There may be times where we need to start logging when an action occurs and stop when this action has completed. Say for example we have an assembly line that begins sending items down the line when a button is pressed. Say we only want to log the data between button presses to calculate a pinpointed average for the amount of items sent down the line. We could theoretically do this with regular logging but then we have to find the individual runs instead of just looking at the timestamps.
Why would we need to do this?
- Create a log showing only the running time frames.
- Reduce the overall size of your historical log file, thus reducing data costs for transmission
- eWON Flexy or CD series unit
- eWON Programming guide
Implementation:There are two direct ways we can accomplish this.
- On a change to the tag
- On a trigger to start and stop
Example 1: On Value Change
In this example we are simply adding a single entry whenever the tag value changes. Instead of creating a massive log file every X number of seconds we can simply log a point on a value change.
Note: You must enable historical logging in your tag setup. You will not specify any intervals however. On your eWON, mimic the settings in the below snip.
INIT Section: ONCHANGE "MyTag", LOGIO "MyTag" REM - This one line of code allows us to log only on a change.
Example 2: On a Trigger
INIT Section: ONCHANGE "Trigger", "GOTO EnableLogging"
Now for the logging script:
EnableLogging Section: IF(Trigger@=1) THEN SETSYS TAG, "Load", "YourTagName" SETSYS TAG, "LogEnabled",1 //Enable logging SETSYS TAG, "SAVE" PRINT "Logging Enabled Successfully" ELSE SETSYS TAG, "LOAD", "YourTagName" SETSYS TAG, "LogEnabled",0 SETSYS TAG, "SAVE" PRINT "Logging Disabled Successfully" ENDIF END
Why use example 1?
Typically example one should be used when we would like to log a single entry at an event. Say for instance a machine is running and a valve opens, perhaps we want to get the value right when the valve opens. We don't need a run of data just a single entry. LOGIO works perfectly in these scenarios.
For more information on LOGIO, see page 66 of the Programming Reference Guide
Why use example 2?
Sometimes in more complex applications, we need to gather more data than just a single point. Example 2 is excellent for scenarios where we need to gather a run of data. Example 2 is very flexible and can be used in a wide array of applications to better control your historical logging.
For more information on SETSYS/GETSYS, see page 47 of the Programming Reference Guide