Transcript
Page 1: OPC with Visual Studio Video

OPCwithVisualStudio

Hans-PetterHalvorsen,M.Sc.

Page 2: OPC with Visual Studio Video

Software• MatrikonOPCSimulationServer• VisualStudio• MeasurementStudio–Add-onpackagetoVisualStudiocreatedbyNationalInstruments(samevendorasLabVIEW)

Page 3: OPC with Visual Studio Video

MeasurmentStudio• Add-onpackagetoVisualStudiocreatedbyNationalInstruments

• SamevendorasLabVIEW• MakesitpossibletocommunicatewithanOPCDAServerfromVisualStudioCode

• UsestheDataSocket Library(sameasinLabVIEW)

Page 4: OPC with Visual Studio Video

OPC

Hans-PetterHalvorsen,M.Sc.

Page 5: OPC with Visual Studio Video

WhatisOPC?• Astandardthatdefinesthecommunicationofdatabetweendevicesfromdifferentmanufactures

• RequiresanOPCserverthatcommunicateswiththeOPCclients

• OPCallows“plug-and-play”,givesbenefitsasreducesinstallationtimeandtheopportunitytochooseproductsfromdifferentmanufactures

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

Page 6: OPC with Visual Studio Video

OPC

OPCServer OPCClientRead/WriteData

DataStorage

Page 7: OPC with Visual Studio Video

OPCServer

OPCClient

WriteData

DataStorage

OPCClient

ReadData

MeasurementData

Monitoring andAnalysis

Page 8: OPC with Visual Studio Video

OPC-Server

Network

OPC-Client OPC-ClientOPC-Client

Process

ProcessData

DataAcquisitionPLC,PAC,DCS,SCADA

TypicalOPCScenario

Driver

SensorsActuators

Page 9: OPC with Visual Studio Video

OPCSpecifications

OPCDA

OPCHDA

OPCA&E

OPCUA

“Classic”OPC “NextGeneration”OPC

...(Manyothers)

Page 10: OPC with Visual Studio Video

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)

Page 11: OPC with Visual Studio Video

NextGenerationOPC

OPCClassic OPCUA

OPCDAServer

OPCHDAServer

OPCA&EServer

COM/DCOM XML,HTTP,SOAP

Cross-platformWindowsonly Allspecificationscollectedinone(DA,HDA,A&E)

NextGenerationOPC

OPCClient(DCOM)

OPCDAOPCHDA

OPCA&E

OPCUAServer OPCUAClient

Protocols:“UABinary”or“UAXML”

Windows,Linux,Mac,Embedded,VxWorks

Simpler!!

(everything builtintoone)

Page 12: OPC with Visual Studio Video

NextGenerationOPC

OPCClassicServer OPCClassicClient

OPCUAServer OPCUAClientNetwork/Internet

ToopenDCOMthrough firewallsdemandedalargehole inthefirewall!Impossible torouteoverInternet!

Nohole infirewall(UAXML)orjustasimpleneedlestick(UABinary)isnecessaryEasytorouteoverInternet!

Network

Page 13: OPC with Visual Studio Video

ClassicOPCvs.OPCUAClassicOPC(DCOM) OPCUA

OPCServer

OPCClient

OPCClient

OPCClient

Windows

Windows

Windows

WindowsOPCUAServer

OPCUAClient

OPCUAClient

ClassicOPCrequiresaMicrosoftWindowsoperatingsystemtoimplementCOM/DCOMserverfunctionality.ByutilizingSOAandWebServices,OPCUAisaplatform-independentsystemthateliminatesthepreviousdependencyonaWindowsoperatingsystem.ByutilizingSOAP/XMLoverHTTP,OPCUAcandeployonavarietyofembeddedsystemsregardlessofwhetherthesystemisageneralpurposeoperatingsystem, suchasWindows,oradeterministicreal-timeoperatingsystem. http://www.ni.com/white-paper/13843/en/

OPCUAClient

Theserver(orclients)canbeanembeddedsystem,LINUX,Windows, etc.

Page 14: OPC with Visual Studio Video

MatrikonOPCSimulationServer

Hans-PetterHalvorsen,M.Sc.

Page 15: OPC with Visual Studio Video

Matrikon OPCExplorer– ConnecttoServer

1

2

Page 16: OPC with Visual Studio Video

Matrikon OPCExplorer- AddTags

1

2

3

4

5

Double-click

Finished

Page 17: OPC with Visual Studio Video

MatrikonOPCExplorer(OPCClient)

TheMatrikonOPCExplorerisusefulfortesting.YoucanuseitforwritingandreadingOPCTags

Page 18: OPC with Visual Studio Video

MeasurementStudio

Hans-PetterHalvorsen,M.Sc.

Page 19: OPC with Visual Studio Video

MeasurmentStudio• Add-onpackagetoVisualStudiocreatedbyNationalInstruments

• SamevendorasLabVIEW• MakesitpossibletocommunicatewithanOPCDAServerfromVisualStudioCode

• UsestheDataSocketLibrary(sameasinLabVIEW)

Page 20: OPC with Visual Studio Video

MeasurementStudio• MeasurementStudioisanadd-ontoVisualStudio.• MeasurementStudioisusedfordevelopmentofmeasurement,controlandmonitoringapplicationsusing.NETandVisualStudio.

• MeasurementStudiohasalibrary(DataSocket library)thatmakesitpossibletocommunicatewithOPCDAserversthatwewilluseisthislabwork

• DownloadSoftwarehere:http://www.ni.com/academic/download

20

Software

Page 21: OPC with Visual Studio Video

VisualStudioEditionsq IhaveVisualStudio2013Ø YoucanInstallanduseMeasurementsStudio2015withoutproblems

q IhaveVisualStudio2015Ø MeasurementStudio2015isdesignedtoworkwithVisualStudio2013(andoldereditions).

Therefore,MeasurementStudio2015doesnotinstallshippingexamplesanddoesnotintegratewithVisualStudio2015

Ø Thismeans,ifyouinstallMeasurementStudio2015withVisualStudio2015,theMeasurementStudio.NETcontrolsarenotintheToolbox,andyoudonothaveaMeasurementStudiomenuitemintheVisualStudio2015toolbar.

Ø Followtheseguidelinestodothismanually:http://home.hit.no/~hansha/documents/control/opc/resources/Using%20Measurement%20Studio%202015.pdf

Page 22: OPC with Visual Studio Video

MeasurementStudio2015MeasurementStudio2015doesnothaveintegrationfeaturesforVisualStudio2015.IfyouinstallMeasurementStudio2015withVisualStudio2015,theMeasurementStudio.NETcontrolsarenotintheToolbox,youdonothaveaMeasurementStudiomenuitemintheVisualStudio2015 toolbar,and.licxwillnotbeautomaticallygenerated.WehaveplanstomakechangestoMeasurementStudiothatwillhelpusbetterkeepupwithnewversions.Unfortunately,thesechangesareaquiteabitmorecostlythanit wouldseem,particularlytheVisualStudioHelpintegration,sothesechangesmaynotcomesoon.

ThissituationisthesameaspreviousMeasurementStudiosoftwareasinthefollowingarticle'UsingMeasurementStudio2013withMicrosoftVisualStudio2013':http://digital.ni.com/public.nsf/allkb/C51E3B38578FAD2786257C070069F386

VisualStudio2015isnot supportedofficiallyinMeasurementStudio2015;however,asintheabovearticle,youcanaddtheMeasurementStudio.NETcontrolstotheToolboxmanuallyandcancreate.licx filesmanually.IhaveattachedaHelpDocumentonthistopicsoyoucanrefertothe AddingMeasurementStudio2015UserInterfaceControls totheToolbox sectionformoreinformationonHowtoAddcontrols.Thissectionalsodescribeshowthesecontrolsarelicensed.ThefollowingsectionsdiscussadditionaltopicstoconsiderwhenusingMeasurementStudio2015withVisualStudio2015.

RebeccaCostinNationalInstrumentsApplicationsEngineeringwww.ni.com/support

Page 23: OPC with Visual Studio Video

VisualStudio2013+MeasurementStudioSelect“NewProject”inVisualStudio:

MakesuretoselecttheDataSocketLibrary

Selectthe“NIWindowsApplication”Template

12

3

4

5

76

8

MeasurementStudio isan“Add-in”forVisualStudiocreatedbyNationalInstruments.

Note!Youdontneedtousethe“MeasurmentStudioTemplates”– YoucanuseanordinaryWinFormAppalso!!

Page 24: OPC with Visual Studio Video

VisualStudio2015+MeasurementStudioYoucanuseanordinaryWinFormApp

