The following information is for the EMANT300

Create an Instrument User Interface

Objective

  • Use third party controls

  • Use Emant300 component

In this final exercise, you will build a computer based light logger with a modern GUI.

  1. Select File -> New Project

  2. Select Visual Visual Basic Projects and click on Windows Application

  3. Call the project name WinLogger. Store your projects in the EmantVB2005 folder. Click on the OK button to create the project.

  4. Add the AnalogMeter, LED, LineGraph & NumericUpDown controls shown.

  5. From the Toolbox and General tab, click and drag the AnalogMeter to place it on the form.

  6. On its Properties window, set the MaximumValue to 500.

  7. Click and drag the LineGraph to place it on the form.

  8. On its Properties window, set the YMax to 500.

  9. Click and drag the LED to place it on the form.

  10. Add the NumericUpDown control you learnt from the previous exercise. On its Properties window, set the Maximum to 500

  11. Add the Label control you learnt from the previous exercise.

  12. Now add the two components Timer and Emant300. Click on Timer. While holding on the mouse left button, drag the Timer to the form and release the left button to get the component placed as shown in the figure above. You must release the component on the form. The Timer component, as a non-visual component, resides in a component tray which is at the bottom of the form designer. Repeat for the Emant300 component. The Form should look as below.



  1. If you select the emant3001 object (an instance of the Emant300 component), you can see its properties. If you are using the simulator, then you should change its Simulation property to true.

  2. Double click on Timer1 component will cause its event handler to be created. Add the highlighted code below to the timer1_Tick event handler.

Program 15.1 Modify Timer Event Handler

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick

Dim volt, lux As Double

volt = Emant3001.ReadAnalog(Emant.Emant300.AIN.AIN0, Emant.Emant300.AIN.COM)
lux = 1333 * volt
AnalogMeter1.Value = lux
LineGraph1.Value = lux
Led1.Value = lux > NumericUpDown1.Value
Label1.Text = lux.ToString("0.0")

End Sub

In exercise 5, we learnt that we need to use the Open method to connect to the DAQ module and the Close method to close the DAQ connection before exiting the program. The Form Class has two events that you can use to automate the process. When the Form loads, there is a Form.Load event generated. Likewise when the user closes the Form, a Form.Closing is generated.

  1. To create the Form.Load event,

  • click on the Code tab to select the Code View

  • select Form1Events from the Class Name drop-down menu.

  • from the Method Name drop-down menu, select the Load event.

  • Add the highlighted code below to the Form.Load event handler created.



Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Emant3001.Open()
Timer1.Enabled = True

End Sub

Repeat the above steps for the Form Closing Event. Add the highlighted code.

Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

Timer1.Enabled = False
Emant3001.Close()

End Sub

Assigning Values to the Controls

AnalogMeter1.Value = lux

assign the lux value to the AnalogMeter1

LineGraph1.Value = lux

assign the lux value to the LineGraph1

Led1.Value = lux > NumericUpDown1.Value

the Led1 state depends on whether the measured lux value exceeds the NumericUpDown setting

Label1.Text = lux.ToString("0.0")

In Exercise 4, you learnt about the Convert class in the System namespace. In this example, we convert a double to a string. The optional format “0.0” instructs the method to display the string with one decimal place.

  1. Click on Debug-> Start to run your light measurement program. Cover or shine on the photodiode to observe the change in light intensity measured and how it is displayed on your interface. Modify the NumericUpDown value and observe the change in LED state.

  2. Click on to return to the development environment.

  3. Save your project by clicking on File -> Save All.

End of Exercise 15

DAQ & Visual Basic Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37