Skip to content

Latest commit

 

History

History
124 lines (89 loc) · 6.17 KB

File metadata and controls

124 lines (89 loc) · 6.17 KB

TimeProject for TwinCAT 3

Overview

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.

Objectives

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.

Acknowledgments

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.

Requirements

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

Getting Started

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.

Dependencies

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, and FB_FileClose for file operations.
  • Tc2_Standard: Provides standard functions like CONCAT for string operations.


Usage

To log an event:

  1. Set the appropriate variables for event type, severity, identifier, and text.
  2. Call the AddEvent method on the EventLogger instance with these variables.

To view logged events:

  1. Access the Events.log file in the specified directory of the PLC's file system.

Project Components

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 and TcEventSeverity (Enums)

  • 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.

ST_Event (STRUCT)

A structured data type that encapsulates all necessary information about an event, including:

  • eEventType: The event type from E_EventType.
  • eEventSeverity: The event severity from TcEventSeverity.
  • nEventIdentity: A unique identifier for the event.
  • sEvenText: A descriptive text string describing the event.
  • dtTimestamp: The date and time when the event occurred.


UpdateEventTimestampWithSystemTime (FUNCTION)

This function let's us update an event's timestamp with the current system time to ensure accuracy.

EventLogger (FB)

A function block responsible for:

  • Buffering events with its AddEvent method.
  • Initialization through FB_init, which links to persistent storage mechanisms.

FB_CsvPersistentEventStorage (FB)

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.

I_PersistentEventStorage (INTERFACE)

Defines a standard contract for persistent event storage across different implementations, ensuring a consistent approach to event storage.

MAIN (PRG)

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.


License

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.

Contact Information

You can contact me here: