https://github.com/blazorextensions/webusb
HTML5 WebUSB APIs for Microsoft ASP.Net Core Blazor
https://github.com/blazorextensions/webusb
Last synced: 10 months ago
JSON representation
HTML5 WebUSB APIs for Microsoft ASP.Net Core Blazor
- Host: GitHub
- URL: https://github.com/blazorextensions/webusb
- Owner: BlazorExtensions
- License: mit
- Created: 2018-10-22T23:38:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-23T15:38:20.000Z (almost 3 years ago)
- Last Synced: 2025-04-19T23:20:08.120Z (11 months ago)
- Language: C#
- Size: 342 KB
- Stars: 78
- Watchers: 6
- Forks: 27
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Canvas
HTML5 WebUSB API implementation for Microsoft Blazor
[](https://github.com/BlazorExtensions/WebUSB/actions)
[](https://www.nuget.org/packages/Blazor.Extensions.WebUSB)
[](https://www.nuget.org/packages/Blazor.Extensions.WebUSB)
[](https://github.com/BlazorExtensions/WebUSB/blob/master/LICENSE)
# Blazor Extensions
Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net).
# Blazor Extensions WebUSB
This package wraps [HTML5 WebUSB](https://wicg.github.io/webusb/) APIs.
# Installation
```
Install-Package Blazor.Extensions.WebUSB
```
# Sample
## Usage
- First add the USB services on Blazor `IServiceCollection`:
```c#
public void ConfigureServices(IServiceCollection services)
{
services.UseWebUSB(); // Makes IUSB available to the DI container
}
```
### To consume on your `.cshtml`:
- On your `_ViewImports.cshtml` add the using entry:
```c#
@using Blazor.Extensions.WebUSB
```
- Then, on your `.cshtml` inject the `IUSB`:
```c#
@inject IUSB usb
```
And then use the `usb` object to interact with connected USB devices thru your Blazor application.
### To inject on a `BlazorComponent` class:
Define a property of type `IUSB` and mark it as `[Injectable]`:
```c#
[Inject] private IUSB _usb { get; set; }
```
Then use the `_usb` variable to interact with the connected USB devices.
**Note**: For now, you have to call `await IUSB.Initialize()` once in your application. This is a temporary requirement and we are looking on a better way to automatically register to _Connect/Disconnect_ events.
# Contributions and feedback
Please feel free to use the component, open issues, fix bugs or provide feedback.
# Contributors
The following people are the maintainers of the Blazor Extensions projects:
- [Attila Hajdrik](https://github.com/attilah)
- [Gutemberg Ribiero](https://github.com/galvesribeiro)