Using a 3Dx Mouse in NI Labwindows CVI

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

Moderator: Moderators

Post Reply
Flat
Posts: 7
Joined: Wed Sep 07, 2011 1:08 am
Location: France

Using a 3Dx Mouse in NI Labwindows CVI

Post by Flat »

Hi all,

I've been struggling a bit trying to integrate a 3D Mouse (namely a Space Navigator) in my NI Labwindows CVI application.

Thus, in order to avoid other people reinventing the wheel, here's the way I managed to get it working. And it works perfectly for me, believe me ;)

First, declare a callback for the 3D mouse in the classical CVI way:

Code: Select all

// 3DMouse Callback declaration
int CVICALLBACK SpaceNavigatorCB(int panelHandle, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData);
Then the main part is here :
After mouse initialization, get the Windows message number used by 3DxWare, and install a CVI callback to react to this message number. Then you can run the user interface:

Code: Select all

 // Initialize 3D mouse
      status = SbInit();

 // Get 3DxWare message number 
	Mess3Dx = RegisterWindowMessage("SpaceWareMessage00");

 // Install a specific callback for this message
	InstallWinMsgCallback (mainPanel, Mess3Dx, SpaceNavigatorCB, VAL_MODE_INTERCEPT, NULL, &postHandle);

 // Run application
	RunUserInterface();

 // Remove callback on quitting
	RemoveWinMsgCallback(mainPanel, Mess3Dx);
The callback itself is quite straightforward, just be sure to cast proper types to message parameters:

Code: Select all

int CVICALLBACK SpaceNavigatorCB(int panel, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData)
{
	int            num;      /* number of button pressed */
    SiSpwEvent     Event;    /* SpaceWare Event */ 
    SiGetEventData EData;    /* SpaceWare Event Data */

 /* init Window platform specific data for a call to SiGetEvent */
   	SiGetEventWinInit(&EData, (UINT)message, (WPARAM)*wParam, (LPARAM)*lParam);

  /* check whether msg was a 3D mouse event and process it */
  	if (SiGetEvent (devHdl, SI_AVERAGE_EVENTS, &EData, &Event) == SI_IS_EVENT) {

		if (Event.type == SI_MOTION_EVENT)
        	SbMotionEvent(&Event);        /* process 3D mouse motion event */     

		if (Event.type == SI_ZERO_EVENT)
	        SbZeroEvent();                /* process 3D mouse zero event */     

		if (Event.type == SI_BUTTON_EVENT) {
			if ((num = SiButtonPressed (&Event)) != SI_NO_BUTTON)	
           		SbButtonPressEvent(num);        /* process 3D mouse button event */

			if ((num = SiButtonReleased (&Event)) != SI_NO_BUTTON)	
           		SbButtonReleaseEvent(num);      /* process 3D mouse button event */
	    }
     	if (Event.type == SI_DEVICE_CHANGE_EVENT)
        	HandleDeviceChangeEvent(&Event);
	}
	return 0;
}
And here you are :)

Here is the CVI port of the 3DxTest demo program:
(is there a way to attach a file to a post) ?
http://www.filefactory.com/file/cee4fd5 ... xMouse.rar

Feel free to test and comment...

François

P.S. In order to get it working, it was necessary to comment the "include <tchar>" line in spwdata.h.
There are no adverse effects until now, but is it safe, Jim ? Or are there workarounds ?
jwick
Moderator
Moderator
Posts: 3340
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

Thanks for posting this.

tchar.h is just an implementation of a type that will switch between ANSI strings (1 byte per char) and Unicode strings (2 bytes per char). If you took it out and it still compiles, the type isn't used in that code (or tchar.h is included somewhere else).
Ibai00
Posts: 5
Joined: Tue Mar 05, 2013 8:09 am

Re: Using a 3Dx Mouse in NI Labwindows CVI

Post by Ibai00 »

Hi Flat,

I am currently using labwindows and I would like to know if you can update the link where I can download the CVI file.

Otherwise you can send me to my next hotmail account: rezola2@hotmail.com

Thank you very much,

Ibai
Flat
Posts: 7
Joined: Wed Sep 07, 2011 1:08 am
Location: France

Re: Using a 3Dx Mouse in NI Labwindows CVI

Post by Flat »

Hi Ibai,

Here it is

Good luck, and tell us if it works for you.

Regards,
François
Ibai00
Posts: 5
Joined: Tue Mar 05, 2013 8:09 am

Re: Using a 3Dx Mouse in NI Labwindows CVI

Post by Ibai00 »

Dear Flat,

First of all thank you!. I am 100% sure your project will make mine much easier.

However, I am not able to run the project. When I try to run the application, spwdata.h asks for tchar.h (running in WIN32). Firstly I tried to used the header file that come with Dev-Cpp and secondly the one that comes with Visual Studio 2010.
In both situations, my proposal didn't work ("deep"compilation errors (not with tchar.h)).
I think I am missing something:
1. Some configuration issue in the project.
2. Where/How to get the correct header files.

As mentioned before, thank you for your time and patience.

Best regards,

Ibai
Ibai00
Posts: 5
Joined: Tue Mar 05, 2013 8:09 am

Re: Using a 3Dx Mouse in NI Labwindows CVI

Post by Ibai00 »

Hi flat,

First of all, I have resolved <tchar> error. Somehow I missed your comments in the first post, sorry for that.

After resolving this error, now I having some linking problems.
Project is calling to C:\Program Files\3Dconnexion\3DxWare SDK\Lib\siapp\bin\win32i\release\siapp.lib and C:\Program Files\3Dconnexion\3DxWare SDK\Lib\spwmath\bin\win32i\release\spwmath.lib, but I do not have these libraries in those directories.




I have those original files in C:\Program Files\3Dconnexion\3DxWare SDK\Lib\x86

I copied the "original" (x86 folder) files into the paths that produced the linking errors (C:\Program Files\3Dconnexion\3DxWare SDK\Lib\siapp\bin\win32i\release\ and C:\Program Files\3Dconnexion\3DxWare SDK\Lib\spwmath\bin\win32i\release\); but it didn't work. Do you have any idea what is going on?

I’m very grateful for your dedication.

Best regards,

Ibai
Ibai00
Posts: 5
Joined: Tue Mar 05, 2013 8:09 am

Re: Using a 3Dx Mouse in NI Labwindows CVI

Post by Ibai00 »

Hi flat,

First of all, thank you one more time because it's thankful the attention you are giving.

Now I added the 4 link errors that I am having, that yesterday didn't upload because an own error.
ERROR LABWINDOWS.jpg
In google in National Instruments, I have seen another option for this case that is <analysis.h> but I don't find this file.

Best regards,

Ibai
Ibai00
Posts: 5
Joined: Tue Mar 05, 2013 8:09 am

Re: Using a 3Dx Mouse in NI Labwindows CVI

Post by Ibai00 »

Dear flat,

I added the library files manually and it works properly.

Thank you very much for your dedication. I'm sure you're proyect will help me a lot.

Best wishes,

Ibai
Post Reply