08-20-2019 02:38 AM
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
08-20-2019 02:02 PM
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
08-20-2019 03:14 PM
Just for clarity, have you tried calling "Close input device" after it goes in to the error state, before reconnecting again?
08-21-2019 02:06 AM
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
08-21-2019 07:01 AM
So, it looks like "Close Input Device" is written such that it doesn't actually do anything in the error case:
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.
08-21-2019 07:07 AM
Yes, I had already tested that. Sorry for not mentioning.
See attached code that does not wire error inte the close function.
Same behavior.
08-21-2019 07:08 AM
The VI now attached.
08-21-2019 07:38 AM
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.
08-21-2019 08:14 AM
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
10-17-2022 04:09 AM
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?