Git Product home page Git Product logo

Comments (1)

JakubAndrysek avatar JakubAndrysek commented on May 30, 2024

Something like this

import hidapi

def my_callback(device, data, length):
    print(f"Received {length} bytes of data: {data}")

# Open a HID device
handle = hidapi.hid_open_path(vendor_id=0x1234, product_id=0x5678, path="/dev/hidraw0")
if handle is None:
    print("Failed to open HID device")
else:
    # Register the callback function
    hidapi.hid_set_callback(handle, my_callback)

    # Write data to the device
    data = [0x01, 0x02, 0x03]
    num_bytes_written = hidapi.hid_write(handle, data, len(data))
    print(f"Wrote {num_bytes_written} bytes of data")

    # Read data from the device
    data = hidapi.hid_read(handle, 64)
    if data is None:
        print("Failed to read data from HID device")
    else:
        print(f"Read {len(data)} bytes of data: {data}")

    # Close the HID device
    hidapi.hid_close(handle)

from pyspacemouse.

Related Issues (8)

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.