A logging session is associated with a dagroup object. Before you start a logging session, you will need to ensure that the logging session is correctly configured. This section explains how you can control
• The duration of a logging session (see “Control the Duration of a Logging Session” on page 7-18). By default, a group will log approximately one minute of data at half second intervals.
• The destination of logged data (see “Control the Logged Data Destination” on page 7-19). By default, a group will log data to memory.
• The response to events that take place during a logging session (see “Configure Logging Callbacks” on page 7-20). By default, a logging session takes no action in response to events that take place during a logging session.
Control the Duration of a Logging Session
While you cannot guarantee that a logging session will take a specific amount of time (see “How OPC Toolbox Software Logs Data” on page 7-15), you can control the rate at which the server will update the items and how many records the logging task should store before automatically stopping the logging task. You control these aspects of a logging task by using the following properties of the dagroup object:
Log OPC Server Data
7-19
• UpdateRate: The UpdateRate property defines how often the item values are inspected.
• RecordsToAcquire: The RecordsToAcquire property defines how many records OPC Toolbox software must log before automatically stopping a logging session. A logging task can also be stopped manually, using the stop function.
• DeadbandPercent: The DeadbandPercent property does not control the duration of a logging task directly, but has a significant influence over how often a data change event is generated for analog items (an item whose value is not confined to discrete values). By setting the DeadbandPercent property to 0, you can ensure that a data change event occurs each time a value changes. For more information on DeadbandPercent, consult the property reference page.
You can use the UpdateRate and RecordsToAcquire properties to define the minimum duration of a logging task. The duration of a logging task is at least
UpdateRate * RecordsToAcquire
For example, if the UpdateRate property is 10 (seconds) and the RecordsToAcquire property is 360, then provided that a data change event is generated each time the server queries the item values, the logging task will take 3600 seconds, or one hour, to complete.
Control the Logged Data Destination
OPC Toolbox software allows you to log data to memory, to a disk file, or both memory and a disk file. When logging data to memory, you can log only as much data as will fit into available memory. Also, if you delete the dagroup object that logged the data without extracting that data to the MATLAB workspace, the data will be lost. The advantage of logging data to memory is that logging to memory is faster than using a disk file.
Logging data to a disk file usually means that you can log more data, and the data is not lost if you quit MATLAB or delete the dagroup object that logged the data. However, reading data from a disk file is slower than reading data from memory.
The LoggingMode property of a dagroup object controls where logged data is stored.
You can specify 'memory' (the default value), or 'disk', or 'disk&memory' as the value for LoggingMode.
The following properties control how OPC Toolbox software logs data to disk. You must set the LoggingMode property to 'disk' or 'disk&memory' for these properties to take effect:
7
Reading, Writing, and Logging OPC Data• LogFileName: The LogFileName property is a string that specifies the name of the disk file that is used to store logged data. If the file does not exist, data will be logged to that filename. If the file does exist, the LogToDiskMode property defines how the toolbox behaves.
• LogToDiskMode: The LogToDiskMode property controls how OPC Toolbox software handles disk logging when the file specified by LogFileName already exists.
Each time a logging task is started, if the LoggingMode is set to 'disk' or 'disk&memory', the toolbox checks to see if a file with the name specified by the LogFileName property exists. If the file exists, the toolbox will take the following action, based on the LogToDiskMode property:
• 'append': When LogToDiskMode is set to 'append', logged data will be added to the existing data in the file.
• 'overwrite': When LogToDiskMode is set to 'overwrite', all existing data in the file will be removed without warning, and new data will be logged to the file.
• 'index': When LogToDiskMode is set to 'index', OPC Toolbox software automatically changes the log filename, according to the following algorithm:
The first log filename attempted is specified by the initial value of LogFileName.
If the attempted filename exists, LogFileName is modified by adding a numeric identifier. For example, if LogFileName is initially specified as 'groupRlog.olf', then groupRlog.olf is the first attempted filename, groupRlog01.olf is the second filename, and so on. If LogFileName already contains numeric characters, they are used to determine the next sequence in the modifier. For example, if the LogFileName is initially specified as
'groupRlog010.olf', and groupRlog010.olf exists, the next attempted file is groupRlog011.olf, and so on.
The actual filename used is the first filename that does not exist. In this way, each consecutive logging operation is written to a different file, and no previous data is lost.
Configure Logging Callbacks
You can configure the dagroup object so that MATLAB will automatically execute a function when the logging task starts, when the logging task stops, and each time a specified number of records is acquired during a logging task. The dagroup object has three callback properties that are used during a logging session. Each callback property defines the action to take when a particular logging event occurs:
Log OPC Server Data
7-21
• Start event: A start event is generated when a logging task starts.
• Records acquired event: A records acquired event is generated each time a logging task acquires a set number of records.
• Stop event: A stop event is generated when a logging task stops, either automatically, or by the user calling the stop function.
For an example of using callbacks in a logging task, see “View Recently Logged Data” on page 9-18.