How to get Voltage value from analog input ???

Supporting Visual Studio on Windows
Post Reply
Biggermens
Phidgetsian
Posts: 10
Joined: Sun Aug 02, 2009 9:55 pm
Contact:

How to get Voltage value from analog input ???

Post by Biggermens »

Hello everyone

I been playing around with my 8/8/8 interface
Been trying to get voltage from all 8 analog inputs
I got one working but all others are displaying the same
I am not very good at this vb stuff but i have fun :)

Code: Select all


Imports Phidget22
Imports Phidget22.Events


Public Class Form1
    Dim WithEvents device As Phidget22.VoltageInput




    Public Sub New()

        Phidget22.Phidget.InvokeEventCallbacks = True
        InitializeComponent()
    End Sub

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

        device = New Phidget22.VoltageInput()
        device.Open()
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        If device.Attached Then
            device.Close()
        End If
    End Sub

    Private Sub device_VoltageChange0(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device.VoltageChange

        device.Channel = "0"
        TextBox0.Text = device.Voltage.ToString() + " "
    End Sub

    Private Sub device_VoltageChange1(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device.VoltageChange

        device.Channel = "1"
        TextBox1.Text = device.Voltage.ToString() + " "
    End Sub

    Private Sub device_VoltageChange2(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device.VoltageChange

        device.Channel = "2"
        TextBox2.Text = device.Voltage.ToString() + " "
    End Sub

    Private Sub device_VoltageChange3(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device.VoltageChange

        device.Channel = "3"
        TextBox3.Text = device.Voltage.ToString() + " "
    End Sub

End Class




User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: How to get Voltage value from analog input ???

Post by mparadis »

You need to make a different Phidget22.VoltageInput() object for each channel you want to use (eg. device0, device1, device2) and then for the change handler functions, put those different objects after the "Handles".

Something like this: (I haven't tested it but it should work)

Code: Select all


Imports Phidget22
Imports Phidget22.Events


Public Class Form1
    Dim WithEvents device As Phidget22.VoltageInput

    Public Sub New()

        Phidget22.Phidget.InvokeEventCallbacks = True
        InitializeComponent()
    End Sub

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

        device0 = New Phidget22.VoltageInput()
        device0.Open()

        device1 = New Phidget22.VoltageInput()
        device1.Open()

        device2 = New Phidget22.VoltageInput()
        device2.Open()

        device3 = New Phidget22.VoltageInput()
        device3.Open()
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        If device.Attached Then
            device.Close()
        End If
    End Sub

    Private Sub device_VoltageChange0(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device0.VoltageChange

        TextBox0.Text = device0.Voltage.ToString() + " "
    End Sub

    Private Sub device_VoltageChange1(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device1.VoltageChange

        TextBox1.Text = device1.Voltage.ToString() + " "
    End Sub

    Private Sub device_VoltageChange2(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device2.VoltageChange

        TextBox2.Text = device2.Voltage.ToString() + " "
    End Sub

    Private Sub device_VoltageChange3(ByVal sender As Object, ByVal e As Phidget22.Events.VoltageInputVoltageChangeEventArgs) Handles device3.VoltageChange

        TextBox3.Text = device3.Voltage.ToString() + " "
    End Sub

End Class
You also don't need to set the channel inside the event handlers. Channel is only checked when open is called; changing it afterward won't do anything unless you close and reopen the same handle.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests