LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot reconnect and use joystick after reconnecting USB cable without restarting LabVIEW

Hi

 

Hardware

APEM HF Series USB joystick

 

Software

LabVIEW 2019

 

Task

To be able to connect and disconnect the USB joystick while the LabVIEW program is running.

The program must detect connections and disconnections.

 

What works

I am using the Input Device Control Palette to acquire the joystick position and button status from a joystick.

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P9aOSAS&l=sv-SE

 

What does not work

If I disconnect and connect the joystick while LabVIEW (or the built EXE) is running, I cannot use the joystick again until I restart LabVIEW (or the built EXE).

I have tried stopping and starting the VI and making versions of the VI using Query Input Devices.vi to detect the joystick.

But Query Input Devices.vi seems to not be able to detect a disconnection. It "remembers" the joystick.

 

Error code -2000000006 is generated by joystickAcquire.vi both after disconnection and also after reconnection of the USB joystick.

 

I have tried the "subVI solution" suggested here:

https://forums.ni.com/t5/LabVIEW/Query-Joysticks-Access-violation/td-p/3560662?profile.language=en

That does not help.

 

Has anyone experienced this before?

 

Thanks

0 Kudos
Message 1 of 12
(3,556 Views)

It would help us to help you if you would attach your VI (not a picture -- we may want to test the code with our own Joystick).

 

Can you explain why you need to detach the Joystick while the Program is running?  

 

Bob Schor

0 Kudos
Message 2 of 12
(3,514 Views)

Just for clarity, have you tried calling "Close input device" after it goes in to the error state, before reconnecting again?

--------------------------------------
0 Kudos
Message 3 of 12
(3,507 Views)

Hi

 

I have attached example code.

Scenario:

1. The VI is running and acquiring joystick input.

2. The USB cable is disconnected and the VI stops, as expected.

3. The USB cable is reconnected

4. Any attempt to run the VI results in an immediate error from "joystickAcquire.vi", "Close input device" is executed, and the VI stops.

5. LabVIEW must be restarted

 

Thanks

 

 

0 Kudos
Message 4 of 12
(3,493 Views)

So, it looks like "Close Input Device" is written such that it doesn't actually do anything in the error case:

joystick close.PNGjoystick close error.PNG

 

Could you try NOT wiring the error wire in to the close function (or clearing the error first)?

I would test it myself, but I don't have a joystick handy.

--------------------------------------
0 Kudos
Message 5 of 12
(3,480 Views)

Yes, I had already tested that. Sorry for not mentioning.

 

See attached code that does not wire error inte the close function.

Same behavior. 

0 Kudos
Message 6 of 12
(3,474 Views)

The VI now attached.

0 Kudos
Message 7 of 12
(3,473 Views)

Hrm, bummer. My only other thought is finding the HID API built in to windows and manually re-enumerating via a Call Library Function node. I wouldn't put money on it working, though.

--------------------------------------
0 Kudos
Message 8 of 12
(3,466 Views)

I suspect this is similar to some other stuff that LV only checks when it wakes up... things like time zone settings etc. I thought I read Rolf mentioning that it is a good thing that helps performance.

 

I can outline an approach that may work but unless there is a dire need, I suspect most will not want to walk that path.

 

When you app starts it should spin-off a separate exe that interacts with the joy-stick via a communications method of your choosing (TCP, ActiveX, ...).

 

When the joy stick disconnects the app exits.

 

Your main application detects the exit and spins up another exe to talk to the joystick.

 

Now if you walk that path, please share an example so others do not have to fight through the same wilderness to get to the same goal.

 

Have fun!

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 12
(3,459 Views)

Hi, i am fighting with the same problem, but in LV 2016 win10.

In development system i could solve the problem. I starting the vi as a sub-vi via reference. If i detect connection error i just close the reference and open the subvi again. Unfortunately if i create an application it is not working :(.

Has someone perhaps found another solution?

 

0 Kudos
Message 10 of 12
(2,099 Views)