opc with visual studio video
TRANSCRIPT
![Page 1: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/1.jpg)
OPCwithVisualStudio
Hans-PetterHalvorsen,M.Sc.
![Page 2: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/2.jpg)
Software• MatrikonOPCSimulationServer• VisualStudio• MeasurementStudio–Add-onpackagetoVisualStudiocreatedbyNationalInstruments(samevendorasLabVIEW)
![Page 3: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/3.jpg)
MeasurmentStudio• Add-onpackagetoVisualStudiocreatedbyNationalInstruments
• SamevendorasLabVIEW• MakesitpossibletocommunicatewithanOPCDAServerfromVisualStudioCode
• UsestheDataSocket Library(sameasinLabVIEW)
![Page 4: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/4.jpg)
OPC
Hans-PetterHalvorsen,M.Sc.
![Page 5: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/5.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/6.jpg)
OPC
OPCServer OPCClientRead/WriteData
DataStorage
![Page 7: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/7.jpg)
OPCServer
OPCClient
WriteData
DataStorage
OPCClient
ReadData
MeasurementData
Monitoring andAnalysis
![Page 8: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/8.jpg)
OPC-Server
Network
OPC-Client OPC-ClientOPC-Client
Process
ProcessData
DataAcquisitionPLC,PAC,DCS,SCADA
TypicalOPCScenario
Driver
SensorsActuators
![Page 9: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/9.jpg)
OPCSpecifications
OPCDA
OPCHDA
OPCA&E
OPCUA
“Classic”OPC “NextGeneration”OPC
...(Manyothers)
![Page 10: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/11.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/14.jpg)
MatrikonOPCSimulationServer
Hans-PetterHalvorsen,M.Sc.
![Page 15: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/15.jpg)
Matrikon OPCExplorer– ConnecttoServer
1
2
![Page 16: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/16.jpg)
Matrikon OPCExplorer- AddTags
1
2
3
4
5
Double-click
Finished
![Page 17: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/17.jpg)
MatrikonOPCExplorer(OPCClient)
TheMatrikonOPCExplorerisusefulfortesting.YoucanuseitforwritingandreadingOPCTags
![Page 18: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/18.jpg)
MeasurementStudio
Hans-PetterHalvorsen,M.Sc.
![Page 19: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/19.jpg)
MeasurmentStudio• Add-onpackagetoVisualStudiocreatedbyNationalInstruments
• SamevendorasLabVIEW• MakesitpossibletocommunicatewithanOPCDAServerfromVisualStudioCode
• UsestheDataSocketLibrary(sameasinLabVIEW)
![Page 20: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/20.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/21.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/22.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/23.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/24.jpg)
VisualStudio2015+MeasurementStudioYoucanuseanordinaryWinFormApp
Thenyouneedto:1. AddReferences(Assemblies)
Manually2. Change/UpdatetheLicenseFile
(Licenses.licx)
![Page 25: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/25.jpg)
AddingReferencestoyourProjectYouneedtoaddtheseAssemblies(.dllfiles)toyourVisualStudioProject
LocatethefollowingAssembliesonyourharddrive:NationalInstruments.Common.dllNationalInstruments.Net.dll
C:\ProgramFiles…\NationalInstruments\MeasurementStudioVSXXXX\DotNET\Assemblies\Current\...
![Page 26: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/26.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/27.jpg)
OPCReadExample
Hans-PetterHalvorsen,M.Sc.
![Page 28: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/28.jpg)
OPCRead
ClickButtontogetlatestValuefromOPCServer
MatrikonOPCServer/OPCExplorer VisualStudioApp
![Page 29: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/29.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/30.jpg)
![Page 31: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/31.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/32.jpg)
OPCWriteExample
Hans-PetterHalvorsen,M.Sc.
![Page 33: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/33.jpg)
WriteOPCExampleMatrikonOPCServer/OPCExplorer
VisualStudioApp
![Page 34: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/34.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/35.jpg)
![Page 36: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/36.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/37.jpg)
OPCWrite/ReadExample
Hans-PetterHalvorsen,M.Sc.
![Page 38: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/38.jpg)
Write/ReadExample
![Page 39: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/39.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/40.jpg)
![Page 41: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/41.jpg)
AdditionalFeatures
Hans-PetterHalvorsen,M.Sc.
![Page 42: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/42.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/43.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/44.jpg)
TrendingDatawithMeasurementStudio
…{
…
waveformGraph.PlotYAppend(analogDataIn);
}
Youmayusethe“WaveformGraph”ControlincludedwithMeasurementStudio
Youonlyneedonelineofcode,e.g.intheTimerEvent:
NameofyourWaveformGraph Control NameoftheMethodtouseNameofthevariablewithTemperaturedata
![Page 45: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/45.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/46.jpg)
![Page 47: OPC with Visual Studio Video](https://reader033.vdocuments.us/reader033/viewer/2022051521/586b89591a28ab431f8bfc29/html5/thumbnails/47.jpg)
Hans-PetterHalvorsen,M.Sc.
UniversityCollegeofSoutheastNorwaywww.usn.no
E-mail:[email protected]:http://home.hit.no/~hansha/