pyspacenavigator
pyspacenavigator copied to clipboard
No Devices Found
My test script
import spacenavigator
from time import strftime as now, sleep
FORMAT = '%Y-%m-%d %H:%M:%S'
devs = spacenavigator.list_devices()
print(devs)
while devs:
success = spacenavigator.open()
if success:
while True:
state = spacenavigator.read()
print("\r" + now(FORMAT), state, end='')
else:
print("\r" + now(FORMAT), 'waiting for space navigator', end='')
sleep(1)
else:
print("No Devices Found")
outputs:
[]
No Devices Found
Process finished with exit code 0
Even though the device is visible in Windows Device Manager:
With a different script I have, using pywinusb.hid, the 3Dconnexion SpaceMouse is listed, can be selected and will output button and movement data.
import pywinusb.hid as hid
from time import strftime as now, sleep
from msvcrt import kbhit
FORMAT = '%Y-%m-%d %H:%M:%S'
def sample_handler(data):
global millis_last
print("\r\x1b[K" + now(FORMAT) + " Raw data: {0:}".format(data), end='')
deviceslist = hid.HidDeviceFilter().get_devices()
print(' i par ser ven prd ver name')
devindex = 0
devicesdict = {}
millis_last = 0
for dev in deviceslist:
hashval = hash(dev.serial_number + ''.join(map(str, [dev.vendor_id, dev.product_id, dev.version_number])))
if not dev.product_name.startswith('@') and hashval not in devicesdict:
devicesdict[hashval] = {'device': dev, 'index': devindex}
print("{0:> 3} {1:> 2} {2:>9} {3:04X} {4:04X} {5:04X} {6:}"
.format(devindex, dev.parent_instance_id, dev.serial_number, dev.vendor_id, dev.product_id,
dev.version_number, dev.product_name))
devindex += 1
selection = int(input("\nEnter id to select device (0-{})\n".format(devindex - 1)))
for key, val in devicesdict.items():
if val['index'] == selection:
device = val['device']
break
print("You have selected {}".format(device.product_name))
try:
device.open()
device.set_raw_data_handler(sample_handler)
print("\nWaiting for data...\nPress any (system keyboard) key to stop...")
while not kbhit() and device.is_plugged():
# just keep the device opened to receive events
sleep(0.5)
finally:
device.close()
Can I get some feedback about how I would proceed forward to make pyspacenavigator properly find the device?
At line line 261 I swapped from product id
0xC632
to
0xC631
there seems to be that SpaceMouse Pro Wireless comes with multiple product id's.
Output from the script mentioned in last comment here:
i par ser ven prd ver name
0 25 256F C652 0106 3Dconnexion Universal Receiver
3 33 256F C631 0441 SpaceMouse Pro Wireless
Take note of the product id.
Thanks for the investigation! I've updated with a commit that has an extra HID entry for 0xC631.
I also have an issue with list_devices returning an empty array. This is my output for the same pywinusb script:
i par ser ven prd ver name
0 12 1E7D 319C 0100 ROCCAT Isku
1 16 256F C62E 0441 SpaceMouse Wireless
Enter id to select device (0-1)
1
You have selected SpaceMouse Wireless
Waiting for data...
Press any (system keyboard) key to stop...
2023-12-17 23:07:30 Raw data: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]