+ All Categories
Home > Documents > NOTAS LABVIEW CORE 2

NOTAS LABVIEW CORE 2

Date post: 13-May-2023
Category:
Upload: independent
View: 0 times
Download: 0 times
Share this document with a friend
22
LABVIEW CORE 2 Asynchronous Communication Reasons to use parallel loops: Execute tasks simultaneously Execute tasks at different rates
Transcript

LABVIEW CORE 2

Asynchronous Communication

Reasons to use parallel loops:

• Execute tasks simultaneously

• Execute tasks at different rates

Other ways of communicating between multiple loops:

• Variables (already seen)

• Notifiers (covered in LabVIEW Core 3)

• User Events (covered in LabVIEW Core 3)

• Queues (covered in this course)

Queues

• Are used for communicating data between parallel loops.

• Store multiple pieces of data (i.e. buffer data).

• Work in a FIFO (first in, first out) manner by default.

• Can hold data of any type.

Queue Operations

What is the data type associated with the Queue?

This is specified by the Obtain Queue function.

What function determines the number of elements in the queue?

Get Queue Status.

What Are Events?

An event is an asynchronous notification that something has occurred. Asynchronous describes a function that begins an operation and returns prior to the completion or termination of the operation.

Events can originate from the user interface, external I/O, or other parts of the program. User interface events include mouse clicks, key presses, etc. External I/O events include hardware timers or triggers that signal when data acquisitioncompletes or when an error condition occurs.

• Event-Driven Programming — Method of programming where the program waits for an event to occur before executingone or more functions

An Event structure works like a Case structure with a built-in Wait on Notification function.

Use an Event structure to handle user-interface (static) events such as:

• Pressing a button on the mouse.

• Pressing a key on the keyboard.

• Changing the value of a numeric control.

In general, place Event structures inside While Loops.

• Event structures handle exactly one event per iteration of the While Loop.

• Event structures sleep when no events occur.

• How many times did the loop run with polling?

• Should be a large number, such as in the thousands.

• How many times did the loop run when you changed the VI to use an Event structure?

• Should be a number in the 10s or 20s as the loop only iterated when an event occurred.

1. Which of the following buffer data?a. Queuesb. Eventsc. Local Variables

3. Which of the following are valid data types for queues?a. Stringb. Numericc. Enumd. Array of Booleanse. Cluster of a String and a Numeric

4. The Event structure handles only one event each time it executes.a. Trueb. False

Why Use Design Patterns?

• They have proven themselves useful for developing software.

• You don’t have to start a program from scratch.• They make it easier for others to read and modify

your code.

• Design Patterns – Code implementations and techniques that are solutions to specific problems in software design

General VI Pattern

This pattern has three phases:• Start-up• Main application• Shut-down

State Machine Pattern

Usually has a start-up and shut-down state, but also containsother states.

Event-Based State Machine

• Combines event programming with a State Machine design.

• Includes a “Wait on Event” case to processes user-interface events.

Multiple Loop Design Patterns

In this class we will go into depth covering the Producer/Consumer (Events) design pattern. Other multi-loop design patterns include the Master/Slave andQueued Message Handler design patterns.

Producer/Consumer Design Patterns

The producer/consumer design pattern separates tasks that produce and consume data at different rates. The parallel loops in the producer/consumer design pattern are separated into two categories, those that produce data and those that consume this data. Data queues communicate data among the loops and buffer data among the producer and consumer loops. A buffer is a memory device that stores temporary data between two devices or multiple loops.

PRODUCER/CONSUMER Design Pattern (Data)The producer/consumer design pattern (data) enhances datasharing among multiple loops running at different rates.There are two categories of parallel loops in theproducer/consumer design pattern (data)—those that producedata and those that consume the data. Data queues communicatedata among the loops.

The data type transferred in Figure 2-8 is a string. A stringis not the most efficient data type for passing data indesign patterns. A more efficient data type for passing datain design patterns is a cluster consisting of state and dataelements

Producer/Consumer Design Pattern (Events)One of the most versatile and flexible design patternscombines the producer/consumer and user interface eventhandler design patterns. AVI built using theproducer/consumer design pattern (events) responds to theuser interface asynchronously, allowing the user interface tocontinuously respond to the user. The consumer loop of thispattern responds as events occur, similar to the consumerloop of the producer/consumer design pattern (data).The producer/consumer design pattern (events) uses the sameimplementation as the producer/consumer design pattern (data)except the producer loop uses an Event structure to respondto user interface events, as shown in Figure 2-9. The Eventstructure enables continuous response to user interaction.

Error Handler – A VI or code that changes normal flow of program execution when an error occurs

Error handlers can be simple or elaborate. Simple error handlers include:

• Simple Error Handler VI—Displays a dialog box with error information when an error occurs.

• State machine error handler—Transitions the state machine to an error or shutdown state when an erroroccurs.

• I/O error handler—If an I/O operation times out, retry for a certain period of time before reportingan error.

Producer/Consumer Error Handler

• Both producer and consumer loops gracefully stop when an error occurs.

− Producer loops pass error information to consumer loops.

− Consumer loops send stop information to producer loops.

• Transition to a Shutdown case in the consumer loop to execute shutdown code prior to stopping the VI.

• Report error information to the user.

Timing a Design Pattern

Execution Timing• Provides the design pattern with a function that

specifically allows the processor time to complete other tasks.

Software Control Timing• Times a real-world operation to perform within

a set time period.• Controls the frequency at which a loop

executes.

Design patterns where the timing is based on the occurrence of events do not need execution timing

Synchronized timeout allows functionality to be executed at regular intervals in both the consumer and producer loops.

The Get Date/Time In Seconds function returns a timestamp of the current time. This can be used to compare time relative to a previously known time.

LabVIEW also has a Tick Count (ms) function that can also be used to get relative time duration. The Tick Count (ms) is best use for benchmarking code while the Get Date/Time in Seconds is better for applications that need to run indefinitely. This is because the Tick Count (ms) function can wrap around from 2^32 -1 to 0.

SemaphoresSemaphores are synchronization mechanisms specificallydesigned to protect resources andcritical sections of code. You can prevent critical sectionsof code from interrupting each other by enclosing eachbetween an Acquire Semaphore and Release Semaphore VI. Bydefault, a semaphore only allows one task to acquire it at atime. Therefore, after one of the tasks enters a critical

section, the other tasks cannot enter their critical sectionsuntil the first task completes. When done properly, this eliminates the possibility of a racecondition. You can use semaphores to protect criticalsections of code in Figure 2-20. To remove the racecondition, open the semaphore before starting each loop.Within each loop, use the AcquireSemaphore VI just before the critical section and use theRelease Semaphore VI after the critical section. Figure 2-21shows a solution to the race condition using semaphores.

Functional Global VariablesOne way to protect critical sections is to place them insubVIs. You can only call a non-reentrant subVI from onelocation at a time. Therefore, placing critical code in anon-reentrant subVI keeps the code from being interrupted byother processes calling the subVI. Using the functionalglobal variable architecture to protect critical sections isparticularly effective, because shift registers can replaceless protected storage methods like global or single-processshared variables. Functional global variables also encouragethe creation of multi-functional subVIs that handle all tasksassociated with a particular resource.

Functional Global Variable Design Pattern

Up Down Counter VI is an FGV VI that:• Eliminates the read-modify-write race condition for

simultaneous transactions.• Encapsulates methods for resetting, incrementing,

and decrementing.

Functional Global Variable

• Functional Global Variable – A non-reentrant VI that uses uninitialized shift registers to hold global data. The VI often allows for actions to be performed on the data.

Variable Funcional Global - A VI no reentrante que utiliza registros de desplazamiento no inicializado para almacenar los datos globales. El VI a menudo permite a las acciones a realizar sobre los datos

1. Which of the following are reasons for using a multiple loop design pattern?a. Execute multiple tasks concurrentlyb. Execute different states in a state machinec. Execute tasks at different ratesd. Execute start up code, main loop, and shutdown code2. Which of the following are examples of error handling code?a. Displays a dialog box used to correct a broken VIb. Generates a user-defined error codec. Displays a dialog box when an error occursd. Transitions a state machine to a shutdown state when an error occurs3. What is the default timeout value of an Event structure?a. 0b. 100 msc. Never time outd. The input value of the Wait (ms) function that exists inthe same loop as the Event structure

Property Nodes can have multiple properties.Properties execute from top to bottom.

A Property Node created from the front panel object or blockdiagram terminal is an implicitly linked Property Node. TheProperty Node is linked to the front panel object.A generic property node with a reference wired to it is anexplicitly linked Property Node.You must use explicitly linked Property Nodes if the PropertyNode will be part of a subVI.

Control References

• A control reference is a reference to a front panelobject.

• Wire control references to generic Property Nodes.

• Pass control references to subVIs.

1. For each of the following items, determine whether they operate on a VI class or a Controlclass.• Format and Precision: Control• Visible: Control• Reinitialize to Default Value: Control• Show Tool Bar: VI2. You have a Numeric control refnum, shown at left, in a subVI. Which control references couldyou wire to the control refnum terminal of the subVI?a. Control reference of a knobb. Control reference of a numeric arrayc. Control reference of a thermometer indicatord. Control reference of an LED

FILE I/O

Use text format files for your data: • To make the data available to other users or

applications.• If disk space and file I/O speed are not

crucial.• If performing random access reads or writes is

unnecessary.• If numeric precision is not important.

Use binary format files for your data:

• When numeric precision is important.• When you need to randomly access stored data .• When efficiency is important.• A specific type of binary file, known as a

Datalog file, is the easiest method forlogging cluster data to a file.

– Datalog files store arrays of clusters ina binary representation.

– The storage format for Datalog files iscomplex, and therefore the data isdifficult to access in any environmentexcept LabVIEW.

Use TDMS files for the following purposes: • To store test or measurement data.• To create a structure for grouping your data.• To store information about your data.• To read and write data at high speeds.• TDMS file format:

– Binary file (.tdms) that contains dataand stores properties about the data.

– Binary index file (.tdms_index) thatprovides consolidated information on allthe attributes and pointers in the TDMSfile.

– TDMS file format is publicly documented.– Can use with TDM Excel Add-in Tool.

3. You need to store data which other engineers will later analyze with Microsoft Excel. Whichfile storage format(s) should you use?a. Tab-delimited ASCII

b. Custom binary formatc. TDMS4. TDMS files store properties at which of the following levels?a. Fileb. Channel Groupc. Channeld. Value


Recommended