14
INTRODUCCI ´ ON A LABWINDOWS/CVI Javier Gamo Aranda Departamento de Electr´onica UNIVERSIDAD DE ALCAL ´ A

Labwindows Intro

Embed Size (px)

Citation preview

Page 1: Labwindows Intro

INTRODUCCION A LABWINDOWS/CVI

Javier Gamo Aranda

Departamento de Electronica

UNIVERSIDAD DE ALCALA

Page 2: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

LABWINDOWS/CVI:

— Producto de national instrument (www.ni.com)

— Entorno de integrado de desarrollo para programadores

— Orientado para aplicaciones de adquisicion de datos y control deinstrumentos

— Compatible ANSI C ⇒ gran flexibilidad

Caracterısticas generales:

— Desarrollo interactivo de programas

— Librerıas de funciones

— Herramientas software para adquisicion, analisis y presentacion dedatos

Javier Gamo Aranda Introduccion a LabWindows/CVI 2

Page 3: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

Estructura de un programa en LABWINDOWS/CVI:

1. GUI (Interfaz Grafico de Usuario)⇒ User Interface Editor

2. Programa de control ⇒ Coordinacion adquisicion + analisis + GUI

3. Adquisicion de datos ⇒ Bus externo (GPIB, VXI,...) / tarjeta adquisicion

4. Analisis de datos ⇒ Librerıas ad hoc

Javier Gamo Aranda Introduccion a LabWindows/CVI 3

Page 4: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

Entorno LABWINDOWS/CVI: Ventana Project:

Ventana Project (*.prj)

Javier Gamo Aranda Introduccion a LabWindows/CVI 4

Page 5: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

Entorno LABWINDOWS/CVI: Ventana Source:

Ventana Source (.c)

— Codigo compatible ANSI C editable por el usuario

— Herramientas de generacion automatica de codigo!

— Utilidades de edicion & depuracion de codigo

Javier Gamo Aranda Introduccion a LabWindows/CVI 5

Page 6: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

Ejemplo 1: Generacion aleatoria de numeros

1. Abrir <cvi directory>\tutorial\sample1.prj2. Ejecutar proyecto (Run → Run project)

EJERCICIO 1: Modificar sample1.c de forma que:

1. Represente graficamente los datos (pista: usar Function Panel YGraphPopup)

2. Calcule e imprima en Standard Input/Output la media de los numeros (pista:usar Function Panel Mean)

Javier Gamo Aranda Introduccion a LabWindows/CVI 6

Page 7: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 1:

— Code ⇒ Set Target File (sample1.c) + Insert Function Call

Javier Gamo Aranda Introduccion a LabWindows/CVI 7

Page 8: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 1 (cont.):

#include <ansi_c.h>#include <userint.h>#include <analysis.h>

int i = 0, err;double mean_value;double datapoints[100];

int main(int argc, char *argv[]){ if (InitCVIRTE (0, argv, 0) == 0) /* needed if linking executable in external compiler; harmless otherwise */ return (-1); /* out of memory */ for (i = 0 ; i < 100 ; i++) { datapoints[i] = rand()/32768.0; printf ("%d \t %f\n", i, datapoints[i]); } YGraphPopup ("random data", datapoints, 100, VAL_DOUBLE); err = Mean (datapoints, 100, &mean_value); printf("Mean = \t %f \n", mean_value); return 0;}

Javier Gamo Aranda Introduccion a LabWindows/CVI 8

Page 9: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

Entorno LABWINDOWS/CVI: User Interface Editor (.uir)

— Construccion de GUIs para controlar el flujo del programa y mostrar resultados

EJERCICIO 2: Adquisicion y representacion de una forma de onda

1. Project Window: File ⇒ Open User Interface (*.uir)⇒ template.uir

2. UIR Window: Create ⇒ Command Button⇒ Adquirir , Salir

3. UIR Window: Create ⇒ Graph

Javier Gamo Aranda Introduccion a LabWindows/CVI 9

Page 10: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

User Interface Editor: edicion propiedades

— Callback Function: ⇒ AcquireData (a rellenar mas tarde)

— File ⇒ Save As (ejemplo2.uir)

— Preview ⇒ User Interface Header ⇒ ejemplo2.h, generado automati-camente

— Code ⇒ Preferences ⇒ Default Control Events ⇒ EVENT COMMIT,

EVEN RIGHT CLICK

— Code ⇒ Generate All Code ⇒ panelHandle

Javier Gamo Aranda Introduccion a LabWindows/CVI 10

Page 11: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

User Interface Editor: adicion codigo para AcquireData

— Declarar variables: int i; double datapoints[100]

— case: EVENT COMMIT ⇒ Edit ⇒ Insert Construct ⇒ For Loop...i=0, i <100, i++ ⇒ datapoints[i] = rand()/32767.0

— PlotY: Library ⇒ User Interface ⇒ Controls/Graphs/... ⇒ Graph& Strip...

— Code ⇒ Personaliza PlotY:

— Edit⇒Add File to Project⇒ ejemplo2.c, ejemplo2.h, ejemplo2.uir

Javier Gamo Aranda Introduccion a LabWindows/CVI 11

Page 12: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 2:#include <ansi_c.h>#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */#include <userint.h>#include "sample4.h"

static int panelHandle;int i;double datapoints[100];

int main (int argc, char *argv[]){ if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, "sample4.uir", PANEL)) < 0) return -1; DisplayPanel (panelHandle); RunUserInterface (); return 0;}

int CVICALLBACK Shutdown (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_COMMIT: QuitUserInterface (0); break; case EVENT_RIGHT_CLICK:

break; } return 0;}

int CVICALLBACK AcquireData (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_COMMIT: for (i=0; i<100; i++) { datapoints[i] = rand()/32767.0;} PlotY (panelHandle, PANEL_WAVEFORM, datapoints, 100, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);

break; case EVENT_RIGHT_CLICK:

break; } return 0;}

Javier Gamo Aranda Introduccion a LabWindows/CVI 12

Page 13: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

EJERCICIO 3:Modificar ejemplo2.prj para implementar la siguiente interfaz de usuario:

— Incluir <cvi tutorial>\scope.fp⇒ Funciones: scope init, scope config,scope read waveform

— Maximo y mınimo: MaxMin1D

— Utilizar SetCtrlVal y GetCtrlVal adecuadamente

Javier Gamo Aranda Introduccion a LabWindows/CVI 13

Page 14: Labwindows Intro

DEPARTAMENTO DE ELECTRONICA Escuela Politecnica UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 3:

Javier Gamo Aranda Introduccion a LabWindows/CVI 14