UltimaSerial How to use ActiveX and Variant in VB.NET
USB-based DI-148, DI-158, DI-710, DI-715B & DI-718B are now supported by Ultimaserial

158u.jpg (11869 bytes)

Let UltimaSerial unleash the power of your Windaq Starter kit!

 

UltimaWaterfall

UltimaWaterfall

 

FFT1024

FFT1024

 

XChart

 

Ultimaserial Classroom

Lessons on how to use UltimaSerial

 

download.jpg (1018 bytes) Downloads

 

Registration.jpg (4365 bytes)

info@ultimaserial.com

 

 

The following is a step-by-step lesson on how to use ActiveX and Variant in VB.NET

In this lession, we will use Ultimaserial ActiveX to develop a data acquisition application with DATAQ's Starter kit. 

Click here to download a VB.NET sample project (Ultimaserial rev 3 based) . You can also use VisualBASIC tutorial as reference

If you google using the terms of "use variant vb.net", you will probably find the statement "VB.NET no longer supports the Variant and Currency data types.". It sounds scary, doesn't it? Without variant, how can we get the data from UltimaSerial?! Do I have to use GetDataPt to retrieve a single data point at a time? (Yes, you could, if you don't want to deal with variant at all)

Well, Microsoft may try to drop the variant support in VB.NET, but it also keeps a back door opened for anyone who wants to use it.

To access the data returned by GetData, instead of using variant, declare it as short directly.

In the following example, we have one form, two buttons, start and stop, and UltimaSerial control.

Please pay attention to the area that is highlighted with red. sections highlighted with blue are added to the project, green area are generated by VB.NET

Public Class Form1
Inherits System.Windows.Forms.Form

Dim v(,) As Short
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents AxUltimaSerial1 As AxULTIMASERIALLib.AxUltimaSerial
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.AxUltimaSerial1 = New AxULTIMASERIALLib.AxUltimaSerial()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
CType(Me.AxUltimaSerial1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AxUltimaSerial1
'
Me.AxUltimaSerial1.Enabled = True
Me.AxUltimaSerial1.Location = New System.Drawing.Point(104, 24)
Me.AxUltimaSerial1.Name = "AxUltimaSerial1"
Me.AxUltimaSerial1.OcxState = CType(resources.GetObject("AxUltimaSerial1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxUltimaSerial1.Size = New System.Drawing.Size(100, 50)
Me.AxUltimaSerial1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 168)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 48)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Start"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(168, 168)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 48)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Stop"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.AxUltimaSerial1})
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.AxUltimaSerial1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region



Private Sub AxUltimaSerial1_NewData(ByVal sender As Object, ByVal e As AxULTIMASERIALLib._DUltimaSerialEvents_NewDataEvent) Handles AxUltimaSerial1.NewData
v = AxUltimaSerial1.GetData()
' the data can be accessed as v(chn, pt),
' where chn=0 for the first channel,
' pt =0 for the first pts

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxUltimaSerial1.CommPort = ULTIMASERIALLib.enumComPort.COM2
AxUltimaSerial1.Device = ULTIMASERIALLib.enumDeviceType.DI194
AxUltimaSerial1.ChannelCount = 1
AxUltimaSerial1.SampleRate = 20
AxUltimaSerial1.EventLevel = 20
AxUltimaSerial1.Start()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
AxUltimaSerial1.Stop()
End Sub
End Class

Last update: 10/05/07

Copyright: 2000-2005  www.UltimaSerial.com