HOW TO: Create a custom historical log file in BASIC

How to create a custom historical log file for a tag

The historical recording of the Flexy can be very powerful tool for monitoring your process data, however the default recording system does come with some limitations. In certain scenarios it may make sense to build your own custom historical file. The intent of this post is to teach you how to do just that.

Why create a custom historical file?

    • Create a log with the colums you want.
    • In the default recording you are unable to 'pick and choose' what columns to display. By creating a custom historical record, we can display only the fields desirable to you.
    • Add custom messaging into the historical records.
    • Display custom threshold values for data types.
    • Example: If a boolean is good instead of writing 1 or 0 I want to write ON or OFF

Requirements:

  • eWON Flexy
  • eWON Programming guide

Implementation:

For the purposes of this demonstration we will be writing a custom log file for a tag named Tank Level and Valve. For each entry I would like to display the current value for Tank Level and whether the valve is OPEN or CLOSED. We will additionally display the tag name and date/time stamp for each record. Finally, we will be writing on a 1 second interval though this is configurable.

INIT Section:
NOTE: REM denotes a comment. It does not control anything programmatic and is merely there for informational purposes. 

fileName$ = "YourfileName"
i% = 1 REM - This INTEGER value controls the interval of our logging. 
TSET 1, i% REM - Begin a 1 second interval timer. 
ONTIMER 1, "GOTO WriteRecord"
END

WriteRecord Section:
valveStatus$ = "" REM - Because I will be saying open/closed instead of 0/1 I need a string to track this. 
IF(Valve@ = 0) THEN
     valveStatus$ = "OPEN"
ELSE
     valveStatus$ = "CLOSED"
ENDIF


REM - Now below we will verify if the file exists on first cycle. If it doesn't we will create the file and write the header. If it does exist we will just append the tag data. 
SETSYS PRG, "RESUMENEXT", 1
CLOSE 1 REM - Close the file just in case.
OPEN fileName$ FOR BINARY INPUT AS 1
ErrorReturned = GETSYS PRG, "LSTERR"
IF(ErrorReturned = 33) THEN
    CLOSE 1
    OPEN fileName$ FOR BINARY OUTPUT AS 1
    PUT 1, "Time,TagName,Value"
    CLOSE 1
ELSE
    CLOSE 1
    OPEN fileName$ FOR BINARY APPEND AS 1
    PUT 1, Time$ + ",TankLevel," + STR$ TankLevel@ + CHR$(13)+ CHR$(10)
    PUT 1, Time$ + ",Valve Status," +  valveStatus$ + CHR$(13)+ CHR$(10)
    CLOSE 1
ENDIF
END


That is it! This will create a custom log file. You can see an example of the log below.

myrecord.csv (3.2 KB)

This can be highly customized and is intended to just be a starting point.

1 Like

Update 2-22

Hi , is this code completed ? I tried to run it for one of my application and it gives me the following error :

‘=’ expected(3) 10 : INIT Section:

Thank you !

Can you send me the .txt file you’re trying to run?