Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome! Workshop 2 of 7.

Similar presentations


Presentation on theme: "Welcome! Workshop 2 of 7."— Presentation transcript:

1 Welcome! Workshop 2 of 7

2 Today's Topics Review of Workshop 1 Basic VI Structure Arrays Clusters
Error Cluster Enumerations

3 Review Question 1 Which of the following are the three parts of a VI?
Front Panel Project Block Diagram Connector Pane/Icon

4 Review Question 1 Which of the following are the three parts of a VI?
Front Panel Project Block Diagram Connector Pane/Icon The project helps organize your VIs that are related to one another (as well as other files). A project is not part of a VI, instead it contains VIs

5 Review Question 2 Which identifies the control or indicator on the block diagram? Caption Location Label Value

6 Review Question 2 Which identifies the control or indicator on the block diagram? Caption Location Label Value The label identifies the terminal that maps to the control or indicator that is on the front panel. Location does not matter; the value is often not seen on the block diagram; and the caption is only available on the front panel.

7 Review Question 3 Which of the following are not a nodes? Terminals
Structures (while loop, for loop) subVIs Wires Functions

8 Review Question 3 Which of the following are not a nodes? Terminals
Structures (while loop, for loop, etc.) subVIs Wires Functions Terminals and wires are also found on the block diagram, but are not nodes.

9 Review Question 4 Which function executes first: Add or Subtract? Add
Unknown

10 Review Question 4 Which function executes first: Add or Subtract? Add
Unknown Add will execute before subtract because the subtract function is dependent on the output of add. The subtract cannot execute until it receives the output from add. Note: We do not know if Add or Random Number will execute first – either can.

11 Review Question 1 True or False?
It is possible to add non-VI files to a LabVIEW Project.

12 Review Question 1 True or False?
It is possible to add non-VI files to a LabVIEW Project. TRUE You can add text files, excel files, word documents, configuration files, and more to the LabVIEW Project. In fact, it is a good idea if those files are directly related, critical, or essential to the application.

13 Review Question 2 True or False? If I am using a virtual folder in the LabVIEW Project, I must keep all of the related files together on disk.

14 Review Question 2 True or False? If I am using a virtual folder in the LabVIEW Project, I must keep all of the related files together on disk. FALSE Virtual folders are not auto-managed like auto-populating folders, which will update in real time to reflect the contents of folders on disk. Therefore, you can add/remove items from a virtual folder that are in various locations on disk. However, it is generally good practice to keep related files together on disk, if possible.

15 Review Question 3 Which mechanical action causes a Boolean in the False state to change to True when you click it and stay True until you release it and LabVIEW has read the value (similar to how a button in Windows operates)? Switch Until Released Switch When Released Latch Until Released Latch When Released

16 Review Question 3 Which mechanical action causes a Boolean in the False state to change to True when you click it and stay True until you release it and LabVIEW has read the value (similar to how a button in Windows operates)? Switch Until Released Switch When Released Latch Until Released Latch When Released It’s an “until released” because its “STAYS true UNTIL you release it” It’s a “Latch” because LabVIEW must read the value.

17 Basic VI Structure Acquire Analyze Present
The most basic VI structure is to first acquire data (from an instrument, file, etc), then analyze (or in some way manipulate- filter, add a gain, subtract noise, curve fit, etc), and finally present the results to the user (maybe through a graph, or an LED that says Pass/Fail) Look at acq_an_pres.vi example

18 Arrays An array consists of elements and dimensions
Elements: data that make up the array Dimension: the length, height, or depth of an array (231)–1 elements per dimension, memory permitting 1 or more dimensions Elements (numeric, here) Index, tells dimension (1D, here) Array: Arrays group data elements of the same type. An array consists of elements and dimensions. Elements are the data that make up the array. A dimension is the length, height, or depth of an array. An array can have one or more dimensions and as many as (231) – 1 elements per dimension, memory permitting. 18

