Git Product home page Git Product logo

Comments (5)

rene-aguirre avatar rene-aguirre commented on August 29, 2024

from pywinusb.

zhji2822 avatar zhji2822 commented on August 29, 2024

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:

 def add_event_handler(self, full_usage_id, handler_function,
            event_kind = HID_EVT_ALL, aux_data = None):
        """Add event handler for usage value/button changes,
        returns True if the handler function was updated"""
        report_id = self.find_input_usage(full_usage_id)
        if report_id != None:
            # allow first zero to trigger changes and releases events
            self.__input_report_templates[report_id][full_usage_id].__value = None
        if report_id == None or not handler_function:
            # do not add handler
            return False
        assert(isinstance(handler_function, collections.Callable)) # must be a function
        # get dictionary for full usages
        top_map_handler = self.__evt_handlers.get(full_usage_id, dict())
        event_handler_set = top_map_handler.get(event_kind, dict())
        # update handler
        event_handler_set[handler_function] = aux_data
        if event_kind not in top_map_handler:
            top_map_handler[event_kind] = event_handler_set
        if full_usage_id not in self.__evt_handlers:
            self.__evt_handlers[full_usage_id] = top_map_handler
        return True

from pywinusb.

zhji2822 avatar zhji2822 commented on August 29, 2024

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.

Capture

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()

from pywinusb.

rene-aguirre avatar rene-aguirre commented on August 29, 2024

from pywinusb.

zhji2822 avatar zhji2822 commented on August 29, 2024

Thank you. I am confused about where did you get that my report is 100 byte long. if you got that by looking at the length of input/output data, you were mislead by my mistake. Sorry, to make fewer screening shots I limited the number of bytes bus hound show. and here are the complete screen shots. The actual data is 1101 bytes long but we can find it sent out same output data twice to the USB device. and I only have one send order.
1
2
3
4
5
6
7
8
9

from pywinusb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.