Hans-Petter Halvorsen
https://www.halvorsen.blog
LabVIEW in Automation
Datalogging and Monitoring in LabVIEW
Introduction
Datalogging and Monitoring Examples
OPC
Matrikon OPC Simulation Server
OPC DA
OPC UA (The Next Generation OPC)
Database Systems
SQL Server
Structured Query Language (SQL)
LabVIEW SQL Toolkit
Delivery
Contents
All Automation Systems or Process
Control Systems, SCADA Systems log
Data from different Sensors or other
Process Information
These Data are stored into a Database
System and/or an OPC Server
The Data is then Monitored, i.e.,
showing Plots, Statistics, Alarms, etc.
Datalogging and Monitoring
SCADA - Supervisory Control And Data Acquisition
Datalogging and Monitoring
Data-
base
Sensors
DAQ System
3. Data Analysis and Monitoring
2. Data Storage
1. Data Collection
Apps
Datalogging and Monitoring Examples
Below you see an example of a “Datalogging and MonitoringApplication made in LabVIEW:
YouTube Video:
Hans-Petter Halvorsen
https://www.halvorsen.blog
OPC
Table of Contents
A standard that defines the communication of data
between devices from different manufactures
Requires an OPC server that communicates with the OPC
clients
OPC allows “plug-and-play, gives benefits as reduces
installation time and the opportunity to choose products
from different manufactures
Different standards: “Real-time” data (OPC DA), Historical
data (OPC HDA), Alarm & Event data (OPC AE), etc.
What is OPC?
OPC Server and Client(s)
OPC Server
OPC Client
Write Data
Data Storage
OPC Client
Read Data
Measurement Data
Monitoring and Analysis
Data from Sensors, etc.
Typical OPC Scenario
OPC-Server
Network
OPC-Client
OPC-Client
Process
Process Data
Data Acquisition
PLC, PAC, DCS, SCADA
Driver
Sensors
Actuators
OPC Specifications
OPC DA
OPC HDA
OPC A&E
OPC UA
“Classic” OPC
“Next Generation” OPC
... (Many others)
UA Unified Architecture
The Next Generation OPC
Cross Platform. “Classic“ OPC works only for
Windows
Based on Modern Software/Network
Architecture (No DCOM problems!)
It makes it easier to transmit and receive data in
a modern data network/Internet
OPC UA
OPC Classic
OPC UA
OPC DA Server
OPC HDA Server
OPC A&E Server
COM/DCOM
XML, HTTP, SOAP
Cross-platform
Windows only
All specifications
collected in one (DA,
HDA, A&E)
Next Generation OPC
OPC Client
(DCOM)
OPC DA
OPC HDA
OPC A&E
OPC UA Server
OPC UA Client
Protocols: “UA Binaryor “UA XML
Windows, Linux, Mac,
Embedded, VxWorks
Theory
Simpler!!
Next Generation OPC
OPC Software
We will use the following Software:
Matrikon OPC Simulation Server
Free OPC DA Server for Test purposes
LabVIEW
LabVIEW has built-in OPC DA Client
LabVIEW OPC UA Toolkit
Her you can create both OPC UA Servers and OPC UA Clients.
If you don’t have a valid license, you can use it for free in a
limited trial period (some weeks)
Matrikon OPC Simulation Server
1
2
MatrikonOPC Explorer - Add Tags
1
2
3
4
5
Double-click
Finished
Use the BucketBrigade Items because they can be used for both reading and writing
MatrikonOPC Explorer
The MatrikonOPC Explorer is useful for testing. You can use it for writing and reading OPC Tags
Right-click in order to Write
Data to the OPC Server
OPC in LabVIEW
OPC DA in LabVIEW:
Built-in support using the DataSocket features
With this feature you can communicate with existing OPC
DA Servers like, e.g., the Matrikon OPC Simulation Server
OPC UA in LabVIEW:
NI OPC UA Toolkit
This is an additional Toolkit not part of the the standard
LabVIEW software.
You need to pay extra for this Toolkit
With this Toolkit you can create both OPC UA Servers and OPC
UA Clients
Hans-Petter Halvorsen
https://www.halvorsen.blog
OPC DA
Table of Contents
OPC DA in LabVIEW
The DataSocket palette in LabVIEW:
Write Data to OPC
Read Data from OPC
Open Connection
to OPC Server
Close Connection
to OPC Server
Browse OPC
Servers and OPC
Items
You can use LabVIEW as an OPC DA client by connecting to an
OPC DA server through a DataSocket connection
OPC DA LabVIEW Example
Matrikon OPC Simulation Server
OPC DA
Server
OPC DA
Client
OPC DA
Client
LabVIEW Application #1
LabVIEW Application #2
Write Data to
OPC DA Server
Read Data from
OPC DA Server
Write Data to OPC DA Server
Or specify URL directly:
1
2
3
4
While Loop
While Loop
Use the BucketBrigade Items because they
can be used for both reading and writing
MatrikonOPC Explorer
Run the LabVIEW program and use the Matrikon
OPC Explorer to check if the data is correctly
written to the OPC server from LabVIEW
Read Data from OPC DA Server
1 2
3
4
While Loop
While Loop
Or specify URL directly:
Hans-Petter Halvorsen
https://www.halvorsen.blog
OPC UA
Table of Contents
OPC UA Toolkit in LabVIEW
OPC UA Example
Write Data to OPC UA Server
Read Data from OPC UA Server
LabVIEW Application #2 LabVIEW Application #3
In this Example LabVIEW Application #1,
#2 and #3 are on the same computer.
Normally they are located on different
computers or devices in a Network.
LabVIEW Application #1
OPC UA Server
OPC UA Client
OPC UA Client
27
OPC UA Server Example in LabVIEW
OPC UA Client - Write Data
OPC UA Client - Read Data
OPC UA in LabVIEW
OPC UA Server
OPC UA Client Write Data
OPC UA Client Read Data
Hans-Petter Halvorsen
https://www.halvorsen.blog
Database Systems
Table of Contents
Database Systems
A Database is a structured way to store lots of information
The information is stored in different Tables inside the
Database System
We have many different Database Systems today, such as
SQL Server, MySQL, PostgreSQL, Oracle, MongoDB, etc.
We will use SQL Server from Microsoft
Today all” Software Systems saves and retrieves data
from a Database System
Examples: Facebook, Bank Systems, Process Control
Systems, Web Shops, etc.
Database Systems
Database
SQL
SQL Structured Query Language
DataBase
Management
System
(DBMS)
We communicate with the Database using a DataBase Management System (DBMS). We use
the Structured Query Language (SQL) in order to communicate with the Database, i.e., Insert
Data, Retrieve Data, Update Data and Delete Data from the Database.
Popular Database Systems
https://insights.stackoverflow.com/survey/
SQL Server
SQL Server Express
Free version of SQL Server that has all we need for for
the exercises in this module
SQL Server Express consist of 2 parts (separate
installation packages):
SQL Server Express
SQL Server Management Studio (SSMS) This software
can be used to create Databases, create Tables,
Insert/Retrieve or Modify Data, etc.
SQL Server Management Studio
Write your Query here
The result from your Query
Your Database
Your
Tables
Your SQL Server
2
3
4
5
1
Structured Query Language
Structured Query Language (SQL) is used to
write, read and update data from the
Database System
You can use SQL inside the “SQL Server
Management Studio” or inside your LabVIEW
Application.
SQL Examples
insert into STUDENT (Name , Number, SchoolId)
values ('John Smith', '100005', 1)
select SchoolId, Name from SCHOOL
select * from SCHOOL where SchoolId > 100
update STUDENT set Name='John Wayne' where StudentId=2
delete from STUDENT where SchoolId=3
Query Examples:
We have 4 different Query Types: INSERT, SELECT, UPDATE and DELETE
LabVIEW SQL Toolkit
https://www.halvorsen.blog/documents/technology/database/database_labview.php
For Easy Database Communication with LabVIEW
© Hans-Petter Halvorsen
Download for free here:
LabVIEW SQL Toolkit
Example 1: Get Data from Database into LabVIEW:
Example 2: Write Data to Database from LabVIEW:
Easy Access to Database Systems from LabVIEW
Your ODBC
Connection
2D Table with Data
1
Query
Query
2
3
1
2 3
Connect to the Database
Alt 1: Use ODBC
Setup your Database connection using a Wizard (“ODBC
Data Source Administrator”)
Alt 2: Use Connection String directly
Alt 2.1: Windows Authentication:
Data Source=<dbserver>;Initial Catalog=<dbname>;Trusted_Connection=True
Alt 2.2: SQL Server Authentication:
Data Source=<dbserver>;Initial Catalog=<dbname>;Persist Security Info=True;User ID=sa;Password=<password>
ODBC
42
The Name of your
SQL Server
The Name of your
ODBC Connection
Use either Windows
or SQL Server
authentication
(Windows is simplest
to use!)
Select the Database
you are using
Test your
connection to see
if its works
Using Connection String
Easy Access to Database Systems from LabVIEW
Alternative Solution: Type in the Connection String for your Database
Note! When using this method, you don’t need to create an ODBC Connection first!
Your Password for the sa user
Your SQL Server Instance
Type your Database here
Your SQL Query
LabVIEW Example
LabVIEW Example
To practice you can use one (or both) of the
Temperature Sensors from the previous
Module, i.e., read Temperature Data using
the USB-6008 DAQ and then Save the
Temperature Data to the SQL Server Database
Hans-Petter Halvorsen
https://www.halvorsen.blog
Delivery
Table of Contents
System Sketch
File
SQL Server
OPC Server
LabVIEW
App #1
Control System in LabVIEW
Excel
Control System
Logging System
Analytics
Write
Write
Read
LabVIEW
App #2
Write
App#1 and 2 are running
on the same PC in parallel
System Requirements
Create a Datalogging and Monitoring System
Extend your Level Tank system with Datalogging and Monitoring Features, i.e., send the process value to an OPC
Server and then save it to a Text File and to a Database. Make sure that you have also updated your Level Tank
system based on feedback given in previous Modules and include your latest LabVIEW skills.
You should create 2 LabVIEW Applications:
LabVIEW Application #1 - Control System. Send Data to OPC Server. This means you should update your existing
Level Tank application by sending the process data to the OPC Server (it is enough sending the process value,
i.e., the level in the water tank). In addition, you should fix your program according to the comments/feedback
given from the previous module.
LabVIEW Application #2 Datalogging System. Retrieve Data from OPC Server and store the Data in a Text file
and a SQL Server Database
Make sure to create a proper GUI. You decide if you want to use OPC DA or OPC UA.
Make .exe files of your LabVIEW Applications.
You should open the Data from either the Database or the Text File in MS Excel. Make a simple plot
and do some basic analytics (e.g., find the average, etc.).
The code should be well structured and intuitive. It should contain basic LabVIEW features like While
Loop, Case Structure, SubVIs, Arrays, Property Nodes and Clusters, etc. You should use the Project
Explorer.
Please follow the "LabVIEW Programming Guidelines"
Hans-Petter Halvorsen
University of South-Eastern Norway
www.usn.no
E-mail: hans.p.halvorsen@usn.no
Web: https://www.halvorsen.blog