Using Databases Labview

26
Using Databases With LabVIEW LabVIEW User Group Meeting December 2007 ALE System Integration PO Box 832 Melville, NY 11747-0832 +1 (631) 421-1198 Charles Spitaleri

Transcript of Using Databases Labview

Page 1: Using Databases Labview

Using DatabasesWith LabVIEW

LabVIEW User Group Meeting December 2007

ALE System IntegrationPO Box 832Melville, NY 11747-0832+1 (631) 421-1198

Charles Spitaleri

Page 2: Using Databases Labview

ALE System Integrationhttp://www.aleconsultants.com – [email protected]

� National Instruments Certified Alliance Partner

� Over 10 Years LabVIEW and Test & Automation experience

� Located in and servicing Long Island and New York City

� Expertise in NI and other instrument manufacturers’ products

� All developers have National Instruments Certification

� Test & Measurement Specialties:– Aerospace/DoD – Automotive– Calibration – Sound and Vibration– Telecommunications/RF – Test Labs– ISO17025 – Instrument Control

Page 3: Using Databases Labview

Charles Spitaleri� Bachelor of Science in Computer Science, New York

Institute of Technology� Background in Electrical Engineering� National Instruments Certified LabVIEW Developer� Co-founder and Vice-President of ALE System Integration� Worked for Underwriters Laboratories for 18 years� Worked for Underwriters Laboratories for 18 years� 9 years LabVIEW and Test & Measurement experience� Member of the IEEE and ACM� Technical knowledge of Database/SQL, DAQ, SCXI,

Machine Vision, Motion Control, FieldPoint, GPIB/Serial control of instruments.

Page 4: Using Databases Labview

� An overview of databases, how they work, and how to interface them with LabVIEW

� A summary of my experiences with databases in the LabVIEW environment

About this presentation…

databases in the LabVIEW environment� All examples:

– Microsoft Windows XP sp2– Microsoft Access 2007– LabVIEW 8.2.1– Database Connectivity Toolset 1.0.1

Page 5: Using Databases Labview

What is a database?

TechTarget.com:A database is a collection of information that is organized so that it can easily be accessed, managed, and updated.

Simple definition:Intelligent data storage object

Page 6: Using Databases Labview

Types of databases?

� Hierarchical� Network� Relational� Object-Oriented

Relational

� Object-Oriented

Page 7: Using Databases Labview

Who makes databases?

� Microsoft:– SQL Server– Access

� Oracle� MySQL (open source)� PostgreSQL (open source)� SQL Anywhere (Sybase)� Others…

Page 8: Using Databases Labview

Relational database

A look inside:

INTERFACEINTERFACE

LOGICLOGIC

ENGINEENGINEDATADATAMicrosoftMicrosoftMicrosoftMicrosoftMicrosoftMicrosoftMicrosoftMicrosoft AccessAccess

Microsoft Data Microsoft Data

Access ComponentsAccess Components

(MDAC)(MDAC)

LabVIEW to MDAC LabVIEW to MDAC

InterpreterInterpreter

(MDAC)(MDAC)

LabVIEW Database LabVIEW Database

Connectivity ToolkitConnectivity Toolkit

Page 9: Using Databases Labview

Why use a database?

� Collect data from multiple/remote systems� Large amounts of data� Smart data manipulation/query� Secure storage� Secure storage

Page 10: Using Databases Labview

Why use a database? (Case 1)

� Multiple standalone part testers� Test results collected in remote database� Database queried via company website� Data queried by:� Data queried by:

– Serial Number– Test system ID– Test Results

Page 11: Using Databases Labview

Why use a database? (Case 2)

� 100’s of ovens scattered over the world� Temperatures monitored/recorded� Temperature alarms for each oven� Datetime stamp each reading� Datetime stamp each reading� Ovens queried by:

– Location– Temperature– Time period

Page 12: Using Databases Labview

Setting up a database

� Create database file (*.mdb)� Create table (name)� Create columns:

– Column name

DONEDONE

ININ– Column name– Column data type– Column can be null?– Column is primary key?

