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.
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:
You also need a basic knowledge of SystemModeler. It is recommended that you check out the learning resources at the Wolfram web page if you need to brush up on your SystemModeler 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 Common OPC Issues at the end of this tutorial.
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.
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 SystemModeler, and drag each component onto the diagram view. Connect the components as shown in Fig. 1.
Fig. 1. Diagram view of OPCClassic.Examples.MultipleServers.
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.
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.
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.
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.
Fig. 5. The General view of the readReal component, with all parameters specified.
For the remaining components, choose the following parameters:
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.
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.
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 SystemModeler 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).
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.
Fig. 8. The sampled data read from opcServer.
Plot the filtered signal and the sampled signal in the same plot.
Fig. 9. The filtered signal filter.y and the sampled signal writeReal.writeSignal.
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.
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.
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.
Fig. 10. A warning is issued when a sampling rate is faster than the update rate of the server.
If you are having other problems with your OPCClassic models, going through the following checklist might help.