You are on page 1of 14

INTRODUCCION A LABWINDOWS/CVI

Javier Gamo Aranda Departamento de Electrnica o

UNIVERSIDAD DE ALCALA

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

LABWINDOWS/CVI:

Producto de national instrument (www.ni.com) Entorno de integrado de desarrollo para programadores Orientado para aplicaciones de adquisicin de datos y control de o instrumentos Compatible ANSI C gran exibilidad Caracter sticas generales: Desarrollo interactivo de programas Librer de funciones as Herramientas software para adquisicin, anlisis y presentacin de o a o datos
Javier Gamo Aranda Introduccin a LabWindows/CVI o 2

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

Estructura de un programa en LABWINDOWS/CVI:


1. GUI (Interfaz Grfico de Usuario) User Interface Editor a o o a 2. Programa de control Coordinacin adquisicin + anlisis + GUI 3. Adquisicin de datos Bus externo (GPIB, VXI,...) / tarjeta adquisicin o o 4. Anlisis de datos Librer ad hoc a as

Javier Gamo Aranda

Introduccin a LabWindows/CVI o

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

Entorno LABWINDOWS/CVI: Ventana Project:

Ventana Project (*.prj)

Javier Gamo Aranda

Introduccin a LabWindows/CVI o

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

Entorno LABWINDOWS/CVI: Ventana Source:

Ventana Source (.c) o Cdigo compatible ANSI C editable por el usuario Herramientas de generacin automtica de cdigo! o a o o o o Utilidades de edicin & depuracin de cdigo

Javier Gamo Aranda

Introduccin a LabWindows/CVI o

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

Ejemplo 1: Generacin aleatoria de n meros o u


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

EJERCICIO 1: Modicar sample1.c de forma que: 1. Represente grcamente los datos (pista: usar Function Panel YGraphPopup) a 2. Calcule e imprima en Standard Input/Output la media de los nmeros (pista: u usar Function Panel Mean)
Javier Gamo Aranda Introduccin a LabWindows/CVI o 6

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 1:

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

Javier Gamo Aranda

Introduccin a LabWindows/CVI o

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

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

Introduccin a LabWindows/CVI o

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

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


Construccin de GUIs para controlar el ujo del programa y mostrar resultados o EJERCICIO 2: Adquisicin y representacin de una forma de onda o o

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 Introduccin a LabWindows/CVI o 9

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

User Interface Editor: edicin propiedades o

Callback Function: AcquireData (a rellenar ms tarde) a File Save As (ejemplo2.uir) Preview User Interface Header ejemplo2.h, generado automtia camente Code Preferences Default Control Events EVENT COMMIT,
EVEN RIGHT CLICK

Code Generate All Code panelHandle


Javier Gamo Aranda Introduccin a LabWindows/CVI o 10

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

User Interface Editor: adicin cdigo para AcquireData o o


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 Introduccin a LabWindows/CVI o 11

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 2:
#include #include #include #include <ansi_c.h> <cvirte.h> <userint.h> "sample4.h" /* Needed if linking in external compiler; harmless otherwise */ 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 o therwise */ 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

Introduccin a LabWindows/CVI o

12

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

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

Incluir <cvi tutorial>\scope.fp Funciones: scope init, scope config, scope read waveform Mximo y m a nimo: MaxMin1D Utilizar SetCtrlVal y GetCtrlVal adecuadamente

Javier Gamo Aranda

Introduccin a LabWindows/CVI o

13

DEPARTAMENTO DE ELECTRONICA

Escuela Politcnica e

UNIVERSIDAD DE ALCALA

SOLUCION EJERCICIO 3:

Javier Gamo Aranda

Introduccin a LabWindows/CVI o

14

You might also like