� Create more tables/columns as necessary� Create database connection

ININ

ACCESSACCESS

DONE IN ODBC DATA SOURCE ADMINISTRATORDONE IN ODBC DATA SOURCE ADMINISTRATOR

Page 13: Using Databases Labview

Additional Considerations

� Keys– Primary– Secondary– Foreign

� Normalization– A formal database design technique– 1st Form – 5th Form– Boyce-Codd Form (between 3rd & 4th form)

Page 14: Using Databases Labview

Setting up a database

MS Access Example….

Page 15: Using Databases Labview

Database Connection

� Database Source Name (DSN)– A data structure used to describe a connection

to a database.– ODBC Data Source Administrator

User DSN: available to current user only� User DSN: available to current user only� System DSN: available to current system only� File DSN: Connection info in file (*.dsn)

� Universal Data Link (UDL)– A type of file that provides a common user

interface for specifying connection attributes. (*.udl)

Page 16: Using Databases Labview

Setting up a database

ODBC Data Source Administrator Example…

Page 17: Using Databases Labview

Database Connectivity Toolkit

Page 18: Using Databases Labview

Palette Layout

TopTopTopTop----Level Menu:Level Menu:Level Menu:Level Menu:

Utility Menu:Utility Menu:Utility Menu:Utility Menu:

List TablesList Columns

Set Properties

Get Properties

Format Datetime

DB Transaction

Save Recordset to File

Load Recordset from File

TopTopTopTop----Level Menu:Level Menu:Level Menu:Level Menu:Open Connection

Close Connection

Insert Data

Select Data

Create Table

Drop Table

DB Variant to Data

Advanced Menu:Advanced Menu:Advanced Menu:Advanced Menu:

Execute QueryFetch Recordset Data

Fetch Element Data

Fetch Next Recordset

Free Object

Move to Next Record

Move to Previous Record

Move to Record N

Create Parameterized Query

Set Parameter Value

Get Parameter Value

Page 19: Using Databases Labview

LabVIEW Examples

Data Manipulation� Insert� Update� Delete� Delete� Retrieve data� Retrieve data conditionally

Page 20: Using Databases Labview

LabVIEW Examples

Data Definition� Create Table� Drop Table� List tables in database� List tables in database� List columns in table

Page 21: Using Databases Labview

SQL

� Structured Query Language� ANSI Standard computer language**� Primary way of interfacing with a database� SQL parts:� SQL parts:

– Data Manipulation Language (DML)� Aggregate functions

– Data Definition Language (DDL)

Page 22: Using Databases Labview

SQL: Data Manipulation

DML affects the data within the database

� Insert/Delete/Update Data� Query (get) dataQuery (get) data� Query data conditionally� Aggregate Functions:

– Sum– Avg– Max– Min

Page 23: Using Databases Labview

SQL: Data Definition

DDL affects the database structure

� Create/Drop/Alter Table� Create/Drop ViewCreate/Drop View� Create/Drop Index� Create/Drop Users

Page 24: Using Databases Labview

SQL Examples

Page 25: Using Databases Labview

LabVIEW executable w/database

� MDAC = Microsoft Data Access Components– ActiveX Data Objects (ADO)– Object Linking & Embedding Database (OLE DB)– Open Database Connectivity (ODBC)

� Knowledgebase article : 3YR8K3G2Building an Executable with LabVIEW 8.x and Database Connectivity Toolset

Page 26: Using Databases Labview

References� Database Design for Mere Mortals

by Michael J. Hernandez; ISBN: 0-201-69471-9

� LabVIEW Examples :LabVIEW -> Help -> Find Examples -> Toolkits & Modules -> Database Connectivity

� Wikipedia:Wikipedia:http://www.wikipedia.org/

� LabVIEW Help:LabVIEW -> Help -> Database Toolset Help and Examples…

� ALE System Integration website :http://www.aleconsultants.com

� NI LabVIEW Database Connectivity Toolset User Manua l: http://www.ni.com/pdf/manuals/321525c.pdf