19 Arrays: the elements Arrays can be of many different data types, but only one data type at a time All the elements in an array must have the same data type, because arrays, by definition, are a way to group items of the same data type. 19

20 Arrays: Initialized and Uninitialized
If the elements of an array are grayed out, then those elements are uninitialized. Uninitialized elements do not have a value and are place holders The uninitialized elements are outlined in red; the initialized elements are outlined in black. Initialized elements have a value. Uninitialized elements are just place holders, so they don’t have a value. They are spots that values can be added. When determining the size of an array, only the initialized elements are considered. Uninitialized elements Initialized elements 20

21 Arrays: Size vs. Dimension
Size is the number of initialized elements in each dimension Dimension is how the elements are organized Size: 4 Dimension: 1D Size: 0x0 Dimension: 2D Size: 4 Dimension: 1D To determine the size of a 1D array, count the number of initialized elements To determine the size of a 2D array, count the number of initialized elements in a row and the number of initialized elements in a column Size: 2x3x? Dimension: 3D Size: at least 4 – more elements could be hidden Dimension: 1D 21

22 Creating an Array Place an array shell on the front panel
From the Controls»Modern»Array, Matrix, and Cluster subpalette, select the Array icon. Drag a data object or element into the array shell To create an array control or indicator as shown, select an array on the Controls»Modern»Array, Matrix, and Cluster palette, place it on the front panel, and drag a control or indicator into the array shell. If you attempt to drag an invalid control or indicator such as an XY graph into the array shell, you are unable to drop the control or indicator in the array shell. Once a valid item is placed in the array shell, the array shell shrinks to fit around the control or indicator. You can then drag the edge of the array to display more elements. Array shells are available on the front panel and block diagram, but you must insert an object in the array shell before you use the array on the block diagram. Otherwise, the array terminal appears black with an empty bracket. © National Instruments Corporation 60 Introduction to LabVIEW Hands-On

23 Arrays: the index The index (zero-based) tells you : index
the dimension of the array (1D, 2D, 3D, etc.) the index of the element displayed in the upper left corner - the 1D array below is displaying index 1 to contain a value of 3.00; we do not know the value of index 0 from this image because the value at index 0 is hidden from view 2D Array (uninitialized) 1D Array (initialized) (row) To add dimensions to an array one at a time, right-click the index display and select Add Dimension from the shortcut menu. You also can use the Positioning tool to resize the index display until you have as many dimensions as you want. The index display tells you the index (location) of the element that is currently displayed in the box in the upper right-hand corner of the array. Imagine the border of the array like a window into a giant speadsheet of numbers, where the spreadsheet can slide around behind the window. The index will tell you how much the spread sheet has slid around from its home position, where the window shows the top left corner of the spreadsheet values. Therefore, the 1D array is hiding index 0 and possibly other values at index 3 or more. The index is zero-based, meaning it begins it counting with zero. Uninitialized arrays will have a gray background and grayed-out numbers. If you have a value at index 1,1 in an array (which would be a 2x2 array), then column 3 will be uninitialized and all columns less than 3 (0,1,2) must be initialized . Keep in mind an array is defined to be a 2x2 by the number of rows/columns that are initialized, not just the number of columns and rows being displayed through the “array window”. (column) index TIP: drag the edge of the index to add another dimension to an array Introduction to LabVIEW Hands-On 61 ni.com

24 Demonstration 1: Creating an array Look at Array.vi example
Introduction to LabVIEW Hands-On 24 ni.com

25 Array Functions Array Size: Index Array: Initialize Array:
Returns the number of elements in each dimension of the array Index Array: Returns the value at the index you specify Initialize Array: Creates an initialized array of the dimension and data type you specify Build Array: Adds elements or dimensions to an array Search 1D Array: Returns the index of the value you specify; if not found, returns -1 There are many more array functions; however, these are the ones that are often used.

