using opc in labview - example

31
Using OPC in LabVIEW 1 HansPe5er Halvorsen, Telemark University College, 2013.02.19 Example: Logging Temperature Data using OPC

Upload: phamdien

Post on 06-Jan-2017

262 views

Category:

Documents


0 download

TRANSCRIPT

Using  OPC  in  LabVIEW  

1  Hans-­‐Pe5er  Halvorsen,  Telemark  University  College,  2013.02.19  

Example:  Logging  Temperature  Data  using  OPC  

Equipment  •  Hardware:  

– NI  USB-­‐TC01  Thermocouple  Measurement  Device  (or  NI  USB-­‐6008  DAQ  Device)  

•  SoNware:  – LabVIEW  2012  – DAQmx  Driver  – MatrikonOPC  SimulaMon  Server  

2  

3  

What  is  OPC?  

What  is  OPC?  

4  

•  OPC  -­‐  “Open  Process  Control”  •  A  standard  that  defines  the  communicaMon  of  data  between  devices  from  different  manufactures  

•  Require  an  OPC  server  that  communicates  with  the  OPC  clients  

•  OPC  allows  “plug-­‐and-­‐play”,  gives  benefits  as  reduces  installaMon  Mme  and  the  opportunity  to  choose  products  from  different  manufactures  

•  Different  standards:  Real-­‐Mme  data  (OPC  DA),  Historical  data  (OPC  HDA),  Alarm  &  Event  data  (OPC  AE),  etc.    

What  is  OPC?  

5  

The  user  are  free  to  choose  the  best  suited  devices,  controller  and  applicaMon  for  their  project  without  worrying  about  which  vendor  each  came  from.  

6  

What  is  OPC?  

E.g.  a  PLC  

OPC  is  the  world’s  most  popular  standards-­‐based  data-­‐connecMvity  method.  It  is  used  to  answer  one  of  the  automaMon  industry’s  biggest  challenges:  how  to  communicate  between  devices,  controllers,  and  applicaMons  without  ge`ng  caught  up  in  the  usual  custom  driver-­‐based  connecMvity  problems.  

7  

NI  USB  TC-­‐01  Thermocouple  

Device  

GeXng  Started  with  the  NI  USB-­‐TC01  Thermocouple  device    

Once  the  device  has  been  successfully  detected,  the  NI  USB-­‐TC01  Launch  Screen  will  open  (as  shown  in  Figure  below),  or  a  Windows  “Autoplay”  dialog  will  appear  allowing  you  to  select  “TC01Launcher.exe”  to  run  the  sobware.  

TC01Launcher.exe  

Note!    If  “Autoplay”  does  not  start  or  it  is  disabled,  locate  the  NI  USB-­‐TC01  under  “My  Computer”  and  double-­‐click  “TC01Launcher.exe”  to  manually  run  the  sobware.  

The  NI  USB-­‐TC01  has  a  green  LED  next  to  the  USB  cable  to  indicate  the    device  status.  When  the  LED  is  illuminated,  the  device  is  powered  and    ready  for  operaMon.  If  the  LED  is  not  illuminated,  the  device  is  not  powered    or  did  not  iniMalize.  

8  

NI  USB-­‐TC01  Thermocouple  Measurement  Device  –  Temperature  Logger  

Run  the  Temperature  Logger  to  check  if  the  device  works  as  expected  before  you  start  on  your  LabVIEW  Programming   9  

Open  the    Log  File  to  see  the  data  

How-­‐To  use  the  NI  USB  TC-­‐01  Thermocouple  Device  in  LabVIEW  

10  

The  USB-­‐TC01  Device  works  similar  as  the  USB-­‐6008  DAQ  device,  i.e.,  you  use  the  DAQ  Assistant  in  LabVIEW  

NI  USB-­‐TC01  Thermocouple  Measurement  Device  using  LabVIEW  

The  USB-­‐TC01  Device  works  similar  as  the  USB-­‐6008  DAQ  device,  i.e.,  you  use  the  DAQ  Assistant  

11  

DAQ  Assistant  for  NI  USB-­‐TC01  

12  

1

2

3

4

5

Acquire  Signals  »  Analog  Input  »  Temperature  »  Thermocouple  

Select  Physical  Channel  ai0  

Use  default  ProperMes  

Click  OK  to  Finish  

Temperature  Simulaaon  

13  

If  you  don’t  have  a  TC-­‐01  device,  you  can  create  a  simple  “Temperature  Simulator”  

A  simple  SubVI  that  simulates  a  Temperature  value  using  a  Random  Generator  

In  this  way  you  can  easily  switch  between  the  real  Temperature  sensor  (TC01)  and  the  Simulator      

Case  Structure  

Case  Structure  

While  Loop  

While  Loop  

14  

OPC  

Matrikon  OPC  Simulaaon  Server  

LabVIEW  

OPC  Server  

OPC  Client  

OPC  DA  

Matrikon  OPC  Explorer  

COM/DCOM  

We  will  use  the  Matrikon  OPC  SimulaMon  Server  –  which  is  a  free  of  charge  OPC  Server  for  test  purposes.    

15  

Note!  Normally,  the  OPC  Server  and  the  Clients  are  not  on  the  same  computer,  but  in  this  assignment  we  will  for  simplicity  have  everything  on  the  same  computer.  

OPC  Client  

OPC  Client  

COM/DCOM  COM/DCOM  

…  

Matrikon  OPC  Explorer  –  Connect  to  Server  

1

2

16  

Matrikon  OPC  Explorer  -­‐  Add  Tags  

Use  the  BucketBrigade  Items  –  because  they  can  be  used  for  both  reading  and  wriMng  

1  

2

3

4

5

17  

Use  OPC  Explorer  to  Check  Communicaaon  Run  the  LabVIEW  program  and  use  the  Matrikon  OPC  Explorer  to  check  if  the  data  is  correctly  wrihen  to  the  OPC  server  from  LabVIEW  

18  

Aliases  In  the  “Matrikon  OPCServer  for  SimulaMon”  you  can  create  Aliases  .  Aliases  is  handy  when  you  want  to  describe  your  OPC  items  using  more  realisMc  names,  e.g.,  we  can  create  an  alias  called  “Temperature”  for  the  “Bucket  Brigade.Real4”  item.  This  is  more  descripMve  and  easier  to  remember.  

19  

Temperature  

You  may  right-­‐click  to  create  one  or  more  Alias  Groups  

Right-­‐click  to  create  a  New  Alias  1 2

3

Type  an  Alias  Name  and  other  se`ngs  here  

