MathWorks offers two ways to interface with OSIsoft Pi
System.
The MATLAB interface for PI System
enables you to import historical PI data
into MATLAB for data exploration and algorithm development.
The MATLAB Production Server Interface for PI System
enables you to perform periodic analytics
on near-real-time data from PI System.
Use the following timestamps to navigate
quickly to the interface that interests you.
The MATLAB interface for PI System
is provided as a MATLAB toolbox.
This interface has read-only access,
as it is primarily designed to help import data into MATLAB
for further analysis.
Simply run the installer, and you'll find the toolbox
in your list of add-ons.
For additional info, you can access
the Getting Started guide here.
The first step is to create a client object for the device
system.
There are a few ways you can do this.
The first option is to specify the name of the server
where your PI System is located.
You can use localhost if your PI System is installed locally.
This will create a client object with a connection type PiAfSdk.
You can also create your client object
using specific credentials.
The example in this video connects without credentials.
PI System uses tags to help arrange data logically.
One of the first things you might do
is find out what tags are available.
This example does a wild card search
for all tags with the letters SIN, which produces
the following two tags.
You can use the tag names to retrieve the corresponding data
from PI System.
This will produce a MATLAB timetable,
since each data value in PI System contains a timestamp.
You'll also note the status value, which indicates
whether an entry was corrupted.
The data here looks good so far.
MATLAB timetables make it easy to apply useful functions
to your data.
The retime function quickly resamples your timetable.
It can also be used to resolve duplicate or irregular times.
You can also pull in data from another PI System tag,
and then use the synchronize function
to aggregate data from multiple sources
into a single timetable.
Many functions provided by this MATLAB toolbox
are wrappers around the functions already provided
by the PiAfSdk.
Here you might recognize the function
that enables you to specify a time range of data
to pull from PI System.
This example retrieves all the data from the last two days
with a SINUSOIDU tag.
Another example is get interpolated values--
which, again, is ultimately provided by the PiAfSdk.
The last piece of code here provides
a visual interactive experience to explore your data.
All the tags in your PI System are exposed to the left column.
You can add tags into the right column
and use the built-in visualization tools
to explore your data at an aggregate level,
and help narrow down which tags you
want to investigate further.
You can download both interfaces using the link
on the mathworks.com web page for OSIsoft.
Once you have developed MATLAB algorithms for your data,
you can deploy them using the MATLAB Production Server
Interface for PI System.
This enables you to run custom MATLAB
analytics against your PI System data in near real time.
The setup instructions for installing and configuring
the interface will be covered later in this video.
In order to run this interface, you
will need to have a license for PI System and access
to the PiAfSdk dll.
This database contains solar plant data
from two different cities.
Each inverter in the plant is defined by various attributes.
The attributes themselves are common to all the inverters.
This example has been scaled down
to this test database, where the inverters and the plants
are now represented by a different set
of common attributes.
The goal is to pool these two temperature attributes, which
are represented in Celsius, and send them
to MATLAB Production Server to be converted into Fahrenheit.
Those values will be saved in out1 and out2.
Here's the MATLAB function that performs the conversion.
It takes two Celsius temperatures imported
as a MATLAB structure-- or struct--
converts them to Fahrenheit, and outputs the results.
If you have MathWorks Compiler SDK,
you can test this function simply
by opening the example project file provided with the package
you download.
Click on Test Client, then Start,
which has the effect of converting your MATLAB
session to act like an instance of MATLAB Production
Server, which accepts HTTP connections at this URL.
Since this interface is implemented as a .NET
application in the form of a Windows service,
you will need to start the service itself.
Pull up the Windows service application by typing Services
into the Start menu.
All of the PI-related services are located here.
Find the service called PI Client for MATLAB Production
Server, and start it-- either through the context menu,
or by clicking this button in the Services menu.
If you switch back to MATLAB, you'll
see that a request has come in.
Currently, requests are made every 10 seconds
from PI System.
Suppose that this PI System is a live system,
and temp1 is changed to 50.
You can examine the latest call and verify
that temp1 has a value of 50.
Once PI System has refreshed its data,
the new output value is reflected as expected.
To install the interface, simply run this batch file
in the package you receive to install the Windows service.
Know that all the logs created by the interface
are stored in this folder.
You'll need to configure the interface
to bridge MATLAB Production Server and PI System.
The key connections are contained in the Mappings.xml
file.
Amongst other things, it will map the input and output
arguments of the MATLAB function to their counterparts
in PI System.
You will need to specify the URL to MATLAB Production
Server here, the name of the MATLAB archive here,
and the name of the MATLAB function here.
The input arguments are listed in the order they are received
by the MATLAB function.
You need to replace these file paths with a full path
to each corresponding PI attribute.
You can obtain this easily by navigating
to your attribute, Right-Clicking,
and selecting Copy Path.
Then do the same for your output arguments.
If you have multiple MATLAB functions
you would like to use, make sure to specify
those as well in this XML file.
Once you're done, save the file, start the Windows service,
and you are good to go.
For more information on using either interface,
check out the Getting Started guide,
or contact us at the following email address.