Example of OnSensorInput()

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Example of OnSensorInput()

Post by rodrigo.seabra »

Hi,

Someone could show an example of use of the method OnSensorInput? I'm trying to implement an application with the SpaceNavigator, however, that while I could only connect to the device. Any interaction I make the same does not result in changes to the vectors of translation and rotation. I think I need to make use of this method to achieve read the details of the device.

Thanks.
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

What language are you using?
I can post VB 2005 project and sample if you wish. It can also b converted to C#
Let me know
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi alexus,

I am using C++ (Visual C++ 2005 Express Edition). Anyway, I would like to see your code... I think that help me very much...

Thanks.
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

ok will post the project in half an hour
Long Range Communications, Inc
If you think it is impossible to be done, please don’t bother those who are already doing it…
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Ok alexus!

Thanks.
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

well greate there is no option to attach the file :(
and my FTP is down... so I will atach as COde rather then project file.
I have lots of junk there since i was experementing on how to controll the menus but in simple way the cordinates are outputed to the text box... wait wanst it a part of SDK?

Code: Select all

Imports SpeechLib
Public Class Form1
    Dim TicValue As Integer = 0
    Dim StepLenght As Integer = 100

    'Speach Settings
    Public WithEvents vox As New SpVoice
    Public RateOfSpeech As Integer = 3
    'Speak Timered Selection Buffer
    Dim SpeakBuffer As String


    ' This delegate enables asynchronous calls for setting
    ' the text property on a TextBox control.
    Delegate Sub SetMotionTextCallback()
    Delegate Sub SetKeyTextCallback(ByVal keyCode As Integer)

    Private WithEvents Sensor As TDxInput.Sensor
    Private WithEvents Keyboard As TDxInput.Keyboard
    Private WithEvents Device As TDxInput.Device

    Public Sub New()

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

        ' Add any initialization after the InitializeComponent() call.
        Device = New TDxInput.Device
        Sensor = Device.Sensor
        Keyboard = Device.Keyboard

        SetMotionTexts()
        SetKeyText(1)

        Device.Connect()

    End Sub

    Private Sub Sensor_SensorInput() Handles Sensor.SensorInput

        Me.SetMotionTexts()

    End Sub


    ' This method demonstrates a pattern for making thread-safe
    ' calls on a Windows Forms control. 
    '
    ' If the calling thread is different from the thread that
    ' created the TextBox control, this method creates a
    ' SetTextCallback and calls itself asynchronously using the
    ' Invoke method.
    '
    ' If the calling thread is the same as the thread that created
    ' the TextBox control, the Text property is set directly. 

    Private Sub SetMotionTexts()
        ' InvokeRequired required compares the thread ID of the
        ' calling thread to the thread ID of the creating thread.
        ' If these threads are different, it returns true.
        If Me.TextBox1.InvokeRequired Then
            Dim d As New SetMotionTextCallback(AddressOf SetMotionTexts)
            Me.Invoke(d)
        Else
            Dim Style1 As String = "f"
            Dim translation As TDxInput.Vector3D
            translation = Sensor.Translation

            Dim rotation As TDxInput.AngleAxis
            rotation = Sensor.Rotation

            Me.TextBox1.Text = Format(translation.X, Style1)
            Me.TextBox2.Text = Format(translation.Y, Style1)
            Me.TextBox3.Text = Format(translation.Z, Style1)

            Me.TextBox6.Text = Format(rotation.X, Style1)
            Me.TextBox5.Text = Format(rotation.Y, Style1)
            Me.TextBox4.Text = Format(rotation.Z, Style1)
            Me.TextBox7.Text = Format(rotation.Angle, Style1)


            'Slide Bar
            'If (translation.Z > 20 And translation.Z <50> 50 And translation.Z <65> 65) Then
            'TrackBar1.Value = TrackBar1.Value - 8
            'End If
            '
            '           If (translation.Z <20> -50) Then
            'TrackBar1.Value = TrackBar1.Value + 1
            'ElseIf (translation.Z <50> -65) Then
            'TrackBar1.Value = TrackBar1.Value + 3
            'ElseIf (translation.Z <65> 1 Then
            'ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
            ''End If

            'End If

            '   If TicValue <0> -300 Then
            'TicValue = TicValue - translation.Z
            'End If


        End If
    End Sub

    Private Sub Keyboard_KeyDown(ByVal keyCode As Integer) Handles Keyboard.KeyDown

        Me.SetKeyText(keyCode)

    End Sub

    Private Sub Keyboard_KeyUp(ByVal keyCode As Integer) Handles Keyboard.KeyUp

        Me.SetKeyText(keyCode)

    End Sub


    Private Sub SetKeyText(ByVal key As Integer)
        ' InvokeRequired required compares the thread ID of the
        ' calling thread to the thread ID of the creating thread.
        ' If these threads are different, it returns true.
        If Me.TextBox1.InvokeRequired Then
            Dim d As New SetKeyTextCallback(AddressOf SetKeyText)
            Me.Invoke(d, key)
        Else
            If (Keyboard.IsKeyDown(key)) Then
                Me.TextBox8.Text = key
            Else
                Me.TextBox8.Clear()
            End If
        End If
    End Sub


    Protected Overrides Sub Finalize()
        Device.Disconnect()
        MyBase.Finalize()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.SelectedIndex = 0
        lblCount.Text = ListBox1.Items.Count - 1
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Timer1.Stop()
        Timer1.Dispose()
        'vox.Speak(ListBox1.SelectedItem.ToString)
        lblSelected.Text = ListBox1.SelectedItem.ToString
        SpeakBuffer = ListBox1.SelectedItem.ToString
        Timer1.Enabled = True
        Timer1.Start()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If ListBox1.SelectedItem.ToString = SpeakBuffer Then
            vox.Speak(ListBox1.SelectedItem.ToString)
        End If
        Timer1.Dispose()
        Timer1.Stop()
    End Sub
End Class

Long Range Communications, Inc
If you think it is impossible to be done, please don’t bother those who are already doing it…
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi alexus,

What the content of the method InitializeComponent()? I woud like to know how you did to link the event handler to sensor device...

Thanks.
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

If you have the code in C#, maybe I can convert it to C++
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

I think InitializeComponent() is the function that will activate the 3D Connexuion DLL file and then as vitrual driver is running we can work with that...

as to C# code, I can convert it to C# easily... ok hand on let me clean the app so I would have les garbadge and then I post clean code in both VB and C#
Long Range Communications, Inc
If you think it is impossible to be done, please don’t bother those who are already doing it…
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Ok alexus.
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

yea just hang on, I need to do some project for client so they see that i'm doing something and then I get back to you =)
Long Range Communications, Inc
If you think it is impossible to be done, please don’t bother those who are already doing it…
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

ok here you go VB and C# code. I would note that C# code is broken, I could not fix it, i did the convertion but It says that Finalize methoud should not be used instead I should use deconstructor... im not to good w/ C# garbadge collectors so C# code provided as is.... VB code worlks fine...

basic procedure:
1. conect to device
2. get data
3. pass it to somethin via multy thhreting

(I think in C++ you dont need to use multi threting which should make life easier)

VB.net

Code: Select all

Public Class Form1
    ' This delegate enables asynchronous calls for setting
    ' the text property on a TextBox control.
    Delegate Sub SetMotionTextCallback()
    Delegate Sub SetKeyTextCallback(ByVal keyCode As Integer)

    Private WithEvents Sensor As TDxInput.Sensor
    Private WithEvents Keyboard As TDxInput.Keyboard
    Private WithEvents Device As TDxInput.Device
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        Device = New TDxInput.Device
        Sensor = Device.Sensor
        Keyboard = Device.Keyboard
        SetMotionTexts()
        Device.Connect()
    End Sub
    Private Sub Sensor_SensorInput() Handles Sensor.SensorInput
        Me.SetMotionTexts()
    End Sub
    ' This method demonstrates a pattern for making thread-safe
    ' calls on a Windows Forms control. 
    '
    ' If the calling thread is different from the thread that
    ' created the TextBox control, this method creates a
    ' SetTextCallback and calls itself asynchronously using the
    ' Invoke method.
    '
    ' If the calling thread is the same as the thread that created
    ' the TextBox control, the Text property is set directly. 

    Private Sub SetMotionTexts()
        ' InvokeRequired required compares the thread ID of the
        ' calling thread to the thread ID of the creating thread.
        ' If these threads are different, it returns true.
        If Me.TextBox1.InvokeRequired Then
            Dim d As New SetMotionTextCallback(AddressOf SetMotionTexts)
            Me.Invoke(d)
        Else
            Dim Style1 As String = "f"
            
            Dim translation As TDxInput.Vector3D
            translation = Sensor.Translation
            Me.TextBox1.Text = Format(translation.X, Style1)
            Me.TextBox2.Text = Format(translation.Y, Style1)
            Me.TextBox3.Text = Format(translation.Z, Style1)

            Dim rotation As TDxInput.AngleAxis
            rotation = Sensor.Rotation
            Me.TextBox6.Text = Format(rotation.X, Style1)
            Me.TextBox5.Text = Format(rotation.Y, Style1)
            Me.TextBox4.Text = Format(rotation.Z, Style1)
            Me.TextBox7.Text = Format(rotation.Angle, Style1)
        End If
    End Sub


    Protected Overrides Sub Finalize()
        Device.Disconnect()
        MyBase.Finalize()
    End Sub
End Class

C#

Code: Select all

private void Sensor_SensorInput() 
    { 
        this.SetMotionTexts(); 
    } 
    // This method demonstrates a pattern for making thread-safe 
    // calls on a Windows Forms control. 
    // 
    // If the calling thread is different from the thread that 
    // created the TextBox control, this method creates a 
    // SetTextCallback and calls itself asynchronously using the 
    // Invoke method. 
    // 
    // If the calling thread is the same as the thread that created 
    // the TextBox control, the Text property is set directly. 
    
    private void SetMotionTexts() 
    { 
        // InvokeRequired required compares the thread ID of the 
        // calling thread to the thread ID of the creating thread. 
        // If these threads are different, it returns true. 
        if (this.TextBox1.InvokeRequired) { 
            SetMotionTextCallback d = new SetMotionTextCallback(SetMotionTexts); 
            this.Invoke(d); 
        } 
        else { 
            string Style1 = "f"; 
            
            TDxInput.Vector3D translation; 
            translation = Sensor.Translation; 
            this.TextBox1.Text = Strings.Format(translation.X, Style1); 
            this.TextBox2.Text = Strings.Format(translation.Y, Style1); 
            this.TextBox3.Text = Strings.Format(translation.Z, Style1); 
            
            TDxInput.AngleAxis rotation; 
            rotation = Sensor.Rotation; 
            this.TextBox6.Text = Strings.Format(rotation.X, Style1); 
            this.TextBox5.Text = Strings.Format(rotation.Y, Style1); 
            this.TextBox4.Text = Strings.Format(rotation.Z, Style1); 
            this.TextBox7.Text = Strings.Format(rotation.Angle, Style1); 
        } 
    } 
    
    
    protected override void Finalize() 
    { 
        Device.Disconnect(); 
        base.Finalize(); 
    } 
Long Range Communications, Inc
If you think it is impossible to be done, please don’t bother those who are already doing it…
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

How come I cxant edit my post? :(
C# code was cut off

Code: Select all

public class Form1 
{ 
    // This delegate enables asynchronous calls for setting 
    // the text property on a TextBox control. 
    public delegate void SetMotionTextCallback(); 
    public delegate void SetKeyTextCallback(int keyCode); 
    
    private TDxInput.Sensor Sensor; 
    private TDxInput.Keyboard Keyboard; 
    private TDxInput.Device Device; 
    public Form1() 
    { 
        // This call is required by the Windows Form Designer. 
        InitializeComponent(); 
        // Add any initialization after the InitializeComponent() call. 
        Device = new TDxInput.Device(); 
        Sensor = Device.Sensor; 
        Keyboard = Device.Keyboard; 
        SetMotionTexts(); 
        Device.Connect(); 
    } 
    private void Sensor_SensorInput() 
    { 
        this.SetMotionTexts(); 
    } 
    // This method demonstrates a pattern for making thread-safe 
    // calls on a Windows Forms control. 
    // 
    // If the calling thread is different from the thread that 
    // created the TextBox control, this method creates a 
    // SetTextCallback and calls itself asynchronously using the 
    // Invoke method. 
    // 
    // If the calling thread is the same as the thread that created 
    // the TextBox control, the Text property is set directly. 
    
    private void SetMotionTexts() 
    { 
        // InvokeRequired required compares the thread ID of the 
        // calling thread to the thread ID of the creating thread. 
        // If these threads are different, it returns true. 
        if (this.TextBox1.InvokeRequired) { 
            SetMotionTextCallback d = new SetMotionTextCallback(SetMotionTexts); 
            this.Invoke(d); 
        } 
        else { 
            string Style1 = "f"; 
            
            TDxInput.Vector3D translation; 
            translation = Sensor.Translation; 
            this.TextBox1.Text = Strings.Format(translation.X, Style1); 
            this.TextBox2.Text = Strings.Format(translation.Y, Style1); 
            this.TextBox3.Text = Strings.Format(translation.Z, Style1); 
            
            TDxInput.AngleAxis rotation; 
            rotation = Sensor.Rotation; 
            this.TextBox6.Text = Strings.Format(rotation.X, Style1); 
            this.TextBox5.Text = Strings.Format(rotation.Y, Style1); 
            this.TextBox4.Text = Strings.Format(rotation.Z, Style1); 
            this.TextBox7.Text = Strings.Format(rotation.Angle, Style1); 
        } 
    } 
    
    
    protected override void Finalize() 
    { 
        Device.Disconnect(); 
        base.Finalize(); 
    } 
} 
Long Range Communications, Inc
If you think it is impossible to be done, please don’t bother those who are already doing it…
AntonyAlbertAnto
Posts: 17
Joined: Wed Mar 24, 2021 1:09 pm

Re: Example of OnSensorInput()

Post by AntonyAlbertAnto »

Please I need help!!!
I would really appreciate if you could let me know the VB.net code to get the button(2 buttons, right and left) values from 3D space mouse while I press them.
ngomes
Moderator
Moderator
Posts: 3318
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: Example of OnSensorInput()

Post by ngomes »

AntonyAlbertAnto wrote: Wed Mar 24, 2021 1:14 pm Please I need help!!!
I would really appreciate if you could let me know the VB.net code to get the button(2 buttons, right and left) values from 3D space mouse while I press them.
Duplicated post. One of us has followed up here.
Post Reply