Scaling/Converang  in  the  OPC  Server  

𝑇↓𝐹 = 9/5 𝑇↓𝐶 +32  

The  OPC  server  can  automaMcally  scale/convert  values  for  you,  e.g.,  from  degrees  Celsius  to  degrees  Fahrenheit  

We  can  create  different  aliases,  e.g.,  “Temperature  Celsius”  and  “Temperature  Fahrenheit”   20  

21  

OPC  in  LabVIEW  

The  DataSocket  palehe  in  LabVIEW:

Write  Data  to  OPC

Read  Data  from  OPC

Open  ConnecMon  to  OPC  Server

Close  ConnecMon  to  OPC  Server  

Browse  OPC  Servers  and  OPC  Items

You  can  use  LabVIEW  as  an  OPC  client  by  connecMng  to  an  OPC  server  through  a  DataSocket  connecMon.

22  

Write  to  OPC  Server  using  LabVIEW  

Or  specify  URL  directly:  

1 2 3 4

23  

While  Loop  

While  Loop  

Read  from  OPC  Server  using  LabVIEW  

Or  specify  URL  directly:  

1 2 3 4

24  

While  Loop  

While  Loop  

Use  OPC  Explorer  to  Check  Communicaaon  

You  can  manually  change  data  in  the  OPC  Server  using  the  OPC  Explorer  

1

2

3

25  

Log  Data    to  File  

Simple  Example  of  how  to  log  data  to  a  Measurement  File  using  the  “Write  To  Measurement  File”  funcMon  in  LabVIEW  

In  this  example  we  just  generate  some  random  data.  In  your  case  you  shall  log  the  data  received  from  the  OPC  Server  

You  can  turn  logging  On/Off  26  

Log  Data  to  File  -­‐  Properaes  Recommended  Se`ngs  in  the  Properaes  Window  (Right-­‐click  on  the  Write  To  Measurement  File  icon):  

27  

Measurement  File  –  Data  Visualizaaon  Open  the  File  with  Logged  Data  in  e.g.  Notepad:  

Open  the  File  with  Logged  Data  in  MS  Excel  and  create  a  Chart:  

28  

Make  sure  to  format  number  of  Decimals  

SubVI  –  Scaling  from  Celsius  to  Fahrenheit  Front  Panel:  

Block  Diagram:  

Create  an  Icon  in  the  Icon  Editor  

Define  Input  and  Output  Terminals  

29  

Addiaonal  Resources  

•  NI  USB-­‐TC01  Thermocouple  Measurement  Device  

•  Data  AcquisiMon  in  LabVIEW    •  OPC  and  Real-­‐Time  Systems  in  LabVIEW  •  IntroducMon  to  Visual  Studio  and  C#  •  Data  AcquisiMon  in  C#    

30  h5p://home.hit.no/~hansha/  The  resources  are  located  here:  

Hans-­‐Pe5er  Halvorsen,  M.Sc.  Telemark  University  College  Faculty  of  Technology  Department  of  Electrical  Engineering,  Informaaon  Technology  and  Cyberneacs  

   E-­‐mail:  [email protected]  Blog:  h5p://home.hit.no/~hansha/    

31