Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python kinect control packet replay code
# some example code from pyusb, otherwise its all public domain. enjoy & keep hackin! - ladyada
import sys
# sys.path.append('/Users/qdot/git-projects/library/usr_darwin_10.5_x86/lib/python2.6/site-packages')
import usb.core
import usb.util
import sys
import time
# find our device
# dev = usb.core.find(idVendor=0x045e, idProduct=0x02B0)
dev = usb.core.find(idVendor=0x045e, idProduct=0x02ae)
# was it found?
if dev is None:
raise ValueError('Device not found')
for cfg in dev:
sys.stdout.write("Configuration #"+str(cfg.bConfigurationValue) + '\n')
for intf in cfg:
sys.stdout.write('\tInterface #' + \
str(intf.bInterfaceNumber) + \
'\t, Alternate setting ' + \
str(intf.bAlternateSetting) + \
'\n')
sys.stdout.write("\tEndpoints:\n")
for ep in intf:
sys.stdout.write('\t\t' + \
str(ep.bEndpointAddress) + \
'\n')
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
# test of reading data from different request #
#bRequest = 8 # or 8 or 9
#for i in range(255):
# try:
# ret = dev.ctrl_transfer(0x80, bRequest, i, 0, 4)
# print i,
# print ret
# except:
# # failed to get data for this request
# pass
# (bmRequestType, bmRequestType, bmRequest, wValue, wIndex, nBytes)
# ret = dev.ctrl_transfer(0x47, 0x4D, 0x0, 0x0, [0x0, 0x0, 0x0, 0x0])
# print ret # should return 0x22 but dont know why ?
ret = dev.ctrl_transfer(0x40, 0x00, 0x00, 0x00, [0x47, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00])
print ret # should return 0x22 but dont know why ?
ret = dev.ctrl_transfer(0xC0, 0x00, 0x00, 0x00, 28)
print map(hex, ret)
ret = dev.ctrl_transfer(0x40, 0x00, 0x00, 0x00, [0x47, 0x4D, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00])
print ret # should return 0x22 but dont know why ?
ret = dev.ctrl_transfer(0xC0, 0x00, 0x00, 0x00, 12)
print map(hex, ret)
ret = dev.ctrl_transfer(0x40, 0x00, 0x00, 0x00, [0x47, 0x4D, 0x04, 0x00, 0x94, 0x00, 0x03, 0x00, 0x25,0x20,0x01,0x01,0xff,0xff,0xff,0xff])
print ret # should return 0x22 but dont know why ?
ret = dev.ctrl_transfer(0xC0, 0x00, 0x00, 0x00, 12)
while len(ret) == 0:
ret = dev.ctrl_transfer(0xC0, 0x00, 0x00, 0x00, 12)
print map(hex, ret)
@ramana106
Copy link

ramana106 commented Mar 9, 2016

Can anyone tell the command to change the resolution of the kinect sensor using pyusb..
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment