LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

grabbing usb mouse velocity

Solved!
Go to solution

In Short: I would like to query a usb mouse for it's X and Y velocity on a regular interval.  How do?

 

What I've Got: My current attempt involves setting up the mouse as a VISA RAW device and grabbing the data via a VISA USB interrupt event on loop (attached).  This works splendidly; my issue with this approach is that this returns buffers on uneven intervals, i.e. whenever an event is triggered or the timeout occurs.

 

My ideas: Though I certainly wouldn't want to stifle anyone's other solutions to the original problem, I have some leads of my own that you may be able to help with, too, if you think one is indeed the correct approach to the original problem.  Ideas:

 

  1. I've read through the handy USB communication nuggets (here and here) and though I can't say I am learned enough of a gentleman to wholly understand them, they DID give me the idea that perhaps instead of a interrupt event, I could use a VISA USB Control In function to grab data on demand.  Nugget #2 describes the warlock-ery (i.e. hex values and whatnot to input) required for the VISA USB Control In vi to GET_DESCRIPTOR.    I've attached my simple VI for how I do this.  I haven't the foggiest idea of what values to provide to grab the X and Y velocities, though.
  2. This may be heresy to some of or you, but I have heard that there may be some device or other that converts the digital output of the mouse to analog signals that could then be simply recorded by my DAQ board.  This could also be achieved via some creative arduino-ing (i.e. arduino program to interpret digital trains from mouse, then output the interpreted X and Y velocities on its analog out ports).

I figure once I am able to set up "on-demand sampling", so to say, of the X and Y data, it will be a simple enough matter to tie this into the master clock of the larger system that the mouse recording will be a part of.  I'm looking forward to hearing what input and ideas y'all have.  Fire away!

 

Best,

zob

Download All
0 Kudos
Message 1 of 15
(4,257 Views)

Bumping in hope someone new will see it...

0 Kudos
Message 2 of 15
(4,223 Views)

Well I wrote the USB nuggets, so we'll just assume for the sake of the argument that I'm a learned gentleman (although I don't think anyone's ever called me that before).

 

HID works intermittantly.  If there's nothing to send, there's nothing sent.

 

You have two choices (at least) to get what you want.  One is putting in an inbetween layer catching the intermittent events but storing the last state and outputting into, say, a notifier at regular intervals.

 

The other choice is the USB command for Getting HID data.  This is meant only for initialisation purposes, but would also work as a way of polling the mouse.  Look up the HID documents for the data values needed for the communications packet.

 

Shane.

0 Kudos
Message 3 of 15
(4,217 Views)

The man himself!  Thanks for taking the time to respond.  I'll do some reading up on HID communication.  I'll likely have more questions, as I am wholly newb-ish at this.  In the meanwhile, can I keep the device as a VISA RAW device or should I reinstall as a regular HID mouse?

0 Kudos
Message 4 of 15
(4,210 Views)

I couldn't answer yesterday because the internet somewhere had a problem.  Some sites were OK but most were like in a time-warp....

 

Either way, here's the parameters for the control command to poll the HID.

 

USB Get report request.png

 

Shane.

Message 5 of 15
(4,193 Views)

Perhaps I am doing it wrong, but I keep getting I/O errors whenever I use my simple little program to try and communicate with the mouse (as setup as a VISA RAW device).  I would try reinstalling it as an HID device but for two reasons: (1) I do not want this mouse chip controller the cursor on screen and (2) I do not know how to initialize the HID device as a VISA resource (so I can use the VISA USB Control In vi).  Perhaps it would be too much to ask, but would you be able to provide an example (or a link to one), please?

0 Kudos
Message 6 of 15
(4,168 Views)

HID is just a device class.  It has a group of standard commands which the device will answer to.  The commands will work no matter which driver you use to interface with.  It's the DEVICE which is HID, the driver doesn't suddenly make the device HID or non-HID.  As such you can use the HID commands also over VISA RAW.

 

If you have trouble getting the packets set up right, look closer at my nuggets.... 😉

 

Shane

 

Ps You can still use VISA RAW, just use the data provided earlier to send the required packet to the device and you'll get the data you want.

Message 7 of 15
(4,164 Views)

Alright, now I understand the difference between a device class and its driver.  I have read your nuggets many times and somehow I am still doing something wrong.  I have tested with a GET_DESCRIPTOR command and it works.  It's just this GET_REPORT that is wrong.  Here are the values I'm inputting:

 

NameValue (input / final*)Format (on radix)Reasoning

Request Type:10100001 / 10100001 binarygiven in 7.2.1 of HID spec

Request:0x01 / 1hexfrom top of pg 51 of HID spec

Value:010 / 10binary7.2.1 of HID spec; report type is input (01) + report ID (0)  <---don't think report ID is used?

Index0 / 0decimalfor default

length18 / 0decimalfirst length to test

 

*by final I mean what it appears as when you input it into LV


But no dice with these values.  I've also attached the sheet for the chip I'm working with for reference.

0 Kudos
Message 8 of 15
(4,152 Views)

Report ID is only used if the device returns more than one report which is normally not the case with a mouse.  In this case DO NOT add a value for report ID.

 

What error are you getting when sending the request, and can you show a screenshot of your call? Or attach a VI?

 

Shane.

 

PS According to 5.2.2 of your PDF your report is only 4 bytes long... Why ask for 18?

Message 9 of 15
(4,144 Views)

I didn't read the whole thread, but after a quick glance I didn't see any reference to the following options, which should be simpler:

 

  1. Use the mouse input VIs. They should return the mouse position all the time, which I understand is what you want.
    Caveats: They would require polling and I think they're only available on Windows and LV full or better.
  2. Use a mouse move event.
    Caveats: You might get too many events, so you will need to filter them (although you have this issue now as well). Will only work if the VI has focus and your mouse is over it.

___________________
Try to take over the world!
0 Kudos
Message 10 of 15
(4,141 Views)