VB Form to read ADC results
Posted: Sat Aug 29, 2009 12:46 pm
Below code is a VB sample to read 8 ADC channels with ADC_Read
Code: Select all
Public Class Form1
' Read all the 8 ADC channels 3 times i.e 8*3=24
Private Const SamplesToRead As Integer = 24
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dev As New Sub20
Dim Data(SamplesToRead) As Integer
Dim Mux(SamplesToRead) As Integer
Dim i As Integer
' Open SUB-20 device
If Not dev.Open(0) Then
MsgBox(dev.GetStrError(dev.GetLastError()))
Exit Sub
End If
Do
' Enable the ADC and set Vref=Vcc
If Not dev.ADC_SetConfig(Xdimax.Adc.Enable Or Xdimax.Adc.RefVcc) Then
Exit Do
End If
' Setup the Mux to read all the channels, i.e Ch0,Ch1,Ch2...Ch7,Ch0,Ch1.. etc
For i = 0 To Data.GetLength(0) - 1
Mux(i) = i Mod 8
Next
' Read samples
If Not dev.ADC_Read(Data, Mux) Then
Exit Do
End If
Loop While False
If dev.GetLastError() > 0 Then
MsgBox(dev.GetStrError(dev.GetLastError()))
End If
' Close SUB-20 device
dev.Close()
End SUB
End Class