VB6 and SpacePilot

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

Moderator: Moderators

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

VB6 and SpacePilot

Post by takedownca » Thu Feb 28, 2008 5:56 pm

I want to modify a VB6 application to accept input from 3DConnexion devices. However, since there are no examples showing how to interface with the TDx dll using VB6, I created a test project first. So far, the project compiles fine, but is not responding to the SensorInput event. Here are the relevant lines of code. Thanks for any help.

Code: Select all

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

Private Sub Form_Load()
    Set Device = New TDxInput.Device
    Set Sensor = Device.Sensor
    Set Keyboard = Device.Keyboard
    
    Device.Connect
End Sub

Private Sub Sensor_SensorInput()
    UpdateAll
End Sub

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

Post by takedownca » Thu Feb 28, 2008 6:15 pm

Also, I know the Connect method is working (I think) because Device.IsConnected reports True.

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

Post by takedownca » Fri Feb 29, 2008 4:25 pm

I figured it out. Turns out VB6 doesn't like it when you name your objects with an existing property name. So I had to change the declarations from:

Code: Select all

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

Code: Select all

Private WithEvents Device1 As TDxInput.Device
Private WithEvents Sensor1 As TDxInput.Sensor
Private WithEvents Keyboard1 As TDxInput.Keyboard

Greensheep2k8
Posts: 3
Joined: Thu Oct 09, 2008 1:06 pm

VB6 and Space Pilot

Post by Greensheep2k8 » Thu Oct 09, 2008 1:26 pm

Hi,

takedownca, do you have a working VB6 space navigator interface?

I have a pretty limited and frankly out of date programming knowledge, I've written a software package for my car PC using VB6 and would love to implement my Space navigator as a controller.

I've scoured the forum and SDK samples and have written a test program as a first step:

Code: Select all

Private WithEvents Sensor1 As TDxInput.Sensor
Private WithEvents Keyboard1 As TDxInput.Keyboard
Private WithEvents Device1 As TDxInput.Device

Private Sub Form_Load()

Set Device1 = New TDxInput.Device
Set Sensor1 = Device1.Sensor
Set Keyboard1 = Device1.Keyboard

Call Device1.Connect

MsgBox ("Connection Status: " & Device1.IsConnected)

End Sub


Private Sub Sensor_SensorInput()

Dim Translation1 As TDxInput.Vector3D
Translation1 = Sensor1.Translation

Dim Rotation1 As TDxInput.AngleAxis
Roataion1 = Sensor1.Rotation

Form1.Text1.Text = Translation1.X
Form1.Text1.Text = Translation1.Y
Form1.Text1.Text = Translation1.Z

Form1.Text1.Text = Rotation1.X
Form1.Text1.Text = Rotation1.Y
Form1.Text1.Text = Rotation1.Z
Form1.Text1.Text = Rotation1.Angle

End Sub
The program runs with no errors, and device1.isconnected always returns true regardless of wether my SN is plugged in. the sensor input function is never triggered.

I appreciate that VB6 may be outdated, however this is the last step in my software development and would really appreciate any help in getting this code to work.

Also, this isnt a sample/snippets of code, this is the complete code, am i missing anything?

thanks in advance

Jonny

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

Post by takedownca » Thu Oct 09, 2008 2:21 pm

Greensheep,

The only difference I see between your my functional code and your non-functional code is the Device1.Connect line. Try removing the "Call" from that line.

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

Post by takedownca » Thu Oct 09, 2008 2:22 pm

And the Sensor_Input event should read Sensor1_Input.

Greensheep2k8
Posts: 3
Joined: Thu Oct 09, 2008 1:06 pm

Post by Greensheep2k8 » Thu Oct 09, 2008 3:23 pm

Thanks for the replies,

Movements of the SN now call the sensor event which is a step in the right direction!

However, I now get an 'Object variable or with block variable not set' error message as soon as i hit:

Code: Select all

Translation1 = Sensor1.Translation
I'm sure i must be missing something.

Again, I would really appreciate your assistance.

Regards

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

Post by takedownca » Thu Oct 09, 2008 3:29 pm

Translation1 is an object, not just a variable. So try putting "Set" in front of the assignment statement.

Greensheep2k8
Posts: 3
Joined: Thu Oct 09, 2008 1:06 pm

Post by Greensheep2k8 » Thu Oct 09, 2008 4:05 pm

It's working!

Adding 'Set' in front of Translation and rotation worked, in addition to one or two other typos it's now up and running perfectly.

Many thanks for your help.

Jonny

Code: Select all

Private WithEvents Sensor1 As TDxInput.Sensor
Private WithEvents Keyboard1 As TDxInput.Keyboard
Private WithEvents Device1 As TDxInput.Device

Private Sub Form_Load()

Set Device1 = New TDxInput.Device
Set Sensor1 = Device1.Sensor
Set Keyboard1 = Device1.Keyboard

Device1.Connect

MsgBox ("Connection Status: " & Device1.IsConnected)

End Sub


Private Sub Sensor1_SensorInput()

Dim Translation1 As TDxInput.Vector3D

Set Translation1 = Sensor1.Translation

Dim Rotation1 As TDxInput.AngleAxis
Set Rotation1 = Sensor1.Rotation

Form1.Text1.Text = Translation1.X
Form1.Text2.Text = Translation1.Y
Form1.Text3.Text = Translation1.Z

Form1.Text4.Text = Rotation1.X
Form1.Text5.Text = Rotation1.Y
Form1.Text6.Text = Rotation1.Z
Form1.Text7.Text = Rotation1.Angle

End Sub


idtec
Posts: 2
Joined: Tue Feb 23, 2010 9:34 am

vb6 and dll

Post by idtec » Tue Feb 23, 2010 9:48 am

I can't insert the tdxinput.dll. Wich control can i use to make the source working in VB6. now i get the error user defined type not defined.

Can someone help me with this problem or where can i find a sample program in V6?

takedownca
Posts: 62
Joined: Thu Mar 29, 2007 3:49 pm

Post by takedownca » Tue Feb 23, 2010 10:19 am

idtec,
The dll is not a control, it's a library. You need to go to Tools>References in the VB environment, browse to the dll, and add it as a reference.

idtec
Posts: 2
Joined: Tue Feb 23, 2010 9:34 am

Post by idtec » Tue Feb 23, 2010 10:33 am

thanks! now its working

xpeace77
Posts: 5
Joined: Sun Aug 22, 2010 5:13 pm

Post by xpeace77 » Mon Sep 06, 2010 4:22 am

Damn I should`ve come here before :-)

I wrote a complete and working HID Interface in VB to communicate with the SpaceNavigator, this works even without any 3dConnection Software being installed :-) I just got one small Problem

In the HID Input Report Samples the Axis Data reported is as following:

pDev->allDOFs[0] = (pDev->buf[1] & 0x000000ff) | ((int)pDev->buf[2]<<8 & 0xffffff00);

Anyone can help to I implement a working conversion in VB ? or Can explain how the Axis Data is transmitted in the Input Report, so that I can form readable "normal" +-Value Axis Data

jwick
Moderator
Moderator
Posts: 2609
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick » Mon Sep 06, 2010 7:48 am

You are unfamiliar with the shifting and masking syntax in C?

The three data elements of the translation [and rotation] axes arrive in a group of 6 bytes. 2 bytes per axis, 3 axes (X, Y, Z). This code grabs two bytes at a time and converts them into a signed integer. If you don't have bit shifting/masking operators, you should be able to do the same thing with multiplication (*256).

Note the least significant byte arrives first. And it is often a pain to get the sign bit extended correctly.

xpeace77
Posts: 5
Joined: Sun Aug 22, 2010 5:13 pm

Post by xpeace77 » Mon Sep 06, 2010 10:42 am

Can you give me an example ?

Currently my Device reacts as following if I push it straight down
I get Values in ReportBuffer 5 from 0 - 255 then pushing more than 255 it starts from 0 to x again, ReportBuffer 6 stays 0 all the time.

If I pull up the ReportBuffer 5 goes from 255 decreasing to 0 ReportBuffer 6 is immediately at Value 255 furthermore pulling upwards ReportBuffer 6 goes to 254 and ReportBuffer 5 starts from 255 again.

Can someone explain me the Logic ? I can`t see how to detect Values > 255 when pusing down the SpaceNavigator, without tracing the Input Data by some means of Envelope Following Algorithm, ... :?

Post Reply