A step-by-step guide to running your first model with OPCClassic


This getting started guide will provide you with the basic knowledge needed to use OPCClassic. If you are new to OPC, it is recommended that you visit the OPC Foundation web page to get more acquainted with this protocol and common terms related to it.

OPC Classic for Data Access

OPCClassic is based on the OPC Classic specification, which means that it is based on Microsoft Windows technology using the COM/DCOM (Distributed Component Object Model) for the exchange of data between software components. This means that OPCClassic is available for Windows only.

OPCClassic supports OPC for Data Access (DA), which is a specification for accessing data in real time. No historical data can be queried with OPC DA.


To be able to perform the steps in this tutorial, you need the following:


  • Wolfram System Modeler
  • The OPC Classic Library
  • The MatrikonOPC Simulation Server
  • OPCEnum (typically installed along with the OPC server)


  • A Windows distribution supported by System Modeler (see platform support here)

You also need a basic knowledge of System Modeler. It is recommended that you check out the learning resources at the Wolfram web page if you need to brush up on your System Modeler skills.

Connecting to an OPC Server

To be able to use OPCClassic, you need to establish a connection to an OPC server running on a local or remote host. If you need to connect to a remote machine, it is recommended to create users and/or groups that are exclusively used for this purpose. That way, you ensure that the OPC connection is secure. You also need to properly configure COM/DCOM on your user account to be able to connect an OPC client to an OPC server. For more information on this, see the section on troubleshooting at the end of this tutorial.

Building a Model with Multiple Servers

As a first exercise, you will reproduce the example model OPCClassic.Examples.MultipleServers that is shipped with OPCClassic. It demonstrates conceptually how to connect to two different OPC servers.

The first thing you need to do is download and install the MatrikonOPC Simulation Server from the MatrikonOPC web page. It is a free OPC test server used for testing and troubleshooting OPC applications in a way that does not risk losing any "real" production data. Make sure you choose an installation that includes OPCEnum. A minimal setup might not do so.

Building the Model

After you have successfully installed the MatrikonOPC Simulation Server, you can start to build your model. To do so, you need to locate the following components:

Create a new model in System Modeler, and drag each component onto the diagram view. Connect the components as shown in Fig. 1.

This is a getting started guide for OPCClassic

Fig. 1. Diagram view of OPCClassic.Examples.MultipleServers.

Parameterizing the Model

Next, you need to specify certain component parameters.

Start with the component named opcServer, shown in Fig. 2. Select the component, and click the General tab at the bottom of the main window.

This is a getting started guide for the OPCClassic

Fig. 2. The opcServer component highlighted.

In the Parameters view, you will find the parameters hostName, serverName, and requestedRefreshRate. Of these three parameters, requestedRefreshRate and hostName have valid default values that can be left as is, if suitable. serverName, however, needs to be specified for each instance of the server object.

Since the MatrikonOPC Simulation Server has been installed on your user account on your local computer, "localhost" can be kept as hostName, whereas serverName should be "Matrikon.OPC.Simulation.1", which is the version-specific program ID of the MatrikonOPC Server. Note that serverName has to correctly identify an OPC server on the host machine named hostName.

This is a getting started guide for OPCClassic

Fig. 3. The General view of the opcServer component, with all parameters specified.

Repeat the procedure for the second OPC server component (opcServer1 in Fig. 1).

Move on to component readReal. Again, select the component and click the General tab.

This is a getting started guide for the OPCClassic

Fig. 4. The readReal component highlighted.

An interesting parameter here is itemName. It identifies the item on the server that you want to read data from (or write data to, if this has been a block for writing data). The item you specify has to exist on the server, and it has to be available for the kind of operation you want to perform, as some items are available for either reading or writing but not both.

In the itemName field, enter "Saw-toothed Waves.Real8". Next, choose a sampling period of 0.2 seconds.

This is a getting started guide for OPCClassic

Fig. 5. The General view of the readReal component, with all parameters specified.

For the remaining components, choose the following parameters:


  • samplePeriod: 0.1 s
  • startTime: 0.1 s
  • itemName: "Saw-toothed Waves.Real4"


  • analogFilter: Modelica.Blocks.Types.AnalogFilter.Butterworth
  • filterType: Modelica.Blocks.Types.FilterType.LowPass
  • order: 3
  • f_cut: 0.2 Hz
  • f_min: 1.6 Hz
Understanding the Model

What does this model do exactly?

First of all, it connects to two OPC servers. As you may have noticed, they are parameterized exactly the same, which actually means that you connect to the same server twice, contrary to what the title of the example suggests. This is due to a limited supply of available, free OPC servers for testing.

If you would like to connect to two different servers, you would either have to have two different servers installed on your computer, or have access to another server on a remote host. In the former case, "localHost" would be kept as hostName, but serverName would have to be changed from "Matrikon.OPC.Simulation.1" to the name of the new server. In the latter case, both hostName (name of host or IP address) and serverName would need to be updated.

The first server, opcServer, is connected to a read block, readReal, that reads data from the server every 0.2 seconds (as specified by parameter samplePeriod). The sampled signal is then run through a Butterworth lowpass filter with a cut-off frequency of 2.0 Hz. The filtered signal is sampled by writeReal and finally written to opcServer1, a second instance of the OPC server.

The model exemplifies a possible use of multiple OPC servers in one model, where one server is used for reading data and the other for writing data.

Simulating the Model

You are now getting ready to simulate your newly built model, which brings up the issue of which experiment settings to use for the simulation. For the majority of all practical applications of OPCClassic, "Fixed step explicit Euler", with a step size of your choice, should be used as the solver method. For this scenario, use a step size of 0.01 s. Simulate for 60 s.

This is a gettings started guide for the OPCClassic

 Fig. 6. The experiment settings specified for the MultipleServers model.

The first time you simulate the model, it is probably too fast for you to actually see what is happening in the simulation. The reason is that System Modeler simulates the model as fast as possible by default. In order to study the simulation in real time, check the "Synchronize with real time" checkbox in Simulation Center (see Fig. 7).

This is a getting started guide for the OPCClassic

 Fig. 7. Check the "Synchronize with real time" option in the Settings tab in Simulation Center.

 If you are building many models with OPCClassic, consider setting the "Synchronize with real time" option as a default simulation setting. This is done by going to Tools ▶ Options and choosing Default Experiment under the Simulation Center header. There, check the "Synchronize with real time" checkbox.

To see the data sampled from the first server, opcServer, plot readReal.y over time. The signal should be similar to that in Fig. 8 below. It will probably not be identical to Fig. 8, since different simulations read data from the server item at different times.

This is a getting started guide for OPCClassic

Fig. 8. The sampled data read from opcServer.

Plot the filtered signal and the sampled signal in the same plot.

This is a getting started guide for OPCClassic

Fig. 9. The filtered signal filter.y and the sampled signal writeReal.writeSignal.


Listing OPC DA Servers
To aid with troubleshooting OPC DA connections OPCClassic comes with a utility program called opcdalist that can list all OPC DA servers on a host or all OPC item names on a specific OPC DA server.
  • HOSTNAME: windows computer name or an IP address, e.g. localhost.
  • SERVERNAME: optional servername, when a server name is specified it will list all item names on that server.
  • DCOM Security

    COM/DCOM needs to be configured to allow an OPC client to connect to an OPC server. If configured incorrectly, DCOM security can cause problems when you are trying to connect to an OPC server. There are several online guides on how to perform the configuration, for example, at the MatrikonOPC support center.

    Connecting to a Remote Host

    When connecting to an OPC server on a remote host, you may be required to create a separate user account on your computer to be able to set up privileges for the OPC connection. More information about users and groups of users can be found at the Matrikon website or in this guide provided by Kepware.

    Requested and Revised Refresh Rates

    When building the MultipleServers model, the parameter requestedRefreshRate was briefly mentioned. This is where you enter the rate at which you would like the OPC server to update. The server makes an attempt to keep that update rate, but if it cannot, it will use a somewhat slower rate. The actual refresh rate is returned as variable revisedRefreshRate in the OPCServer component. The scenario to be avoided is when you are using a sampling period that is faster than the revised refresh rate. When this happens, a warning will be issued in the simulation log (see Fig. 10). To avoid getting this warning, try to increase the affected sampling period.

    This is a getting started guide for the OPCClassic

    Fig. 10. A warning is issued when a sampling rate is faster than the update rate of the server.

    Troubleshooting Checklist

    If you are having other problems with your OPCClassic models, going through the following checklist might help.

    • Do your server components have specified host and server names?
    • Do your block components have specified sampling periods and item names?
    • Do all item names, server names, and host names have quotation marks?
    • Are the blocks trying to access items of the correct type? Blocks that read or write data of a certain type are only compatible with OPC items of that same type.
    • Are the items you are trying to access available for the type of operation you want to do? Some items are available for reading or writing only, not both.
    • Is the OPC server you are using really active and running on the host computer?
    • Do you have OPCEnum installed on your OPC client?

    If you are still experiencing problems, visit http://community.wolfram.com and ask a question, or contact support@wolfram.com.


    Wolfram Language