14
Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Embed Size (px)

Citation preview

Page 1: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing

Tim Mewes

4. LabVIEW - Advanced

Page 2: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 2

4.1 String data type

• String is the data type that represents text• Strings can be concatenated • Numbers can be converted to strings

(Number to Exponential String function)

• Strings can be converted to numbers(Fractional/Exponential String to number function)

• Strings can be manipulated in many wayssee the “String” Subpalette on the Block diagram for details

Page 3: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 3

4.2 Clusters• A cluster is a data structure that groups data together• In contrast to arrays the elements grouped together in a cluster can have different types

• Clusters can be created on the front panel using the cluster object on the “Array, Matrix & Cluster Subpalette

• This creates an empty cluster container on the front panel

• Simply drop the elements you want to group together in this container

• You can not mix controls and indicators within a cluster!!!• Name your clusters!

Page 4: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 4

4.2 Clusters• If you use clusters in SubVIs you can connect an entire cluster to one terminal of the connector pane

• Group related controls or indicators together

• Use the unbundle function to access the individual elements of a cluster

Unbundle

Unbundle by name

Keep your VIs readable – use Unbundle by name!

Page 5: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 5

4.2 Clusters• Use the bundle function to bundle elements together

• Use the bundle by name function to replace individual elements of an existing cluster

Page 6: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 6

4.3 Event-driven programming

• Allows your VI to react on the user’s interaction with objects on the front panel

• Every action the user performs causes an “event”

- moving the mouse in the VI window “Mouse enter” event- moving the mouse out of the window “Mouse leave” event- changing a value of a control “Value change” event

• In event-driven programming the VI waits for an event to occur• Then responds to those events and • then returns to waiting for the next event (sleep)

• The possibility to sleep between events frees up processor time for other applications

Page 7: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 7

4.3.1 The event structure

1. Place a while loop on the block diagram

2. Place the event structure inside the loop

3. Right-click on the border of the event structure and select “Add Event Case”

4. In the Edit Events menu select “Controls/stop” as the event source and “Value Change” as the event

Page 8: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 8

4.3.1 The event structure

5. Place the Stop button inside the new event case – this ensures that the stop button works as expected.

• Other buttons:

1. Create the button and place it inside the While-Loop

2. Right-click on the border of the event structure and select “Add Event Case”

3. In the Edit Events menu select the control as the event source and “Value Change” as the event

Place the code/SubVIs to be executed when the button is pressed

here

Page 9: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 9

4.3.2 The Timeout event

1. Wire an integer value to the Timeout terminal at the top left edge of the event structure

2. The Timeout event will occur whenever the event structure waited for specified time in milliseconds

This allows to periodically execute thecode placed in the Timeout event case,while the user still can interact with theVI.

Place the code/SubVIs to be executed periodically

here.

Works good for tasks that are not time critical and take less than the specifiedtimeout time to complete.

Page 10: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 10

4.4 Local Variables

• Allow to read from and write to front panel objects

• In particular: allow to write to a control

• Only use them if really necessary as they– Make code more difficult to read– Hide the data flow– Use more memory (each local variable creates a copy)– Can lead to unexpected results

• Create local variables by right-clicking the object

Page 11: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 11

4.5 Sequence structure

• Problem which one of the two SubVIs will execute first?

Flat sequence structure Stacked sequence structure

• Solution: Use sequence structure Executes code frame after frame

Page 12: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 12

4.5 Sequence structure

• Avoid using sequence structures if possible:it prevents parallel execution of code

• Solution for previous case without sequence structure:

Passing information about possible errors from one SubVI to the next ensures sequential execution and allows the second SubVI to perform the appropriate action

Page 13: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 13

4.6 Property node

• Property nodes can be used to get and set properties of VIs and front panel objects while the VI is running

Page 14: Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced

Digital Electronics and Computer Interfacing 14

4.6 Property node

• Many properties available – to be read by default

• If necessary one can change this by right-clicking in the top part of the icon and selecting “Change All to Write”

• Left-clicking in the lower part of the icon allows to select a specific property to read or write

Resize and addingmore properties