sensors.dll with VB.net 2008

Jan 25, 2010 at 8:51 AM

Just wanted to contribute some code because I did not find it somewhere else on the net. This is to access the sensors data with vb.net.
You need to compile the sensors.dll (VC.net) and reference it in your vb.net project first!

 

Imports Sensors

Public Class Gsensor
    Dim mySensor As IGSensor = GSensorFactory.CreateGSensor


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mySensor As IGSensor = GSensorFactory.CreateGSensor()
        Dim vx, vy, vz, vv
        Dim gvector = mySensor.GetGVector()
        Label1.Text = gvector.ToString() & " " & mySensor.Orientation
        vv = gvector.ToString()
        vx = Trim(Mid(vv, 3, InStr(vv, "Y=") - 3))

        vy = Trim(Mid(vv, InStr(vv, "Y=") + 2, InStr(vv, "Z=") - InStr(vv, "Y=") - 3))

        vz = Trim(Mid(vv, InStr(vv, "Z=") + 2, Len(vv) - (InStr(vv, "Z="))))

        Label2.Text = vx
        Label3.Text = vy
        Label4.Text = vz

        tbx.Value = Val(vx)
        tby.Value = Val(vy)
        tbz.Value = Val(vz)

    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        Timer1.Enabled = True
    End Sub

    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        Timer1.Enabled = False
        mySensor.Dispose()
    End Sub
End Class
T.u.b.e.