HOW TO: Event driven historical logging

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

Requirements:

  • 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

1 Like

Based on the provided example with the LOGIO function for adding a single entry whenever the tag value (or config) changes, I struggled for a minute but figured out the issue.

It seems the LOGIO function needs to be within double quotes and its argument within single quotes in order for the eWON to not get a syntax error.

Example

ONCHANGE "<TagName>", "LOGIO '<YourTagName>'"
1 Like

@PJ_IOT

That is absolutely correct when using Logio as an argument for another action listener.
ONCHANGE in and of itself requires a tag and an argument (both in quotes). When using
LOGIO in a single line onchange definitely use quotes.

Nice catch!

@jseanor

Question

I wanted to confirm that if I have a tag of an Int or Bool type setup in Historical Logging with a Logging Deadband value of 1 and a Logging Interval of 0 that this solution would still work in that scenario to enable or disable historical logging based on the event?

Goal

The goal would be to setup the tag so it only logs when historical logging is enabled if the value changes by 1 in either direction (up or down) but have it become enabled only if another tag value changes and the conditions of the IF logic sets it up accordingly.

I assume this will work fine but wanted to run by you for confirmation.

1 Like

Hi @PJ_IOT

Yes that will work just fine!

The above script works by enabling the core logging function, it doesn’t actually update the logging parameters and directly relies on the options that you set there.

1 Like

Very cool @jseanor, this seems to work well, and in case someone else finds it helpful, below is the logic.

Basically when one tag’s value goes to 1 this will trigger the routine/function to enable the logging on multiple tags. When the other tag’s value goes to 1 that will trigger the routine/function to disable logging on multiple tags. In our case there will be time passed between each of those tags going to 1 and we do want separate tags dictating when to enable or disable logging.

Note: Yes, two separate tags explicitly set to TRUE in this case is by design but having the same tag go from TRUE to FALSE would work too from what I tested so adjust accordingly for your needs if you need something like this.

INIT Section:
ONCHANGE "TriggerTag1", "GOTO Check_Logging"
ONCHANGE "TriggerTag2", "GOTO Check_Logging"

Check_Logging:

//Enable Logging
IF(TriggerTag1@ = 1) THEN
    SETSYS TAG, "Load", "Tag1"
    SETSYS TAG, "LogEnabled",1
    SETSYS TAG, "SAVE"
    SETSYS TAG, "Load", "Tag2"
    SETSYS TAG, "LogEnabled",1
    SETSYS TAG, "SAVE"
    SETSYS TAG, "Load", "Tag3"
    SETSYS TAG, "LogEnabled",1
    SETSYS TAG, "SAVE"
    PRINT "Logging Enabled Successfully"
ENDIF

//Disable Logging
IF(TriggerTag2@ = 1) THEN
    SETSYS TAG, "Load", "Tag1"
    SETSYS TAG, "LogEnabled",0
    SETSYS TAG, "SAVE"
    SETSYS TAG, "Load", "Tag2"
    SETSYS TAG, "LogEnabled",0
    SETSYS TAG, "SAVE"
    SETSYS TAG, "Load", "Tag3"
    SETSYS TAG, "LogEnabled",0
    SETSYS TAG, "SAVE"
    PRINT "Logging Disabled Successfully"
ENDIF