Thenyouneedto:1. AddReferences(Assemblies)

Manually2. Change/UpdatetheLicenseFile

(Licenses.licx)

Page 25: OPC with Visual Studio Video

AddingReferencestoyourProjectYouneedtoaddtheseAssemblies(.dllfiles)toyourVisualStudioProject

LocatethefollowingAssembliesonyourharddrive:NationalInstruments.Common.dllNationalInstruments.Net.dll

C:\ProgramFiles…\NationalInstruments\MeasurementStudioVSXXXX\DotNET\Assemblies\Current\...

Page 26: OPC with Visual Studio Video

LicenseFile

NationalInstruments.Net.DataSocket,NationalInstruments.Net,Version=13.0.45.242,Culture=neutral,PublicKeyToken=4febd62461bf11a4

Youmayneed toupdatetheLicenseFilewithcorrectVersionNumberandPublicKeyToken accordingtotheinstalledAssembliesyouhaveonyourharddrive

Page 27: OPC with Visual Studio Video

OPCReadExample

Hans-PetterHalvorsen,M.Sc.

Page 28: OPC with Visual Studio Video

OPCRead

ClickButtontogetlatestValuefromOPCServer

MatrikonOPCServer/OPCExplorer VisualStudioApp

Page 29: OPC with Visual Studio Video

ReadfromOPCServerusingVisualStudiousingNationalInstruments;usingNationalInstruments.Net;…stringopcUrl;doubleopcValue;

opcUrl ="opc://localhost/Matrikon.OPC.Simulation/Bucket Brigade.Real4";

DataSocketdataSocket =newDataSocket();

if(dataSocket.IsConnected)dataSocket.Disconnect();

dataSocket.Connect(opcUrl, AccessMode.Read);dataSocket.Update();opcValue =Convert.ToDouble(dataSocket.Data.Value);

Note!ThisCodeSnippet readsonly onevalueonce,you canusee.g.aTimer inordertoreadvalues atspecific intervals.

Page 30: OPC with Visual Studio Video
Page 31: OPC with Visual Studio Video

usingNationalInstruments;usingNationalInstruments.Net;usingSystem;usingSystem.Windows.Forms;

namespaceOPC_Read{public partialclassForm1:Form{DataSocketdataSocket=newDataSocket();

public Form1(){InitializeComponent();

stringopcUrl;opcUrl ="opc://localhost/MATRIKON.OPC.Simulation/Bucket Brigade.Real4";

if(dataSocket.IsConnected)dataSocket.Disconnect();

dataSocket.Connect(opcUrl, AccessMode.Read);}

privatevoidbtnReadOpc_Click(object sender, EventArgse){dataSocket.Update();

txtReadOpcValue.Text =dataSocket.Data.Value.ToString();}

}}

Page 32: OPC with Visual Studio Video

OPCWriteExample

Hans-PetterHalvorsen,M.Sc.

Page 33: OPC with Visual Studio Video

WriteOPCExampleMatrikonOPCServer/OPCExplorer

VisualStudioApp

Page 34: OPC with Visual Studio Video

usingNationalInstruments;usingNationalInstruments.Net;…stringopcUrl;doubleopcValue;

opcUrl ="opc://localhost/Matrikon.OPC.Simulation/Bucket Brigade.Real4";

DataSocketdataSocket =newDataSocket();

if(dataSocket.IsConnected)dataSocket.Disconnect();

dataSocket.Connect(opcUrl, AccessMode.Write);

opcValue=Convert.ToDouble(txtWriteOpcValue.Text);dataSocket.Data.Value=opcValue;dataSocket.Update();

WritefromOPCServerusingVisualStudio

Page 35: OPC with Visual Studio Video
Page 36: OPC with Visual Studio Video

usingNationalInstruments;usingNationalInstruments.Net;usingSystem;usingSystem.Windows.Forms;

namespaceOPC_Write{publicpartialclassForm1:Form{DataSocketdataSocket=newDataSocket();

publicForm1(){InitializeComponent();

stringopcUrl;opcUrl="opc://localhost/MATRIKON.OPC.Simulation/BucketBrigade.Real4";

if(dataSocket.IsConnected)dataSocket.Disconnect();

dataSocket.Connect(opcUrl,AccessMode.Write);}

privatevoidbtnWriteOpc_Click(objectsender,EventArgse){doubleopcValue=0;

opcValue=Convert.ToDouble(txtWriteOpcValue.Text);

dataSocket.Data.Value =opcValue;

dataSocket.Update();}

}}