26 Clusters Clusters group data elements of mixed types
Similar to a record or a struct in text-based programming languages Cluster: Clusters group data elements of mixed types. Often the objects have a relationship with one another from the perspective of the user or programmer (such as the student’s name [string], age [numeric], and graduation status [boolean]). Cluster are created in a similar fashion to arrays: place a shell, then add object into the shell. 26

27 Cluster Functions Bundle (there is also Unbundle)
Assembles a cluster from individual elements. Bundle By Name (there is also Unbundle By Name) Replaces one or more cluster elements. This function refers to cluster elements by name instead of by their position in the cluster. Cluster Constant Use this constant to supply a constant cluster value to the block diagram. The terms bundle and cluster are closely related in LabVIEW. Example: You use a bundle function to create a cluster. You use an unbundle function to extract the parts of a cluster. Bundle - Forms a cluster containing the given objects in the specified order. Bundle by Name - Updates input cluster’s element values (the object must have an owned label). *requires input cluster* Unbundle - Splits a cluster into each of its individual elements by data type. Unbundle by Name - Returns the cluster elements whose names you specify. Two major difference between Unbundle/Bundle and Unbundle By Name/Bundle By Name: (1) “By Name” = label of elements visible (not just the data type. (2) Bundle By Name requires an input cluster and updates, instead of creating a new cluster. (Terminal labels reflect data type) Bundle By Name Cluster Constant Bundle Introduction to LabVIEW Hands-On 81 ni.com

28 Clusters: Order Cluster elements have a logical order unrelated to their position in the shell You can view and modify the cluster order by right-clicking the cluster border and selecting Reorder Controls In Cluster from the shortcut menu Order determines how cluster is unbundled The order in clusters is important to… the user if they want to tab through the objects (ie, input value 1, tab, input value 2, tab….) -the programmer because the order is what defines the order in which items are unbundled from a cluster using the Unbundle function. The Unbundle By Name function will display the label of the items, but the Unbundle function only displays the data type. Therefore, the only way to determine which string output is at the top of the Unbundle function when there are multiple strings in the cluster is through the order. The initial order of a cluster is determined by the order in which elements are added. If I add a numeric, a boolean and then a string; the order will be numeric=0, boolean=1, string=2. When reordering, the number displayed in the menu bar (outlined in red on this slide) will be the new order number given to the element that you next click on. It will increment after an item is clicked. You can enter a value, such as 4, to specify the new value. In other words, you do not have to start at zero and click through every element of the cluster. 28

29 Error Cluster Three parts:
Status – Boolean, TRUE when an error occurred Code - numeric (I32), identifies which error occurred Source – string, identifies where the error occurred Note: Warnings have a code and source, but the status is FALSE 29

30 Creating a cluster and reordering its element
Demonstration 2: Creating a cluster and reordering its element Error.vi Example Introduction to LabVIEW Hands-On 24 ni.com

31 Clusters vs. Arrays Clusters differ from arrays in that they are a fixed size Clusters can contain mixed data types; arrays contain only one data type Like an array, a cluster is either a control or an indicator and cannot contain a mixture of controls and indicators You can create a cluster of clusters, cluster of arrays, array of clusters, but NOT an array of arrays Cluster are a fixed size because you cannot add an object to an existing cluster – only change the values within the object. You can create a new cluster which contains an existing cluster (cluster within a cluster), but this is still a new cluster. Great article about Arrays and clusters:

32 Enumeration An enum represents a pair of values, a string and a numeric, where the enum’s value is one of a defined list of value pairs Appears as a string to you, and a number to computer An enum (short for enumeration) is a data type that pairs a number with a string (ie, months of the year with the number 0-11). The list of pairings is maintained as part of the data type (this is important when it comes to type definitions and is different from a ring, which looks similar)

33 Enumeration: Configuring
Right-click on the enum Select Edit Items… Right-click and select Edit Items… to bring up the window in which you can add/delete/move items on the list.

34 Demonstration 3: Configuring an Enum Place an enum on the front panel
Right-click on the enum and select Edit Items… Add Start, Stop, Read to the listing (0= Start, 1=Stop, 2=Read) Move Stop to last entry (0= Start, 1=Read, 2=Stop) Close the Properties Window and show the entries on the front panel Change the enum control to a constant and show the entries as a constant - Explain that the value chosen/showing is the value of that enum Introduction to LabVIEW Hands-On 24 ni.com

35 Customizing Controls LabVIEW ships with multiple palettes of controls available to you. However, you may want to customize them or create your own Depending on you application, you may want customize a control. For example, if your VI will be running on a touch screen, you might want to make the increment/decrement buttons on a numeric control much larger. If you creating something that will be presented or sold, you may want to use a custom color scheme and make the control a bit “flashier” like the gauge in this slide customized with an NI theme. Not only do you have the ability to customize controls cosmetically, but you can save them for use again later. Furthermore, there is a way to link each instance of a custom control to the saved file so if you want to change something down the road, you don’t have to edit each and every one. Standard LabVIEW Gauge Customized LabVIEW Gauge

36 Creating Custom Controls
How to create: Right click on the control; select Advanced >> Customize The Control Edit window will appear. In order to create a custom control or type def, you must right-click on an object on the FRONT PANEL. Then go to Advanced >> Customize… to pull up the Control Editor window. In the Control Editor Window you can add/remove things from a cluster, edit the items listed in an enum, change the color of an LED, move increment/decrement arrows to the top/bottom of digital display instead of to the side, and much more! The tweezer button next to the drop-down takes you to low level editing where you can pull apart the layers that create the object (ie, shadow, foreground, background, etc) Edit Mode Customize Mode (low-level changes)

37 Saving Custom Controls
Three options: Custom Control Type Definition Strict Type Definition All 3 options create a *.ctl file. Once you save the custom control it takes on the name of the option you chose. When you are ready to save your customization, you have three options, which are displayed in the drop down box on the toolbar: -Custom Control -Type Definition -Strict Type Definition All 3 options create a *.ctl file, but behave differently. The next slide explains the difference between these options, as they are very useful when used properly. Depending on the option you choose, the file created will typically be referred to as that option. For example, if you save as a type definition, it is common to refer to that file as a type definition (or type def, for short).

38 Custom Controls & Type Definitions
No connection between the one you saved and the instance in the VI Update the file, but the instances are not updated Type Def Connection between the saved file and all instances Forces the data type of each instance to be identical (clusters, enum) Changes made to file will populate throughout each instance Strict Type Def Connection between saved file and all instances Forces everything about an instance to be identical to the strict type definition, except: label description default value A custom control, type def or strict type def all create a *.ctl file, which stores the customizations you make to a front panel control. The thing that is special about type defs and strict type defs is that every instance of that control you use on your block diagram is linked to the *.ctl and will update if you make changes to the file. The purpose of a *.ctl file saved as a Custom Control is to prevent you from going through the potentially lengthy process of creating it again- the file provides easy access to create another. The purpose of a type def is to make sure that the data type is consistent (including the item list for an enum- which is particularly helpful when building state machines) for each instance. Strict typ defs are just that, strict. Everything must be the same (most noticeable is cosmetic changes –size of LED, color, etc). To be able to tell them apart, the label should be different (labels should always be unique and descriptive). Descriptions can be different because they might serve slightly different purposes (LED indicating different warnings in a system – you would want to be able to describe which LED represents which process more than just using the label). Last, the default value can be different. Everything else is the same. *.ctl *.ctl *.ctl

39 Creating and Saving a Type Definition
Demonstration: Creating and Saving a Type Definition Introduction to LabVIEW Hands-On 24 ni.com

40 Homework: Create a new VI from the instructions located at ni.com/mst
CLAD Extra Questions (Put the answers in the message) HW to: Introduction to LabVIEW Hands-On 24 ni.com


Download ppt "Welcome! Workshop 2 of 7."

Similar presentations


Ads by Google