07-25-2014 01:43 PM
I have encountered a very strange problem. I'm writing a Training program that runs on a PC not connected to the network (so no autoupdates and other things to interrupt us). The idea is when the program is running, the Front Panel display is black, with a fairly large green circle in the middle ("Home") and a smaller white circle inside it ("Avatar"). The Avatar is controlled by a Joystick, and will move when the Joystick position changes. When the Avatar leaves Home, I want to turn on a relay and provide a reward, and when the Avatar returns Home (for example, by releasing the Joystick), I want to turn the relay off.
My code consists of two loops running as Start Asynchronous Call routines. Loop 1 reads a USB Joystick, puts the X,Y coordinates on a Queue, and goes to sleep for 100 milliseconds (i.e. it gets the Joystick to spit out a reading at 10 Hz).
The other loop dequeues data from the Joystick. For every point, it repaints the Front Panel (black background, Green Home, White Avatar), and decides whether or not we've entered or left Home. If we just left, it tells an NI USB-6501 to turn on Port 0-0 (which produces a TTL high that energizes our relay, whose coil voltage comes from a separate battery), and if we just reentered, it tells the 6501 to turn the Port off. Then we wait for another element in the Queue.
This is running on an Acer Aspire V5 notebook, powered by an AMD Dual-core processor running at 1GHz with 4GB of memory, running Windows 8.1. A bit underpowered, but it seems to run LabVIEW OK (if slowly).
We compiled this program into an executable and tested it. It ran fine -- the Joystick moved around, the relay went on and off, and everyone was happy. Then they tried to use it in the actual Training Paradigm -- it worked for 10-15 minutes, and then froze, with the Joystick apparently unresponsive (the Avatar didn't move, was "stuck" outside Home even though the Joystick was released) and the relay left On.
I changed the Dequeue routine to time out after 5000 seconds (in which time 50 Joystick points should have been received). Sure enough, the Dequeue timed out, providing a Log message and ending the program "gracefully".
Most of the time (and maybe all of the time), we seem to "get stuck" just as we are moving the Joystick out of Home (and turning on the relay) -- it does seem to be the case that the Relay On routine occurs just over 5 seconds before the Queue times out. My interpretation of what I'm observing is that sometimes issuing a "Turn Port 0-0 On" to the 6501 (I'm using standard DAQmx calls) seems to "lock up" the Joystick loop, running asynchronously, so that it stops putting values in the Joystick Queue.
I've tried a few variations. We had been combining the two USB cables (from the Joystick and the 6501) into a USB 2-port unpowered minihub. In this configuration, as I said, we can run for minutes without trouble, but if we are sufficiently persistent, we seem to get "stuck". I tried using a powered 4-port hub -- got stuck right away (I didn't test further). I had been running the Laptop on its own battery, so I tried plugging it in -- gets "stuck".
For my final test, I plugged the two USB devices into the two USB ports on the Laptop. Program seemed to run without getting stuck, with periodic tests of a few minutes over the course of an hour. But then I noticed that if I moved the Joystick out and back quickly, the relay stayed on for 2-3 seconds (and the Avatar remained "stuck" outside the Home circle for the same time). This suggests, to me, that I still have the same problem (traffic on one USB port, namely the 6501, where I'm only issuing a Digital Line On or Off) is preventing traffic on another USB port connected to my Joystick. [Incidently, if I just test how fast I can read data from the Joystick, even on this slow laptop the rate seems to be on the order of 10KHz].
I'm 99.9% certain that this is not my code, nor LabVIEW's fault (though I don't know about the robustness of their "Read from Joystick" routines), and think that it is probably hardware. I'm planning to test with a completely different notebook (heck, maybe I'll try running this on my Surface Pro).
I would welcome suggestions, or information if you have seen similar cases of one USB stream preventing another from transmitting data to the Host. I will also post a followup here once I do the additional Hardware tests.
Bob (confused) Schor
07-26-2014 10:06 AM
I wonder if you are getting a transient from activating the relay which "kills" the USB connection? Try replacing the relay coil with a resistor and LED so you can see that the USB-6501 changed state. The LED will not cause a transient like the relay coil could.
The fact that it seems to go to timeout immediately after the DO write is suspicious. What are the voltage and current ratings of the relay coil?
Lynn
07-26-2014 12:20 PM
That's not a bad idea! I suspect this is not the issue for a couple of reasons I didn't mention in my original post. We are using a 4-relay DIY board that is designed to take a USB input, has a microprocessor, and you give it serial commands like "Relay 0 on" and it turns on the relay (provided you have hooked up a separate +12v battery to run the coil). Turns out the microcode for the processor is bad -- if you send the command as the manual and demos suggest (with a trailing <CR>), then this command locks up the communication port and you have to power cycle the board (on the other hand, the "Ver<CR>" command returns the firmware version quite nicely). We decided to skip the faulty microprocessor and go with the "external TTL" inputs which are, we hope, isolated from the relays with diodes and other circuitry. In any case, we get the same USB "interference" with the Joystick whether the USB is the 6501 or the USB controller on the relay card.
I've got a related question about LabVIEW's Joystick implementation, but I'm going to post it as a separate "Reply".
BS
07-26-2014 12:32 PM
At the end of the previous Post, I joked "Maybe I'll try running this on my Surface Pro". Well, the Surface Pro doesn't let me "see" the Joystick using LabVIEW!
Background -- I developed this software with LabVIEW 2012 SP1 running on Dell desktops running Windows 7 Pro SP1. I wrote a utility based around the LabVIEW "Input Devices" functions that provide access to Joysticks, Keyboards, and Mice, to allow me to explore Joysticks. The function Query Input Device returns an array of all the Joysticks found on the system, including the number of Axes, number of Buttons, number of Hat (POV) switches, and the Device Name. You use the index of this array that has the Joystick Name you want (often Index 0, as the first item in the array is often your Joystick) as the argument to Initialize Joystick, and then you can Acquire Input Data to get the values of the Axes, Buttons, and Hat Switches.
This code runs like a champ on my Windows 7 machines, including on the little notebook. However, when I run it on my Surface Pro, which (heaven help me) runs Windows 8.1, the Query Input Device function fails to find any Joystick plugged into my USB port. When I plug it in, I hear the "USB noise", and if I ask Windows to configure any Game Controllers, it finds (in this case) Logitech Joystick (and can show me axes, buttons, and hats), yet LabVIEW finds nothing.
Any ideas? Is this a Windows 8 / LabVIEW problem?
BS
07-26-2014 03:51 PM
In partial answer to the question "Why can't my Surface Pro find a Logitech Joystick", I plugged it into one of my Windows 7 desktops and my LabVIEW routine found it with no trouble. Maybe it is a Windows 8 issue? More testing needed ...
BS
07-27-2014 01:41 PM
... and, if I had half a brain, I would have remembered that the Acer notebook, on which we discovered the "hanging USB" problem, is also running Windows 8.1. So both the Acer and my Surface Pro run Windows 8.1 (though, for all its faults, the Surface is much faster and more powerful), both can "see" the Joystick in the Windows "Game Controller" setup code, but only the Acer finds the Joystick when running LabVIEW's Query Input Device function. Hmm, maybe it is an NI issue ...
BS
07-28-2014 05:04 PM
Well, with the help of an NI Applications Engineer, I got the answer to why LabVIEW on the Surface Pro cannot find the Joystick. The VIs that handle the Joystick, Keyboard, and Mouse as Input Devices use DirectX DLLs. For reasons that are unclear (but may be an NI "bug"), the function that Queries the devices only returns the first (up to 😎 items that DirectX reports. On my Surface, DirectX shows 15 items, and (of course) the Joystick is #15. Oops ...
BS
07-28-2014 05:07 PM
I have also had problems with Win7 where connecting to my office PC via VPN and Remote Desktop would work fine locally to start, work fine remotely but then the buttons of my mouse would cease to function in LV only when I return to a local session.
There are some bugs in LVs handling of input devices somewhere. I've reported a few times, but it's never been reproduced.
Shane.
06-01-2015 06:06 PM
Hi Bob,
I seem to be having the exact same problem as you did. The joystick that i want to use is #14 on the list of DirectInput Devices on my Surface Pro. Did you find a way to change the order of your devices so that your joystick would be in the top 8?
Any help would be so appreciated! Thank you.
06-02-2015 06:15 PM
Hi Raqcgal,
This thread has been inactive for over a year! You might have better luck looking elsewhere for an answer to this question.