Page 37: OPC with Visual Studio Video

OPCWrite/ReadExample

Hans-PetterHalvorsen,M.Sc.

Page 38: OPC with Visual Studio Video

Write/ReadExample

Page 39: OPC with Visual Studio Video

usingSystem;usingSystem.Windows.Forms;usingNationalInstruments;usingNationalInstruments.Net;

namespaceOPCExample{publicpartialclassForm1:Form{

DataSocketdataSocketRead=newDataSocket();DataSocketdataSocketWrite=newDataSocket();

publicForm1(){InitializeComponent();

stringopcUrl;opcUrl="opc://localhost/MATRIKON.OPC.Simulation/BucketBrigade.Real4";

if(dataSocketRead.IsConnected)dataSocketRead.Disconnect();

dataSocketRead.Connect(opcUrl,AccessMode.Read);

if(dataSocketWrite.IsConnected)dataSocketWrite.Disconnect();

dataSocketWrite.Connect(opcUrl,AccessMode.Write);

}

privatevoidbtnReadOpc_Click(objectsender,EventArgse)…

privatevoidbtnWriteOpc_Click(objectsender,EventArgse)…

}}

privatevoidbtnReadOpc_Click(objectsender,EventArgse){

dataSocketRead.Update();

txtReadOpcValue.Text=dataSocketRead.Data.Value.ToString();

}

privatevoidbtnWriteOpc_Click(objectsender,EventArgse){

doubleopcValue=0;

opcValue=Convert.ToDouble(txtWriteOpcValue.Text);

dataSocketWrite.Data.Value=opcValue;

dataSocketWrite.Update();}

Page 40: OPC with Visual Studio Video
Page 41: OPC with Visual Studio Video

AdditionalFeatures

Hans-PetterHalvorsen,M.Sc.

Page 42: OPC with Visual Studio Video

AdditionalFeatures• UsingaTimerinordertoread/write Datafrom/tothe OPCServeratspecific Intervals

• Trending/PlottingData– Usingthe ”WaveformGraph”Control includedwithMeasurment Studio

• UsingOOP,i.e.,CreateandUseClassesinyourCode

Page 43: OPC with Visual Studio Video

Timer

publicForm1(){InitializeComponent();

timer1.Start();}

privatevoidtimer1_Tick(object sender, EventArgs e){…//ReadfromOPC…//Scaling…//PlotData

}

TimerEvent:

Initialization:

Properties:

StructureyourCodeproperly!!DefineClassesandMethodswhichyoucanusehere

InVisualStudio youmaywanttouseaTimerinsteadofaWhileLoopinordertoreadvaluesatspecificintervals.

YoumayspecifytheTimerIntervalinthePropertiesWindow

Selectthe“Timer”componentintheToolbox

Double-clickontheTimerobjectinordertocreatetheEvent

2

3

4

1

Page 44: OPC with Visual Studio Video

TrendingDatawithMeasurementStudio

…{

waveformGraph.PlotYAppend(analogDataIn);

}

Youmayusethe“WaveformGraph”ControlincludedwithMeasurementStudio

Youonlyneedonelineofcode,e.g.intheTimerEvent:

NameofyourWaveformGraph Control NameoftheMethodtouseNameofthevariablewithTemperaturedata

Page 45: OPC with Visual Studio Video

OOP:Classes,FieldsandMethodsclassCar //Class{

publicstringcolor;//Field

//MethodpublicvoidShowCarColor(){

MessageBox.Show("MyCaris:"+color);}

}CarmyCar =newCar();//WecreateanInstanceoftheClass

myCar.color ="blue"; //WesetavalueforthecolorField

myCar.ShowCarColor(); //WecalltheMethod

1

2

3

Example:

OOP:ObjectOrientedProgramming

YoushoulduseOOPtechniques inyourapplication!Createyourownclasses,fieldsandMethods

MakesuretouseOOP(ObjectOrientedProgramming) inyour solutions

Page 46: OPC with Visual Studio Video
Page 47: OPC with Visual Studio Video

Hans-PetterHalvorsen,M.Sc.

UniversityCollegeofSoutheastNorwaywww.usn.no

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


Top Related