• No results found

Hands-On: Introduction to Object-Oriented Programming in LabVIEW

N/A
N/A
Protected

Academic year: 2021

Share "Hands-On: Introduction to Object-Oriented Programming in LabVIEW"

Copied!
10
0
0

Loading.... (view fulltext now)

Full text

(1)

Hands-On:

Introduction to

Object-Oriented

Programming in

LabVIEW

Please do not remove this manual.

You will be sent an email which will enable you to

download the presentations and an on-line version of this

manual – Thank you!

Version 13.11 1 Hr

uk.ni.com

ireland.ni.com

(2)

Hardware Requirements:-

None Required

Software Requirements:-

(3)

Object Oriented Programming Hands On

1. Launch LabVIEW from Start>>All Programs>> National

Instruments>> LabVIEW 20XX.

2. On the splash-screen, click on Create Project to create a new project.

3. Navigate to Hands On in the left side of the window, select the LabVIEW category

and double-click the OOP Hands On as shown below.

4. Navigate to LabVIEW and a window will prompt you to configure the new project as shown below. Save it to a folder of your choice.

(4)

Exercise 1

Concept – The aim of this exercise is to add a message popup to a base VI to show dynamic dispatch.

1. Open the OOP Hands On Project in the Exercises folder.

2. Expand the Classes virtual folder and then the Message Child Classes virtual folder. 3. Right click on the Message Child Classes virtual folder and select New>>Class 4. Change the name to Popup

5. Click OK

6. Double Click the Popup.ctl to open it. Drop a String control into the Cluster of Private Class Data. Re-label this to “Message String”.

(5)

7. Close the Popup.ctl and click save. Save the Popup.lvclass file in the exercise1 folder

8. Right click Popup.lvclass in your project and select Properties

9. Then select Inheritance, and click the button Change Inheritance

10. Select Message.lvclass, and click Inherit From Selected and then click OK

11. Now we must create the Accessor Methods for the data in the class.

12. Right click Popup.lvclass and select New>>VI for Data Member Access. 13. Change the Access mode to Read and Write and ensure that the Make available

through Property Nodes and Create dynamic accessor options are selected as

shown below. Click on Create.

14. A Write Message String and Read Message String VI should be created for you, Close these and save to the folder Exercise 1

(6)

15. Right click Popup.lvclass in the project and select New>>VI for Override , then click OK (There is only one method to select, the Execute Method)

16. Go to the block diagram of the created VI. Delete the Call Parent Method VI and then use Ctrl B to delete the broken wires

17. Create more space in the centre of the block diagram and place a case structure. You

can do this by holding Ctrl, left clicking the mouse and dragging an area on the screen.

18. Wire it as shown below

19. Return to the No Error case. Drag a Read Message String in from your project and wire the Error lines and the Popup class wires through it.

(7)

20. Add a One Button Dialog from the functions palette, Programming>>Dialog &

User Interface>>One Button Dialog, then wire the Message String from the Read

Message String VI to the message input of the One Button Dialog VI.

21. Close the VI and save it in the Exercise 1 folder. Do NOT change the name of the VI. 22. Open the OOP Advanced with Commands VI from the Project Explorer. We will

call your new method from here.

23. Create a new Boolean button from the controls palette System>>Boolean>>System

Button. (This will keep the style of the Front Panel). Change the label to “Display

Message”.

24. Also create a string control. System>>String and Path>>System String. Change the label to “Message String”.

25. Switch to the Block Diagram. Navigate the Event Structure to “Frequency”:Mouse Up 26. Right click and Duplicate Event Case. Select “Display Message” and

(8)

27. Delete the control “Frequency 2”, the Write Frequency Message VI and the class

constant.

28. Drag Popup.lvclass and Write Message String.vi from the project into the event case. Move the “Message String” control into the case as well.

29. Wire the class constant to the “Write Message String” VI and then into the “Enqueue Element” VI. Wire the “Message String” control to the “Message String” input of the “Write Message String” VI.

30. Switch to the front panel and save then Run the VI. Enter a message and click the “Display Message” button. Your message will appear. If you Generate a signal, you must move the Frequency dial first to send the message.

Exercise 2

Concept – The aim of this exercise is to add a class to turn our function generator into an arbitrary waveform generator by loading in a waveform from a selection on disk. Add functionality with no architecture change.

1. Open the “OOP Advanced with Commands and Factory” VI from the project. Run this and experiment with the drop down box to load the different classes from disk and execute their methods. Note the options in the drop down box.

2. Stop the VI and close it.

3. In the project navigate to Classes>>Generation Class>>Generate Child Classes 4. Right click on “Generate Child Classes” and go to New>>Class

(9)

5. Name the class “Gen Arb” and click OK

6. Right click on Gen Arb.lvclass in the project and navigate to properties and then Inheritance.

7. Click Change Inheritance.

8. Select Generate.lvclass and then Inherit from Selected, then OK

9. Right click on Gen Arb.lvclass in the project and navigate to VI for Override... 10. Click OK. The only method available should be Generate.vi

11. Go to the block diagram of the created VI. Delete the Call Parent Method VI and then use Ctrl B to delete the broken wires.

12. Create more space in the centre of the block diagram and place a case structure. 13. Wire it as shown below

(10)

15. Go to Express>>Input>>File Dialog and drop this into the No Error case. Just click OK to the Dialog that pops up.

16. Drop down a Read From XML File. Programming>>File I/O>>XML>>LabVIEW

Schema>>Read from XML File. Select the String option in the polymorphic drop

down.

17. Drop down an Unflatten from XML VI. Programming>>File

I/O>>XML>>LabVIEW Schema>>Unflatten from XML.

18. Drop down a Waveform constant. Programming>>Waveform>>Analog Waveform>>Waveform Constant.

19. In the project navigate to Advanced Waveform.lvclass and then Waveform. Expand this and then drag in a Write Waveform method. Add an Enqueue Element VI from

Programming>>Synchronization>>Queue Operations>> Enqueue Element.

20.

a. Wire the Selected path of the File Dialog to the XML File Path of the Read from XML File.

b. Wire from XML Elements output of this VI to the xml string input of the Unflatten from XML VI.

c. Wire the waveform constant to the Type input of this VI.

d. Wire from the value of the Unflatten from XML VI to the waveform input of the Write Waveform VI.

e. Wire the Advanced Waveform class through the Write Wavefrom VI. Wire the Message Queue through the Enqueue Element VI.

f. Connect the Error Out of the Write Waveform VI to the Error In of the Enqueue Element VI.

g. In the project navigate to Message Child Classes. Drag the Display Message.lvclass into the VI.

References

Related documents

Attendees to conferences are decision makers and recognize that your level of support translates into increased NSTA services and programs provided to all science educators.

When you compose a new message, before you send the message, click on the Options tab, and, on the More Options Group, click Save Sent Item To > Other Folder.. Select the

- Right click the Hello class again to select Open Specification - The window called Class Specification for Hello is then displayed; change the attribute name to message; select

ƒ To create a filter, right click on any subsystem and select New -> xxx – Objects -> New -> Library Filter, Object Filter, Member Filter. – Commands -> New ->

Hasil analisis pada Tabel 5 diketahui bahwa serangga yang diperoleh pada tiga tipe tegakan mangrove mempunyai keanekaragaman jenis yang berbeda.. Jumlah individu jenis

3) Click on New x Folder 4) Name your folder Folder 1. 5) To change the folder name, right click on the folder name and left click on rename. Rename your folder to My First

(1) Select Menu > Settings > Application Settings > Messaging Settings > Multimedia Message > Multimedia Message Profiles > Options > New. (4) Highlight

Understanding that each situation is unique and that there is no silver bullet solution, Siemens created its own proprietary modeling and simulation environment from which to