• No results found

How OPC Toolbox Software Logs Data

In document Opc Manual (Page 133-136)

“Configure a Logging Session” on page 7-18

“Execute a Logging Task” on page 7-21

“Get Logged Data into the MATLAB Workspace” on page 7-23

How OPC Toolbox Software Logs Data

The OPC Data Access Specification, which OPC Toolbox software implements, provides access to current values of data on an OPC server. Often, for analysis, troubleshooting, and prototyping purposes, you will want to know how OPC server data has changed over a period of time. For example, you can use time series data to perform control loop optimization or system identification on a portion of your plant. OPC Toolbox software provides a logging mechanism that stores a history of data that changed over a period of time. This section discusses how to configure and execute a logging task using the toolbox.

Note The OPC Toolbox software logging mechanism is not designed to replace a data historian or database application that logs data for an extended period. Rather, the logging mechanism allows you to quickly configure a task to log data on an occasional basis, where modifications to the plant-wide data historian may be unfeasible.

OPC Toolbox software uses the data change event to log data. Each data change event that is logged is called a record. The record contains information about the time the client logged the record, and details about each item in the data change event. Data change events are discussed in detail in “Data Change Events and Subscription” on page 7-11.

The use of a data change event for logging means that you should consider the following points when planning a logging session:

• Logging takes place at the group level — When planning a logging task, configure the group with only the items you need to log. Including more items than you need to will only increase memory and/or disk usage, and using that data may be more difficult due to unnecessary items in the data set.

7

Reading, Writing, and Logging OPC Data

• Inactive items in a group will not be logged — You must ensure that the items you need to log are active when you start a logging session. You control the active state of a daitem object using the Active property of the daitem object.

• Data change events (records) may not include all items — A data change event contains only the items in the group that have changed their value and/or quality state since the last update. Hence, a record is not guaranteed to contain every data item. You need to consider this when planning your logging session.

• OPC logging tasks are not guaranteed to complete — Because data change events only happen when an item in the group changes state on the server, it is possible to start a logging task that will never finish. For example, if the items in a group never change, a data change event will never be generated for that group.

Hence, no records will be logged.

• Logged data is not guaranteed to be regularly sampled — It is possible to force a data change event at any time (see “Force a Data Change Event” on page 7-13).

If you do this during a logging task, the data change events may occur at irregular sample times. Also, a data change event may not contain information for every item in the group. Consequently, logged OPC server data may not occur at regular sample times.

An overview of the logging task, and a representation of how the above points impact the logging session, is provided in the following section.

Overview of a Logging Task

To illustrate a typical logging task, the following example logs to disk and memory six records of data from two items provided by the Matrikon OPC Simulation Server. During the logging task, data is retrieved from memory. When the task stops, the remaining records are retrieved.

Step 1: Create the OPC Toolbox object hierarchy

This example creates a hierarchy of OPC Toolbox objects for two items provided by the Matrikon Simulation Server. To run this example on your system, you must have the Matrikon Simulation Server installed. Alternatively, you can replace the values used in the creation of the objects with values for a server you can access.

da = opcda('localhost','Matrikon.OPC.Simulation.1');

connect(da);

grp = addgroup(da,'CallbackTest');

itm1 = additem(grp,'Triangle Waves.Real8');

Log OPC Server Data

7-17 itm2 = additem(grp,'Saw-Toothed Waves.Boolean');

Step 2: Configure the logging duration

This example sets the UpdateRate value to 1 second, and the RecordsToAcquire property to 6. See “Control the Duration of a Logging Session” on page 7-18 for more information on this step.

grp.UpdateRate = 1;

grp.RecordsToAcquire = 6;

Step 3: Configure the logging destination

In this example, data is logged to disk and memory. The disk filename is set to

LoggingExample.olf. The LogToDiskMode property is set to 'overwrite', so that if the filename exists, the toolbox engine must overwrite the file. See “Control the Logged Data Destination” on page 7-19 for more information on this step.

grp.LoggingMode = 'disk&memory';

grp.LogFileName = 'LoggingExample.olf';

grp.LogToDiskMode = 'overwrite';

Step 4: Start the logging task

Start the dagroup object. The logging task is started, and the group summary updates to reflect the logging status. See “Start a Logging Task” on page 7-21 for more

information on this step.

start(grp) grp

Step 5: Monitor the Logging Progress

After about 3 seconds, retrieve and show the last acquired value. After another second, obtain the first two records during the logging task. Then wait for the logging task to complete. See “Monitor the Progress of a Logging Task” on page 7-21 for more information on this step.

pause(3.5)

sPeek = peekdata(grp, 1);

% Display the local event time, item IDs and values disp(sPeek.LocalEventTime)

disp({sPeek.Items.ItemID;sPeek.Items.Value}) pause(1)

sGet = getdata(grp, 2);

7

Reading, Writing, and Logging OPC Data

wait(grp)

Step 6: Retrieve the data

This example retrieves the balance of the records into a structure array. See “Retrieve Data from Memory” on page 7-23 for more information on this step.

sFinished = getdata(grp,grp.RecordsAvailable);

Step 7: Clean up

When you no longer need them, always remove from memory any toolbox objects and the variables that reference them. Deleting the opcda client object also deletes the group and daitem objects.

disconnect(da) delete(da)

clear da grp itm1 itm2

In document Opc Manual (Page 133-136)