TimeProject is a comprehensive event logging and timestamping system built using TwinCAT 3. It is designed to operate within industrial automation environments, offering capabilities to monitor, record, and maintain a persistent history of events for subsequent analysis and review.
The TimeProject aims to provide:
- Event Logging: Real-time capture of events, precise timestamp assignment, and immediate buffering for processing.
- Persistent Storage: Assurance that events are stored in a manner that allows them to persist through system restarts, available for recovery and analysis, typically in a CSV format.
Such a system is crucial in industrial settings for troubleshooting, conducting audits, process optimization, and meeting traceability and compliance requirements.
This project is based on the educational content created by Jakob Sagatowski as part of his TwinCAT 3 tutorial series. All credit for the original concept and instructional design goes to him.
Find his tutorials on YouTube
And my notes on these tutorials here.
TwinCAT 3 Environment:
System Manager Version: v3.1.0 (Build 4329)
TwinCAT Version: v3.1.4024.25
Software/Package | Link |
---|---|
TwinCAT 3 | Download TwinCAT 3 |
To get started with the TimeProject, clone this repository and open the .sln
file in TwinCAT 3.
- Open the project in TwinCAT 3.
- Compile the project and load it onto your target PLC.
- Ensure all dependencies, including
Tc2_Utilities
, are resolved.
The project relies on several TwinCAT 3 libraries and external types. Ensure that the following are included in your environment before compiling and running the project:
- Tc2_Utilities: Used for handling file time (
FILETIME
) and converting it to DATE_AND_TIME format. - Tc2_System: Contains function blocks such as
FB_FileOpen
,FB_FilePuts
, andFB_FileClose
for file operations. - Tc2_Standard: Provides standard functions like
CONCAT
for string operations.
To log an event:
- Set the appropriate variables for event type, severity, identifier, and text.
- Call the
AddEvent
method on theEventLogger
instance with these variables.
To view logged events:
- Access the
Events.log
file in the specified directory of the PLC's file system.
To facilitate a comprehensive understanding of the TimeProject's functionality and its codebase, I have provided a series of detailed diagrams along with their descriptions. Through these diagrams, users and developers can gain insights into the project's underlying structure, making it easier to navigate the code, implement modifications, or troubleshoot issues.
The following images depict the project's main components, their interconnections, and the flow of data across the system:
E_EventType
: An enumeration that defines the types of events, such as Alarms or Messages, enabling easy categorization and filtering of logged events.TcEventSeverity
: An enumeration provided by the TwinCAT library that classifies the severity of an event into categories like Verbose, Info, Warning, Error, and Critical.
A structured data type that encapsulates all necessary information about an event, including:
eEventType
: The event type fromE_EventType
.eEventSeverity
: The event severity fromTcEventSeverity
.nEventIdentity
: A unique identifier for the event.sEvenText
: A descriptive text string describing the event.dtTimestamp
: The date and time when the event occurred.
This function let's us update an event's timestamp with the current system time to ensure accuracy.
A function block responsible for:
- Buffering events with its
AddEvent
method. - Initialization through
FB_init
, which links to persistent storage mechanisms.
Implements the I_PersistentEventStorage
interface for persistent event storage, specifically:
- Writing events to a CSV file on the PLC's file system.
- Managing file operations through a state machine to open, write to, and close files systematically.
Defines a standard contract for persistent event storage across different implementations, ensuring a consistent approach to event storage.
The main program that:
- Triggers event logging based on specific conditions.
- Ensures the
FB_CsvPersistentEventStorage
is executed in every PLC cycle for consistent logging and storage.
TimeProject is released under the MIT License. It is shared for educational purposes and is not officially affiliated with Beckhoff or TwinCAT. Please use and share responsibly, giving credit to the original author and sources.
You can contact me here: