UltimaSerial How to use ActiveX in Visual Basic 2008 Express Edition
USB-based DI-148, DI-158, DI-710, DI-715B & DI-718B are now supported by Ultimaserial

Data logger
UltimaSerial

 

Windaq add-ons
Windaq Add-ons

 

Spectrogram
UltimaWaterfall

Ultimaserial XChart
XChart

 

FFT1024
FFT1024

 

Ultimaserial Classroom
Lessons

 

The following is a lesson on how to use ActiveX in Visual Basic 2008 Express Edition, which can be downloaded for free from Microsoft's website.

Note: If you wish to use Visual Basic 2008 Express Edition (VB2008)'s upgrade wizard to upgrade the VB6 examples provided in the installations of Ultimaserial, UltimaWaterfall and XChart, check this out

You may download VB2008 projects for reference

In this lesson, we will use Ultimaserial ActiveX to develop a data acquisition application with DATAQ's Starter kit, here we use DI-158.

  1. Start Visual Basic 2008 Express Edition
  2. Select Create: Project...
  3. From the Visual Studio installed templates, select Windows Forms Application to create a new project
  4. The studio will create Form1.vb for you
  5. Right-click inside the toolbox pane and follow Choose Items...
  6. Select Ultimaserial and XChart under the COM Components tab


     
  7. Add XChart and Ultimaserial to the form
  8. Add two buttons to the form, one call Start, the other Stop
  9. Add four labels (label 1,2,3,4) to display the readings in two different approaches, one via direct access to the data array, the other via calls to AnalogInput()
  10. Double click on both buttons, XChart and Ultimaserial to enter the source editor of Form1.vb
  11. Make sure your code is similar to the following:

    Public Class Form1

    Dim v(,) As Short

    Private Sub AxUltimaSerial1_NewData(ByVal sender As Object, ByVal e As     AxULTIMASERIALLib._DUltimaSerialEvents_NewDataEvent) Handles AxUltimaSerial1.NewData
    v = AxUltimaSerial1.GetData
    AxXChart1.Chart(v)
    Label1.Text = AxUltimaSerial1.AnalogInput(ULTIMASERIALLib.enumAChn.Ch1)
    Label2.Text = AxUltimaSerial1.AnalogInput(ULTIMASERIALLib.enumAChn.Ch2)
    Label3.Text = v(0, 0)
    Label4.Text = v(1, 0)

    End Sub

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
    AxUltimaSerial1.ChannelCount = 2
    AxUltimaSerial1.set_PChannel(0, ULTIMASERIALLib.enumChn.Ch01_SE)
    AxUltimaSerial1.set_PChannel(1, ULTIMASERIALLib.enumChn.Ch02_SE)

    AxUltimaSerial1.Device = ULTIMASERIALLib.enumDeviceType.DI158
    AxUltimaSerial1.CommPort = ULTIMASERIALLib.enumComPort.USB
    AxUltimaSerial1.SampleRate = 100
    AxUltimaSerial1.Start()

    End Sub

    Private Sub StopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopButton.Click
    AxUltimaSerial1.Stop()
    End Sub

    End Class

  12. Run it and it should plot the input waveform on the chart and print readings from the two channels on the text labels.
  13. If you need to access the data returned by GetData, access them directly via v(x,y), where x is the channel index, y is the data index

 

Last update: 07/23/09

Copyright: 2000-2005  www.UltimaSerial.com