-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about get input and send output from my custom USB device. #66
Comments
Seems this quite excessive:
send_list = [0xFF]*1101
That'd cause to create a list of more than 1kB for your output report.
For the input report check the examples. Input reports are
asynchronous, only feature reports can be polled.
You need to prepare a handler (callback) to receive the input reports.
…On Mon, Aug 24, 2020 at 11:36 PM zhji2822 ***@***.***> wrote:
Here are my codes:
import pywinusb.hid as hid
from ctypes import *
class hidHelper(object):
def __init__(self, vid=0x0483, pid=0xa005):
self.alive = False
self.device = None
self.report = None
self.vid = vid
self.pid = pid
def start(self):
_filter = hid.HidDeviceFilter(vendor_id = self.vid, product_id = self.pid)
hid_device = _filter.get_devices()
if len(hid_device) > 0:
self.device = hid_device[0]
self.device.open()
self.out_report = self.device.find_output_reports()
self.in_report = self.device.find_input_reports()
self.alive = True
def stop(self):
self.alive = False
if self.device:
self.device.close()
if __name__ == '__main__':
myhid = hidHelper()
myhid.start()
input_interrupt_transfers = False
if myhid.alive:
send_list = [0xFF]*1101
send_list[0] = 0xfd
myhid.out_report[0].send(send_list)
myhid.in_report[0].get()
import time
time.sleep(0.5)
myhid.stop()
I used bus hound to monitor the communication. I get output that PC sent
to the device with full 0xFF and 0xFD in the first place twice, and I only
expect once. Then there are response from my USB device but my code can not
get that, is there any thing wrong with my code? @rene-aguirre
<https://github.com/rene-aguirre> Thank you for your time!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#66>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAF3G7VDJVSDM2BT4IMCBJDSCNLYVANCNFSM4QKJEIVA>
.
|
Thank you for your help! I am afraid that I cannot change size of the input and output report size since it is fixed for the device I am communicating with. And for the handler part, do you mean use function that is written in core.py to define a handler for input report? it is copied below:
|
It works! But I got duplicated output and input during the communication. I used bus hound for monitoring and it is shown in the image. Is this because of some default setting? that I need to change? I also uploaded my edited code below.
|
The monitor shows you report is only 100 byte long, this shows there is
something wrong with your descriptor.
Usually the report size limit is the endpoint transfer size limit.
Remove the .get() is not required.
…On Wed, Aug 26, 2020 at 6:28 PM zhji2822 ***@***.***> wrote:
It works! But I got duplicated output and input during the communication.
I used bus hound for monitoring and it is shown in the image. Is this
because of some default setting? that I need to change? I also uploaded my
edited code below.
[image: Capture]
<https://user-images.githubusercontent.com/28940774/91372846-5edbb300-e847-11ea-8945-9bb26ffc6fa2.PNG>
import pywinusb.hid as hid
import time
class hidHelper(object):
def __init__(self, vid=0x0483, pid=0xa005):
self.alive = False
self.device = None
self.report = None
self.vid = vid
self.pid = pid
def setcallback(self):
'''
设置接收数据回调函数
'''
if self.device:
self.device.set_raw_data_handler(self.read)
def read(self, data):
'''
接收数据回调函数
'''
print([hex(item).upper() for item in data[1:]])
def start(self):
'''
开始,打开HID设备
'''
_filter = hid.HidDeviceFilter(vendor_id = self.vid, product_id = self.pid)
hid_device = _filter.get_devices()
if len(hid_device) > 0:
self.device = hid_device[0]
self.device.open()
self.setcallback()
self.out_report = self.device.find_output_reports()
self.in_report = self.device.find_input_reports()
self.alive = True
def stop(self):
'''
停止,关闭HID设备
'''
self.alive = False
if self.device:
self.device.close()
if __name__ == '__main__':
myhid = hidHelper()
myhid.start()
input_interrupt_transfers = False
if myhid.alive:
send_list = [0xFF]*1101
send_list[0] = 0xfd
myhid.out_report[0].send(send_list)
myhid.in_report[0].get()
time.sleep(0.5)
myhid.stop()
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#66 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAF3G7STTDJVGR3PFVR6E6DSCWZE3ANCNFSM4QKJEIVA>
.
|
Here are my codes:
I used bus hound to monitor the communication. I get output that PC sent to the device with full 0xFF and 0xFD in the first place twice, and I only expect once. Then there are response from my USB device but my code can not get that, is there any thing wrong with my code? @rene-aguirre @j3hyde @c1728p9 @ElectricRCAircraftGuy Thank you for your time!
The text was updated successfully, but these errors were encountered: