• Aucun résultat trouvé

Low-Level File I/O VI and Functions

Dans le document PDF Generation Test Course (Page 94-99)

Use the following low-level File I/O VI and functions to perform basic le I/O operations:

Open/Create/Replace File - Opens an existing le, creates a new le, or replaces an existing le, programmatically or interactively using a le dialog box. You can optionally specify a dialog prompt, default le name, start path, or lter pattern. If le path is empty, the VI displays a dialog box from which you can select a le.

Read File - Reads data from an open le specied by refnum and returns it in data. Reading begins at the current le mark or a location specied by pos mode and pos oset. How the data is read depends on the format of the specied le.

Write File - Writes data to an open le specied by refnum. Writing begins at a location specied by pos mode and pos oset for byte stream les and at the end of the le for datalog les. data, header, and the format of the specied le determine the amount of data written.

Close File - Closes an open le specied by refnum and returns the path to the le associated with the refnum. Error I/O operates uniquely in this function, which closes regardless of whether an error occurred in a preceding operation. This ensures that les are closed correctly.

2.3.1 Error Handling

The low-level File I/O VIs and functions return error information. Wire the error information from the beginning of the VI to the end. Include an error handler VI, such as the Simple Error Handler (p. 86) VI located on the Time & Dialog palette, at the end of the VI to determine if the VI ran without errors. Use the error in and error out clusters in each VI you use or build to pass the error information through the VI.

2.3.2 Saving Data in a New or Existing File

You can write any data type to a le you open or create with the File I/O VIs and functions. If other users or applications need to access the le, write string data in ASCII format to the le. Refer to the LabVIEW Basics II: Development Course Manual for more information about writing LabVIEW datalog or binary les.

You can access les either programmatically or interactively through a le dialog box. To access a le through a dialog box, do not wire file path in the Open/Create/Replace File VI. However, you can save time by programmatically wiring the default lename and path to the VI. Table 2.1 describes how pathnames are organized.

6This content is available online at <http://legacy.cnx.org/content/m12258/1.1/>.

Platform Pathname

Windows Consists of the drive name, a colon,

backslash-separated directory names, and the lename. For example, c:\testdata\test1.dat is the pathname to a le named test1.dat in the testdata direc-tory.

UNIX UNIX Consists of forward slash-separated

direc-tory names and the lename. For example, /home/testdata/test1.dat is the pathname to a le named test1.dat in the testdata directory in the /home directory. Filenames and pathnames are case sensitive.

Mac OS Consists of the volume name (the name of

the disk), a colon, colon-separated folder names, and the lename. For example, Hard Disk:testdata:test1.dat is the pathname to a le named test1.dat in a folder named testdata on a disk named Hard Disk.

Table 2.1

The block diagram shown in Figure 2.7 shows how to write string data to a le while programmatically wiring the lename and pathname. If the le already exists, it is replaced; otherwise a new le is created.

Figure 2.7

The Open/Create/Replace File VI opens the le test1.dat. The VI also generates a refnum and an error cluster.

When you open a le, device, or network connection, LabVIEW creates a refnum associated with that le, device, or network connection. All operations you perform on open les, devices, or network connections use refnums to identify each object.

The error cluster and refnum pass in sequence from one node to the next. Because a node cannot execute until it receives all its inputs, passing these two parameters forces the nodes to run in order and creates a data dependency. The Open/Create/Replace File VI passes the refnum and error cluster to the Write File function, which writes the data to disk. When the Write File function nishes execution, it passes the refnum and error cluster to the Close File function, which closes the le. The Simple Error Handler VI examines the error cluster and displays a dialog box if an error occurred. If an error occurs in one node, subsequent nodes do not execute, and the VI passes the error cluster to the Simple Error Handler VI.

Chapter 3

Equation Breaking

3.1 Classic Fourier Series

1

The classic Fourier series as derived originally expressed a periodic signal (periodT) in terms of harmonically related sines and cosines. The complex Fourier series and the sine-cosine series are identical, each representing a signal's spectrum. The Fourier coecients, ak andbk, express the real and imaginary parts respectively of the spectrum while the coecients ck of the complex Fourier series express the spectrum as a magnitude and phase. Equating the classic Fourier series (3.1) to the complex Fourier series (3.10), an extra factor of two and complex conjugate become necessary to relate the Fourier coecients in each.

ck= 1

2(ak−ibk)

Exercise 3.1.1 (Solution on p. 110.)

Derive this relationship between the coecients of the two Fourier series.

Just as with the complex Fourier series, we can nd the Fourier coecients using the orthogonality proper-ties of sinusoids. Note that the cosine and sine of harmonically related frequencies, even the same frequency, are orthogonal.

1This content is available online at <http://legacy.cnx.org/content/m0039/2.24/>.

Available for free at Connexions <http://legacy.cnx.org/content/col10278/1.5>

These orthogonality relations follow from the following important trigonometric identities.

sin (α) sin (β) = 12(cos (α−β)−cos (α+β)) cos (α) cos (β) =12(cos (α+β) + cos (α−β)) sin (α) cos (β) =12(sin (α+β) + sin (α−β))

(3.3)

These identities allow you to substitute a sum of sines and/or cosines for a product of them. Each term in the sum can be integrated by noticing one of two important properties of sinusoids.

• The integral of a sinusoid over an integer number of periods equals zero.

• The integral of the square of a unit-amplitude sinusoid over a periodT equals T2.

To use these, let's, for example, multiply the Fourier series for a signal by the cosine of thelthharmonic cos 2πltT and integrate. The idea is that, because integration is linear, the integration will sift out all but the term involvingal.

R

T

The rst and third terms are zero; in the second, the only non-zero term in the sum results when the indices k and l are equal (but not zero), in which case we obtain al2T. If k = 0 = l, we obtain a0T.

All of the Fourier coecients can be found similarly.

a0=T1RT

Exercise 3.1.2 (Solution on p. 110.)

The expression fora0 is referred to as the average value ofs(t). Why?

Exercise 3.1.3 (Solution on p. 110.)

What is the Fourier series for a unit-amplitude square wave?

Example 3.1

Let's nd the Fourier series representation for the half-wave rectied sinusoid.

s(t) =

Begin with the sine terms in the series; to ndbk we must calculate the integral bk= 2

Using our trigonometric identities turns our integral of a product of sinusoids into a sum of integrals of individual sinusoids, which are much easier to evaluate.

RT2

Thus,

b1= 1 2 b2=b3=· · ·= 0

On to the cosine terms. The average value, which corresponds toa0, equals π1. The remainder of the cosine coecients are easy to nd, but yield the complicated result

ak =

Thus, the Fourier series for the half-wave rectied sinusoid has non-zero terms for the average, the fundamental, and the even harmonics.

Dans le document PDF Generation Test Course (Page 94-99)