matlab opc toolbox video...matlab opc toolbox • opc toolbox provides access to live and historical...

31
MATLAB OPC Toolbox Hans-Petter Halvorsen, M.Sc.

Upload: others

Post on 30-Jan-2021

34 views

Category:

Documents


0 download

TRANSCRIPT

  • MATLABOPCToolbox

    Hans-PetterHalvorsen,M.Sc.

  • SoftwareYouneedthefollowingSoftware:• OPCServer(e.g.,MatrikonOPCSimulationServer,FreeDownload)

    • MATLAB• MATLABOPCToolbox

    www.mathworks.com/products/opc

  • MATLAB

    Hans-PetterHalvorsen,M.Sc.

  • WhatisMATLAB?• MATLABisatoolfortechnicalcomputing,computationandvisualizationinanintegratedenvironment.

    • MATLABisanabbreviationforMATrix LABoratory• ItiswellsuitedforMatrixmanipulationandproblemsolvingrelatedtoLinearAlgebra,Modelling,SimulationandControlApplications

    • PopularinUniversities, TeachingandResearch

  • TheMATLABEnvironment(IDE)

    CommandWindow

    ScriptEditor

    WorkspaceCurrentFolder

    PlotWindow

  • MATLABSyntax- Exampleclearclcclose all

    x=[0, 1, 2, 3, 4 ,5];y=[15, 10, 9, 6, 2 ,0];

    for n=1:6 % n = model order

    p = polyfit(x,y,n)

    ymodel = polyval(p,x);

    subplot(3,2,n)plot(x,y,'o',x,ymodel)title(sprintf('Model order %d', n));

    end

    ForLoop

    Built-inFunctions

    DefiningVectors

    50+Toolboxes

  • Installation

    • MATLABandSimulinkStudentSuite(NOK699)Included:MATLAB+Simulink+StatisticsToolbox+OptimizationToolbox+SymbolicMathToolbox+ControlSystemToolbox+SignalProcessingToolbox+ImageProcessingToolbox,...

    • MATLABStudent(NOK350+)IncludesMATLABonly.Add-onproductsmustbepurchasedseparately(NOK70/Toolboxifyoubuythematthesametime,elseNOK200/Toolbox).Selectbetween55differentToolboxes

    http://www.mathworks.com/academia/student_version

    2differentoptions:

  • OPC

    Hans-PetterHalvorsen,M.Sc.

  • WhatisOPC?• Astandardthatdefinesthecommunicationofdatabetweendevicesfromdifferentmanufactures

    • RequiresanOPCserverthatcommunicateswiththeOPCclients

    • OPCallows“plug-and-play”,givesbenefitsasreducesinstallationtimeandtheopportunitytochooseproductsfromdifferentmanufactures

    • Differentstandards:“Real-time”data(OPCDA),Historicaldata(OPCHDA),Alarm&Eventdata(OPCAE),etc.

  • OPC

    OPCServer OPCClient

  • OPC-Server

    Network

    OPC-Client OPC-ClientOPC-Client

    Process

    ProcessData

    DataAcquisitionPLC,PAC,DCS,SCADA

    TypicalOPCScenario

    Driver

    SensorsActuators

  • OPCSpecifications

    OPCDA

    OPCHDA

    OPCA&E

    OPCUA

    “Classic”OPC “NextGeneration”OPC

    ...(Manyothers)

  • OPCSpecifications• OPCDA(DataAccess)ThemostcommonOPCspecificationisOPCDA,whichisusedtoreadandwrite“real-time”data.WhenvendorsrefertoOPCgenerically,theytypicallymeanOPCDA.• OPCHDA(HistoricalDataAccess)• OPCA&E(Alarms&Events)• ...(manyothers)TheseOPCspecificationarebasedontheOLE,COM,andDCOMtechnologiesdevelopedbyMicrosoftfortheMicrosoftWindowsoperatingsystemfamily.ThismakesitcomplicatedtomakeitworkinamodernNetwork!TypicallyyouneedaTunneller SoftwareinordertosharetheOPCdatainanetwork(betweenOPCServersandClients)

    • OPCUA(UnifiedArchitecture)OPCUAeliminatingtheneedtouseaMicrosoftWindowsbasedplatformofearlierOPCversions.OPCUAcombinesthefunctionalityoftheexistingOPCinterfaceswithnewtechnologiessuchasXMLandWebServices(HTTP,SOAP)

  • MATLABOPCToolbox

    Hans-PetterHalvorsen,M.Sc.

  • MATLABOPCToolbox• OPCToolboxprovidesaccesstoliveandhistoricalOPCdatadirectlyfromMATLABandSimulink

    • Youcanread,write,andlogOPCdatafromdevices,suchasdistributedcontrolsystems(DCS),supervisorycontrolanddataacquisitionsystems(SCADA),andprogrammablelogiccontrollers(PLS)

  • MATLABOPCToolbox

    TheMATLABOPCToolboxsupportsthefollowingOPCprotocols:• OPCDA(DataAccess)• OPCHDA(HistoricalDataAccess)• OPCUA(UnifiedArchitecture)

    ThisVideo

    ALaterVideo

  • AcquireDatafromanOPCDataAccessServer(withExamples):http://se.mathworks.com/help/opc/examples/acquire-data-from-an-opc-data-access-server.html?prodcode=OT&language=en

    RunthiscommandintheMATLABCommandwindow

  • MATLABOPCToolboxFormoreinformationabouttheMATLABOPCToolbox:

    AcquireDatafromanOPCDataAccessServer(withExamples):http://se.mathworks.com/help/opc/examples/acquire-data-from-an-opc-data-access-server.html?prodcode=OT&language=en

    www.mathworks.com/products/opc

  • MatrikonOPCSimulationServer

    Hans-PetterHalvorsen,M.Sc.

  • Matrikon OPCExplorer– ConnecttoServer

    1

    2

  • Matrikon OPCExplorer- AddTags

    1

    2

    3

    4

    5

    Double-click

    Finished

  • MatrikonOPCExplorer(OPCClient)

    TheMatrikonOPCExplorerisuseful fortesting.YoucanuseitforwritingandreadingOPCTags

  • MATLABOPCToolbox

    Hans-PetterHalvorsen,M.Sc.

    ReadDatafromOPCDAServer

    Examples

  • MATLAB

    OPCServer

    OPCClient

    MATLABisaTooltypicallyusedforDataAnalysis,soyoutypicallyReadDatafromtheOPCServer.(Butitispossible toconnectDAQdevicesandReadMeasurementDataintoMATLABandthenWritethoseDataValuestoanOPCServer)

    WithMATLABOPCToolboxyoucancreateOPCClientsthatWriteorReadtoanOPCServer

  • clear, clc% Connect to OPC Serverda = opcda('localhost', 'Matrikon.OPC.Simulation.1');connect(da);

    % Create Groupgrp = addgroup(da, 'DemoGroup');

    %Add TagsitmIDs = {'Random.Real8'};itm = additem(grp, itmIDs);

    % Retrieve Datadata = read(grp);opcdata = data.Value

    %Clean Updisconnect(da)delete(da)

    MATLABOPCRead

    Example1

    ThissimpleExamplereadsonlyonevaluefromtheServer

  • MATLABOPCRead

    Example2

    clear, clc

    % Connect to OPC Serverda = opcda('localhost', 'Matrikon.OPC.Simulation.1');connect(da);

    % Create Groupgrp = addgroup(da, 'DemoGroup');

    %Add TagsitmIDs = {'Random.Real8'};itm = additem(grp, itmIDs);

    % Retrieve DataN=10;for i=1:N

    data = read(grp);opcdata(i) = data.Value;pause(2)

    end

    %Clean Updisconnect(da)delete(da)

    plot(opcdata)

    ThissimpleExamplereadsvaluesfromtheServer.

    ThisExamplesreadsNvaluesusingaForLoop

  • MATLABOPCRead

    Example3

    clear, clc% Connect to OPC Serverda = opcda('localhost', 'Matrikon.OPC.Simulation.1');connect(da);% Create Groupgrp = addgroup(da, 'DemoGroup');%Add TagsitmIDs = {'Random.Real8'};itm = additem(grp, itmIDs)% Set PropertieslogDuration = 60;logRate = 0.2;numRecords = ceil(logDuration./logRate)grp.UpdateRate = logRate;grp.RecordsToAcquire = numRecords;% Acquire Datastart(grp), wait(grp)% Retrieve Data[logIDs, logVal, logQual, logTime, logEvtTime] = getdata(grp, 'double');% Plot Dataplot(logTime, logVal);axis tightdatetick('x', 'keeplimits')legend(logIDs)%Clean Updisconnect(da)delete(da)

    ThissimpleExampleusessomeofthemoreadvancedfeaturesintheMATLABOPCToolbox.NoFor/WhileLoopneeded!

  • Hans-PetterHalvorsen,M.Sc.

    UniversityCollegeofSoutheastNorwaywww.usn.no

    E-mail:[email protected]:http://home.hit.no/~hansha/