LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a 3Dx Mouse in NI Labwindows CVI

Hi all,

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


A Windows SDK is provided with these 3D mice (you have to ask for it by e-mail to apisupport-win@3dx.com), and eases quite a lot the managing of such devices.


As I haven't found any 3D mouse code sample using LabWindows here, here's the way I managed to get it working (it assumes the mouse driver are installed):

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

Code:
// 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:
 // 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:
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 Smile

 

There are other ways to control such mice (adding a panel callback or writing your own low-level Windows message handler), but this one is by far the easiest and the quickest (in terms of implementation and response time)


Attached is the CVI port of the 3DxTest demo program included in the SDK.

Feel free to test and comment...

François

Message 1 of 3
(3,184 Views)

tomob ha scritto:
Feel free to test and comment...


François



I'd really like to, but I haven't any such mouse in my hands! Smiley Wink

 

In any case this i a valuable addition to that great forum: thank you very mush for sharing your knowledge!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,179 Views)

Well, being a CVI user from scratch, I have found countless useful clues on this forum.

Then it was quite normal for me to send my refund 😉

 

I just hope it can help someone some day.

 

François

 

0 Kudos
Message 3 of 3
(3,175 Views)