how to tell if no device connected?

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

Moderator: Moderators

Post Reply
neil_at_informatix
Posts: 6
Joined: Wed Apr 23, 2008 1:48 am
Location: Cambridge UK

how to tell if no device connected?

Post by neil_at_informatix »

If 3Dx software is installed, then CoCreateInstance is expected to succeed.
Regardless of whether a SpaceXXX device is plugged in, we expect dev->Connect() to succeed after that.

So ... how to tell whether the user has a real device plugged in, or software installed but device unplugged? (This is quite likely on a laptop!)

I don't want to put up additional navigation menus if the user has no means to use them...

Is the "approved" test

Code: Select all

#define UnknownDevice 0
long type; 
hr = dev->get_Type(&type);
if (type==UnknownDevice) throw "ErrNoActualDeviceConnected";
or is there a more specific test?

BTW - what happens if some oddball user plugs in two SpaceXX devices? Two the same? Two different ones?
Creo Imaginem Mente
alexus
Posts: 39
Joined: Sat Apr 19, 2008 9:42 am
Location: New York, NY
Contact:

Post by alexus »

Hey there, one way to do that for sure is to chek windows device list.
You got to ways.
1. My.Computer.Hardware scope and then select the space navigator name... what ever it is
2. use HID class and chek spesifuc Vendor and Product ID to pinpoint spesific usb device, in this way you will even be able to tell if 2 devices of the same categoty are plugged in .

I can post sample code but only in MS Visual Basic.... I'm no friend with C++
mbonk
Moderator
Moderator
Posts: 181
Joined: Mon Dec 04, 2006 4:06 am

Re: how to tell if no device connected?

Post by mbonk »

neil_at_informatix wrote:Is the "approved" test

Code: Select all

#define UnknownDevice 0
long type; 
hr = dev->get_Type(&type);
if (type==UnknownDevice) throw "ErrNoActualDeviceConnected";
or is there a more specific test?
No. Testing the device type is how we recommend to test for an attached and functioning device. You will also receive the same result if the driver s not running.
Once a device is attached or the driver is started you will receive a Device::DeviceChange signal.
neil_at_informatix wrote: BTW - what happens if some oddball user plugs in two SpaceXX devices? Two the same? Two different ones?
With two devices attached only one is handled by the 3dxware driver. In the case of identical devices the driver will serve the first one it enumerates.
In the case of different devices the driver will serve the device with more value added features.

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

Post by rodrigo.seabra »

Sorry, but after all, what we should do the test so that if the device is not connected to the USB port, the user is advised?

In the examples shown so far, even if the device is not connected, the user receives information that yes.

Thanks.
ngomes
Moderator
Moderator
Posts: 3458
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

Hi rodrigo.seabra,
In the examples shown so far, even if the device is not connected, the user receives information that yes.
If no device is connected or if 3DxWare isn't running, then no functioning device is available. This is the same as saying "no 3D Mouse found".

You can reconnect if you handle the DeviceChange event.
Nuno Gomes
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Yes, I agree. Maybe this code help others developers...

Code: Select all

hr = _3DxDevice.CoCreateInstance(__uuidof(Device));
	if (SUCCEEDED(hr)) {
		CComPtr<ISimpleDevice> _3DxSimpleDevice;
		hr = _3DxDevice.QueryInterface(&_3DxSimpleDevice);
		hr = _3DxSimpleDevice -> get_Type(&type); 
		if (type == UnknownDevice) cout << "Space Navigator not found!";
		if (SUCCEEDED(hr) && type != UnknownDevice) {
			
			g3DSensor = _3DxSimpleDevice -> Sensor;
	         g3DKeyboard = _3DxSimpleDevice -> Keyboard;
			_3DxSimpleDevice -> Connect();
			cout << "SpaceNavigator connected..." << endl;
		}
	}
dotbond
Posts: 6
Joined: Thu Jul 09, 2009 5:32 pm

Post by dotbond »

We're developing an application in C# (Visual Studio 2008) and are having difficulty detecting if our Spacenavigator mouse is plugged in.

Ideally we want to be able to enable alternate controls for our program if the mouse isn't plugged in.

What code can we use to tell us if the 3d mouse has been detected or not, as the code in this thread is totally foreign to us.


Thanks
Trev.
mbonk
Moderator
Moderator
Posts: 181
Joined: Mon Dec 04, 2006 4:06 am

Post by mbonk »

C# code similar to the C++ might be something like:

Code: Select all

    class Input3DMouseDevice
    {
        TDx.TDxInput.Device   m_device;
        TDx.TDxInput.Sensor   m_sensor;
        TDx.TDxInput.Keyboard m_keyboard;

        protected void Initialize()
        {
            m_device = new TDx.TDxInput.Device();

            if (m_device.Type == UnknownDevice)
               Console.WriteLine("3D Mouse not found!");

            // Add the event handlers
            m_device.DeviceChange += new TDx.TDxInput._ISimpleDeviceEvents_DeviceChangeEventHandler(this.device_DeviceChange);

            // Instance the buttons and the 6dof sensor
            m_keyboard = m_device.Keyboard;
            m_sensor = m_device.Sensor;
       
            // Connect to driver
            m_device.Connect();
        }

        void device_DeviceChange(int reserved)
        {
            if (m_device.Type != UnknownDevice)
               Console.WriteLine("3D Mouse found!");

        }
     }
dotbond
Posts: 6
Joined: Thu Jul 09, 2009 5:32 pm

Post by dotbond »

Thank you very much Markus. We will see if we can make this code work.


Thanks again
Trev.
dotbond
Posts: 6
Joined: Thu Jul 09, 2009 5:32 pm

Post by dotbond »

hi again

this code sort of works, except that m_device.Type is always returning 6 whether the mouse is plugged in or not. What might be causing this, and how can we get around it?

Thanks
Trev.
mbonk
Moderator
Moderator
Posts: 181
Joined: Mon Dec 04, 2006 4:06 am

Post by mbonk »

Currently, you will received the id of the last device plugged in. i.e the driver does not inform anyone that the device has been removed
in the mean time.
Post Reply