Coder Social home page Coder Social logo

device.net's Introduction

Hid.Net, Usb.Net, SerialPort.Net (Device.Net)

diagram

Version 4 is going to be a big version. Check out the plan. Many enhancements including Reactive support, standard ILogger throughout, are already done and I'm in the middle of testing with more real devices with real apps. The framework is currently getting a thrashing with an app I'm working on. Pull Requests are super welcome!

Cross platform C# framework for talking to connected devices such as Usb, Serial Port and Hid devices.

This framework provides a common Task based Async interface across platforms and device types. This allows for dependency injection so that different types of devices can be used on any platform with the same code. The supported device types are Hid, Serial Port, and USB. Other device types such as Bluetooth and so on may be added in future. Hid.Net is specifically for Hid devices that may be Usb devices. Usb.Net is specifically for Usb devices that don't have a Hid interface. Please visit the documentation page. Would you you like to contribute?

Currently supports:

Platform Device Types
.NET Framework Hid, USB, Serial Port
.NET Core Hid, USB, Serial Port
Android USB
UWP Hid, USB
Linux, MacOS* USB (Via LibUsbDotNet)

Important! Before trying this code, see the above Quick Start

Example Code:

public async Task InitializeTrezorAsync()
{
    //Register the factories for creating Usb devices. This only needs to be done once.
    WindowsUsbDeviceFactory.Register(Logger, Tracer);
    WindowsHidDeviceFactory.Register(Logger, Tracer);

    //Define the types of devices to search for. This particular device can be connected to via USB, or Hid
    var deviceDefinitions = new List<FilterDeviceDefinition>
    {
        new FilterDeviceDefinition{ DeviceType= DeviceType.Hid, VendorId= 0x534C, ProductId=0x0001, Label="Trezor One Firmware 1.6.x" },
        new FilterDeviceDefinition{ DeviceType= DeviceType.Usb, VendorId= 0x1209, ProductId=0x53C1, Label="Trezor One Firmware 1.7.x" },
        new FilterDeviceDefinition{ DeviceType= DeviceType.Usb, VendorId= 0x1209, ProductId=0x53C0, Label="Model T" }
    };

    //Get the first available device and connect to it
    var devices = await DeviceManager.Current.GetDevicesAsync(deviceDefinitions);
    var trezorDevice = devices.FirstOrDefault();
    await trezorDevice.InitializeAsync();

    //Create a buffer with 3 bytes (initialize)
    var buffer = new byte[64];
    buffer[0] = 0x3f;
    buffer[1] = 0x23;
    buffer[2] = 0x23;

    //Write the data to the device and wait for the response
    var readBuffer = await trezorDevice.WriteAndReadAsync(buffer);
}

Donate

All my libraries are open source and free. Your donations will contribute to making sure that these libraries keep up with the latest firmware, functions are implemented, and the quality is maintained.

Coin Address
Bitcoin 33LrG1p81kdzNUHoCnsYGj6EHRprTKWu3U
Ethereum 0x7ba0ea9975ac0efb5319886a287dcf5eecd3038e
Litecoin MVAbLaNPq7meGXvZMU4TwypUsDEuU6stpY

Google Play

Windows Store

Contact

Store App Production Usage

Hardfolio - Cryptocurrency portfolio app for hardwarewallets. Hid.Net started its life as a project inside the Hardfolio app codebase. The original aim of this app was to support multiple hardwarewallets across multiple platforms. It turned out that Hid.Net and Usb.Net were warranted as libraries in their own right because there really is not other library on the internet that supports all the platforms that were needed for Hardfolio.

See Also

Human Interface Device Wikipedia Page - Good for understanding the difference between the meaning of the two terms: USB and Hid.

USB human interface device class Wikipedia Page - as above

USB Wikipedia Page - as above

Jax Axelson's USB Page - General C# USB Programming

device.net's People

Contributors

g9c9 avatar melbournedeveloper avatar www avatar

Watchers

 avatar

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.