LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Query Joysticks - Access violation

Solved!
Go to solution

I am currently using an XBox One controller to steer multiple elements in my application. I want to be able to connect and disconnect the joystick during runtime (mostly because it goes to energy saving when not used for a while - the wakeup should work).

 

I followed the guidelines in this thread, which states that one should unload the "lvinput.dll" between calls to get updated values. This is working fine but whenever I stop the program, I get an Access violation (0xC0000005) (see screenshot).

The original poster seems to have had the same problem but there is no solution and I couldn't find anything around.

 

The attached code has the "Query Test.vi" which actually queries the lvinput.dll and the "Reconnect Testing.vi" which calls the "Query Test.vi" in a loop. Running either of them results in a crash when exiting it.

0 Kudos
Message 1 of 6
(1,224 Views)

Hi,

I was seeing a similar problem a few months ago with a X-Box controller.

When unplugging and then plugging the controller in again, while the VI that opened the connection to the controller is running, it is not possible to reconnect the controller again.

Error -2000000006 appears after disconnecting the controller. When trying to reconnect, the error is not cleared.

This is a known problem as Windows only releases the controller (joystick) reference when the calling program (which is the VI here) is closed.

My workaround is to initialize and use the joystick connection in a sub vi which is called dynamically:

 

Main.png

SubVI.png

 

After disconnecting the controller error -2000000006 appears and the "Joystick Handler.vi" closes.

Then you have to call it again dynamically like I did in my "Top level.vi" above.

This worked fine for me.

Christian
CLA, CTA, CLED
0 Kudos
Message 2 of 6
(1,152 Views)

Interesting. But the part I actually want to get around is that in your example, the user has to trigger the reconnection by clicking the button.

I would like to have a way of constantly checking in the background wether the controller is connected or not and then read it or not.

I tried your suggestion with the Query Input Devices.vi inside your Joystick Handler.vi and it also doesn't get the list of currently connected devices but rather the list of devices connected when it was run for the first time (as usual).

0 Kudos
Message 3 of 6
(1,145 Views)
Solution
Accepted by ehrlich

I finally managed to solve the issue of connecting and disconnecting the XBox controller at runtime. The solution is to not use the LabView internal joystick VIs but the XInput library provided by Windows.

 

For further see here and the attached VI for an example. As a bonus, this API also allows to use the vibration of the controller 🙂

Message 4 of 6
(980 Views)
Highlighted

Do you know if it works with other controls? or only works with the 360

0 Kudos
Message 5 of 6
(42 Views)
I think it's only for the XBox controllers. However I read somewhere that some other controllers (some from Logitech) also support to be used via the XInput library but I guess it will be very hard to figure that out without trying. But there might be a similar Microsoft library for Joysticks in general which I have not used.
0 Kudos
Message 6 of 6
(21 Views)