Event driven historical logging

I’ve been working on a project using a flexy and I need to save some tags (40 tags) from diferents PLC’s by event but I had a problem about event repetition when I save them in the Historical Logging.

The script I use is similar to this:

ONCHANGE “event_plc1”,“GOTO EVENT_LOG”

EVENT_LOG:
Setsys Tag,“load”,“TAG_NAME” REM ENABLE Historical logging & Interval Datalogger = 1 seg.
g$=Getsys Tag,“IVgroupA”
If g$=“1” Then
Setsys Tag, “LogEnabled”,“1”
Setsys Tag, “LogDB”,“0”
Setsys Tag, “LogTimer”,“1”
Setsys Tag, “save”
Endif
Cfgsave

Setsys Tag,“load”,“TAG_NAME” REM ENABLE Historical logging & Interval Datalogger = 0 seg.
g$=Getsys Tag,“IVgroupA”
If g$=“1” Then
Setsys Tag, “LogEnabled”,“1”
Setsys Tag, “LogDB”,"-1"
Setsys Tag, “LogTimer”,“0”
Setsys Tag, “save”
Endif
Cfgsave

The script is supposed to save the tag value to the HL and then only enable the “LogEnabled”.

I’ve tried to change Setsys Tag, “LogDB”,“0” to Setsys Tag, “LogDB”,"-1" in the first part but with this change I didn’t see anything in the Historical Logging.

PS. I use this final config.:
Setsys Tag, “LogEnabled”,“1”
Setsys Tag, “LogDB”,"-1"
Setsys Tag, “LogTimer”,“0”
Because I’m using datamailbox and if I don’t enable the HL Logging I can’t get all the historic data from a group. (group A in my case)

Thank you

@Adria_Garcia

Are you trying to enable logging over a period of time or just log the tag once after the event is triggered?

I just want to log the tag once after the event is triggered

@Adria_Garcia

If you are only trying to log the tag once then I recommend our logio function.

Example:

ONCHANGE "event_plc1", " LOGIO 'IVgroupA' " REM - This one line of code allows us to log only on a change. 

If you are on firmware 12.2 or above then you can also log a whole group of tags using Log group IO.

Example:

ONCHANGE "event_plc1", LoggroupIO("A") // logs all tags in group "A" one time on a change

I’ll try it. Is it possible to use logio function by tag not by group? I’m asking that because if I need to log tags from more than 4 PLCs I would need more than four groups and there are only Group A,B,C and D.

Thank you

@Adria_Garcia

Yes, you can definitely do it by tag and not by group.
This first example above only does it for the tag called IVgroupA.

ONCHANGE "event_plc1", " LOGIO 'IVgroupA' " REM - This one line of code allows us to log only on a change.  

I tried to log using loggroupio as you told me and It works, the repetitions have disappered. I would want to know if it’s possible to use logio function by index or I should write this function for each tag I have.

Thank you.

@Adria_Garcia

You can set a deadband in each of your tags in the tag setup which would not require scripting. This would act as an ONCHANGE but when it changes by a certain amount. Is the an option for you? Typically you wouldn’t use the deadband logging if you have 1 event triggering the logging of all your tags but it seems you want all your tags to log only if they change which is what deadband was created to do.

Additionally, you could use scripting to set an ONCHANGE for all your tags.
Example below:

If you want all your tags to use logio then you can use a FOR loop in the INIT section to set the ONCHANGE listener for all your tags.

Init section:
C% = GETSYS PRG, "NBTAGS"
FOR i% =0 TO (C%-1) // all your tags
   SETSYS Tag, "load", -i%
   t$ = GETSYS Tag, "Name"
   ONCHANGE t$, '@logTag(t$)'
NEXT i%

Function logTag($tagName$)
  Print "LOGGING " + $tagName$
  LOGIO $tagName$
ENDFN

The problem with this solution is that I don’t want to log all the tags at each event. I would want to log some of them. How could I sort tags out? By changing their names?

I have another question, I’m having some problems in an installation I’ve found several times the “schedule execution module” switch turned off. How is it possible? How can fix it?

Thank you

@Adria_Garcia

What are you considering an event? The examples above show how to log certain groups.
Additionally, the latest script does not log all tags at each tag change. It sets an ONCHANGE listener for all your tags but only only logs the tag that changes.

I’d take a look at this thread as well as this may be something your interested in doing:

Can you provide a screenshot of the schedule execution module? I’m not sure what you are referring to.

Hello Joe,

I’m considering an event a change in a data memory from the plc. My init script is something like that:

  ONCHANGE "Event", GOTO "log_tags" (event is a memory from the PLC and log_tags is a part from the script where the tags are logged).

I don’t want to log a tag that is changing (as it happens with the deadband), I want to log a number of tags when the event is triggered. I did it successfully but I asked that because I want to optimize the script. Right now my script is similar to:

ONCHANGE “Event_from_plc1”, goto “log_tags_plc1”

ONCHANGE “Event_from_plc2”, goto “log_tags_plc2”

log_tags_plc1:

logio “tag_1_from_plc1”

logio “tag_2_from_plc1”

logio “tag_3_from_plc1”

logio “tag_N_from_plc1”

log_tags_plc2:

logio “tag_1_from_plc2”

logio “tag_2_from_plc2”

logio “tag_3_from_plc2”

logio “tag_N_from_plc2”

I would want to know if its possible to use a simplified code. I don’t want to do it by groups (loggroupio) because there are only 4 and It’s possible that I’m goign to need more.

I’ve attached the screenshot of the schedule execution module.

Thank you so much Joe!

@Adria_Garcia

You can use the tag description instead of a group to sort your tags.

Once you a have description set in your tag setup then you can load the description for your tags and use an IF statement to determine whether to log it or not.

Example below:


ONCHANGE "my_bit", "GOTO logPLC1"
ONCHANGE "my_bit2", "GOTO LOGPLC2"
C% = GETSYS PRG, "NBTAGS" // load tag amount
END

logPLC1:
FOR C% = 0 TO (C%-1)
   SETSYS Tag, "load", -C%
   t$ = GETSYS Tag, "Name"
   d$ = GETSYS Tag, "Description"
   If d$ = "PLC 1" THEN LOGIO t$
   NEXT C%
END

LOGPLC2:
FOR C% = 0 TO (C%-1)
   SETSYS Tag, "load", -C%
   t$ = GETSYS Tag, "Name"
   d$ = GETSYS Tag, "Description"
   If d$ = "PLC 2" THEN LOGIO t$
   NEXT C%
END