LogWriter
Introduction
A Sequencer block for logging data with a message-based API. Compatible with the same Datastores as CDPLogger.
Glossary
This documentation refers to two kinds of events:
- CDP events - CDPEventManager events. For example, CDPAlarm Set, Clear and Acknowledge events. These are the events that are logged by CDP Logger, LogWriter and read by EventLogReader.
- Message events - the event inputs and outputs of sequencer blocks as defined by the IEC 61499 standard. In this document, also referred as event messages or just messages.
Usage
To set up a LogWriter, add it to a component. Next, select and add a Datastore (e.g. CDPCompactDatastore) into the LogWriter.
To write values, first send the WriteValueDefinition message to write the tags associated with the node providing values. Then send the WriteValue message to write the values. The WriteValue message event can be called multiple times for the same node. Finally, call the Flush message event to flush any internal buffers and commit the data to the datastore or wait until the AutoFlush triggers.
CDP events can be written in a similar way. First, call the WriteEventDefinition message to write the tags associated with the node emitting the CDP events. Then call the WriteEvent message to write an CDP event. As with values, either call Flush manually to make sure the data is committed to the datastore or wait until the AutoFlushTimeout triggers.
The following is a block diagram of the typical usage of the LogWriter block. See below for instructions on how to replicate the example.
Tips
- The LogWriter value inputs match the ValueLogReader outputs. This means that the LogWriter can be connected directly to the ValueLogReader and be used to extract either all or a subset of the logged data to a new datastore.
- Similarly, the LogWriter CDP event inputs match the EventLogReader outputs, so it can be used to extract CDP event data to a new datastore.
- The LogWriter CDP event inputs also match the CDPEventListener outputs. This can be used to log CDP events from a CDPEventListener to a datastore.
Configuration
See below for a list of configuration options specific to this block.
Datastore
Datastore is the backend used by LogWriter, usually some database. The default is CDPCompactDatastore.
For more information about datastores, see the Choosing a Datastore page.
Message Events
Name | Type | Description |
---|---|---|
Init | Input | Reinitializes the LogWriter block. Flushes any internal buffers and recreates the datastore connection. Will emit Inited when done. |
Inited | Output | Will be emitted after Init is done. |
WriteValue | Input | A single value change. The arguments must include Timestamp, Value, ValueType and Path. Optionally Tags and TagSources can be included to describe the tags associated with the value - in that case it is not necessary to call WriteValueDefinition before this message event. Will emit WriteValueDone or Error when done. Note: The WriteValue message event only writes tags and tag sources when encountering a Path for the first time. If the same Path is encountered again, the Tags and TagSources are not updated to prevent unintentional clearing of existing metadata. Use the WriteValueDefinition message event to replace existing tags and tag sources for a Path. |
WriteValueDone | Output | Will be emitted after WriteValue is done. |
WriteValueDefinition | Input | Writes logged node path and any associated tags. The arguments must include Path and Tags. Optionally TagSources can be included to describe the path where the tag information was fetched from. This message event should be called before WriteValue because some Datastores use the tags to optimize storage format. Will emit WriteValueDefDone or Error when done. If this message event is called multiple times for the same Path, the existing tags and tag sources are replaced. |
WriteValueDefDone | Output | Will be emitted after WriteValueDefinition is done. |
WriteEvent | Input | A single CDP event. The arguments must include Timestamp and Path, optionally also other CDP event data: Id, Code, Status, Text, Level, Desc and EventData. In addition, Tags and TagSources can be included to describe the tags associated with the CDP event sender - in that case, it is not necessary to call WriteEventDefinition before calling this. Will emit WriteEventDone or Error when done. Note: The WriteEvent message event only writes tags and tag sources when encountering a Path for the first time. If the same Path is encountered again, the Tags and TagSources are not updated to prevent unintentional clearing of existing metadata. Use the WriteEventDefinition message event to replace existing tags and tag sources for a Path. |
WriteEventDone | Output | Will be emitted after WriteEvent is done. |
WriteEventDefinition | Input | Writes the tags associated with the CDP event sender. The arguments must include Path and Tags. Optionally TagSources can be included to describe the path where the tag information was fetched from. This message event should be called before WriteEvent because some Datastores use the tags to optimize storage format. Will emit WriteEventDefDone or Error when done. If this message event is called multiple times for the same Path, the existing tags and tag sources are replaced. |
WriteEventDefDone | Output | Will be emitted after WriteEventDefinition is done. |
Flush | Input | Flushes internal buffers and commits data to the datastore. Will emit FlushDone or Error when done. |
FlushDone | Output | Will be emitted after Flush is done. |
Error | Output | Failure when writing data described by ErrorMsg. |
Writing Tags
The tags associated with a node can be written in two ways:
- Semicolon-separated tagname=value list in the Tags argument.
- Add each tag as a separate input argument with the tag name as the argument name and the tag value as the argument value. Note each user-added argument must be listed in the Data property of the message event.
This affects the WriteValue, WriteValueDefinition, WriteEvent and WriteEventDefinition message events.
Internal Message Events
When disabling the Hide Internal Items filter, some additional message events become visible. It is normally not necessary to access them.
Name | Type | Description |
---|---|---|
TriggerAutoFlush | Input | Called automatically after AutoFlushTimeout to flush internal buffers and commit data to datastore. Will emit AutoFlushDone or Error when done. |
AutoFlushDone | Output | Will be emitted after TriggerAutoFlush is done. |
Arguments
Name | Type | Description |
---|---|---|
Timestamp | Input | Unix timestamp of a value change or CDP event. The unit is specified by the TimeUnit attribute. |
Value | Input | The value change of a single node. |
ValueType | Input | The value type of a value change. Valid values are "undefined", "double", "uint64_t", "int64_t", "float", "unsigned int", "int", "unsigned short", "short", "unsigned char", "char", "bool" and "string". |
Path | Input | The path (full Routing) to a node that emitted the value change or generated the CDP event. |
Tags | Input | Semicolon-separated tagname=value list of all tags associated with a Path. |
TagSources | Input | Related to the Tags argument. Allows to optionally describe the path where the tag information was fetched from. The format is a semicolon-separated tagname=source list. |
Id | Input | System unique eventId (CDP eventId + application handle). Note: for CDP events it is unique only until the application restarts. |
Code | Input | CDP event code flags. See below for details. |
Status | Input | New status of the object that caused the CDP event after the CDP event occurred. For alarms see the Alarm Status Defines in CDPAlarm documentation. |
Text | Input | Optional text sent with the CDP event. |
Level | Input | Optional level data (for example sent with CDP alarm events). |
Desc | Input | Optional description sent with the CDP event. Describes the node that emitted the CDP event. |
EventData | Input | Semicolon-separated Name=Value pairs containing other optional data sent with the CDP event. |
ErrorMsg | Output | The error message emitted when a request fails. |
CDP Event Code Flags
Common event codes used in the CDP framework (note multiple flags can be set at the same time)): Common event codes used in the CDP framework (note that multiple flags can be set at the same time):
Name | Code | Description |
---|---|---|
AlarmSet | 0x1 | The alarm's Set flag/state was set. The alarm changed state to "Unack-Set" (The Unack flag was set if not already set). |
AlarmClr | 0x2 | The alarm's Set flag was cleared. The Unack state is unchanged. |
AlarmAck | 0x4 | The alarm changed state from "Unacknowledged" to "Acknowledged". The Set state is unchanged. |
AlarmReprise | 0x40 | A repetition/update of an event that has been reported before. Courtesy of late subscribers. |
SourceObjectUnavailable | 0x100 | The provider of the event has become unavailable (disconnected or similar). |
NodeBoot | 0x40000000 | The provider reports that the CDPEventNode has just booted. |
Properties
Name | Description |
---|---|
AutoFlushTimeout | When non-zero, after a specified number of seconds has passed from the last write, flushes any internal buffers and commits data to the datastore. |
Debug | The debug level. Increase it to see more printouts. |
LogFrequencyHint | Used by some datastores to optimize storage format. Should be set equal to the average sampling frequency of logged values. |
DatastoreSize | Current Datastore size in GB. |
TimeUnit | Unit of the Timestamp argument. Can be set to Second, Millisecond, Microsecond or Nanosecond since epoch (Unix timestamp). |
Accessing the Data
The data is written to the selected Datastore. Depending on the Datastore, the data can be accessed in different ways. For example, the CSVDatastore writes the data to a CSV file, which can be opened in a spreadsheet application. To access the written data with CDP tools, add a LogServer component and copy the Datastore configuration from the LogWriter. The LogServer component will then serve the data in the same way as the built-in server of CDP Logger.
There are several options to view logged data through the log server:
- Using CDP Studio Analyze mode Historic Data functionality which will detect a running CDP Logger or LogServer and connect to it. The Analyze mode can also be used to export the logged data to CSV format.
- Making your own GUI application that includes Database Graph Widget.
- Python code can query values from a running CDP Logger or LogServer using the PythonCDPLoggerClient.
- The ValueLogReader and EventLogReader sequencer blocks can be used to extract and process logged data.
The selected Datastore might provide other custom ways to view logged data. See the manual for the selected datastore to get specific information on that.
Note: CDP does not currently provide any widgets for browsing logged event data (e.g. CDPAlarm Set, Clear and Acknowledge events). Datastore-specific third-party tools must be used. If necessary, use the EventLogReader sequencer block and connect it to a LogWriter block to export event data to a different datastore, for example to CSV - see the example here.
Examples
Here are some examples of using the LogWriter.
Logging CDPEventListener Events
Here is a minimal example using the LogWriter. The example uses a CDPEventListener and writes every CDP event it emits to a CSV file.
To run the example, just start the application. The extracted values will be written to a "log-events.csv"
file in the application's working directory.
Here is how to replicate the example:
- Create a system.
- From the Resource tree, add
- Sequencer.CDPEventListener - a block that listens to all CDP events in the system and emits an event message for each CDP event. In this minimal example, we have not set any filters, so the block will emit all CDP events.
- CDPLogger.LogWriter - writes the received event messages to a new Datastore (CSVDatastore in this example).
- Add a CDPLogger.CSVDatastore into the LogWriter block to store extracted CDP events in a CSV file.
- Connect the blocks as shown in the image above.
Other Examples
See also some other examples containing the LogWriter:
- ValueLogReader and LogWriter - extract logged values from a CDP Logger datastore and write them to a new datastore.
- EventLogReader and LogWriter - extract logged events from a CDP Logger datastore and write them to a new datastore.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.