|
1 | | -# Canvas |
2 | | -HTML5 WebUSB API implementation for Microsoft Blazor |
3 | | - |
4 | | -[](https://dotnet-ci.visualstudio.com/DotnetCI/_build/latest?definitionId=18&branch=master) |
5 | | -[](https://www.nuget.org/packages/Blazor.Extensions.WebUSB) |
6 | | -[](https://www.nuget.org/packages/Blazor.Extensions.WebUSB) |
7 | | -[](https://github.com/BlazorExtensions/WebUSB/blob/master/LICENSE) |
8 | | - |
9 | | -# Blazor Extensions |
10 | | - |
11 | | -Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net). |
12 | | - |
13 | | -# Blazor Extensions WebUSB |
14 | | - |
15 | | -This package wraps [HTML5 WebUSB](https://wicg.github.io/webusb/) APIs. |
16 | | - |
17 | | -# Installation |
18 | | - |
19 | | -``` |
20 | | -Install-Package Blazor.Extensions.WebUSB |
21 | | -``` |
22 | | - |
23 | | -# Sample |
24 | | - |
25 | | -## Usage |
26 | | - |
27 | | -- First add the USB services on Blazor `IServiceCollection`: |
28 | | - |
29 | | -```c# |
30 | | -public void ConfigureServices(IServiceCollection services) |
31 | | -{ |
32 | | - services.UseWebUSB(); // Makes IUSB available to the DI container |
33 | | -} |
34 | | -``` |
35 | | - |
36 | | -### To consume on your `.cshtml`: |
37 | | - |
38 | | -- On your `_ViewImports.cshtml` add the using entry: |
39 | | - |
40 | | -```c# |
41 | | -@using Blazor.Extensions.WebUSB |
42 | | -``` |
43 | | - |
44 | | -- Then, on your `.cshtml` inject the `IUSB`: |
45 | | - |
46 | | -```c# |
47 | | -@inject IUSB usb |
48 | | -``` |
49 | | - |
50 | | -And then use the `usb` object to interact with connected USB devices thru your Blazor application. |
51 | | - |
52 | | -### To inject on a `BlazorComponent` class: |
53 | | - |
54 | | -Define a property of type `IUSB` and mark it as `[Injectable]`: |
55 | | - |
56 | | -```c# |
57 | | -[Inject] private IUSB _usb { get; set; } |
58 | | -``` |
59 | | - |
60 | | -Then use the `_usb` variable to interact with the connected USB devices. |
61 | | - |
62 | | -**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. |
63 | | - |
64 | | -# Contributions and feedback |
65 | | - |
66 | | -Please feel free to use the component, open issues, fix bugs or provide feedback. |
67 | | - |
68 | | -# Contributors |
69 | | - |
70 | | -The following people are the maintainers of the Blazor Extensions projects: |
71 | | - |
72 | | -- [Attila Hajdrik](https://github.com/attilah) |
73 | | -- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
| 1 | +# Canvas |
| 2 | +HTML5 WebUSB API implementation for Microsoft Blazor |
| 3 | + |
| 4 | +[](https://github.com/BlazorExtensions/WebUSB/actions) |
| 5 | +[](https://www.nuget.org/packages/Blazor.Extensions.WebUSB) |
| 6 | +[](https://www.nuget.org/packages/Blazor.Extensions.WebUSB) |
| 7 | +[](https://github.com/BlazorExtensions/WebUSB/blob/master/LICENSE) |
| 8 | + |
| 9 | +# Blazor Extensions |
| 10 | + |
| 11 | +Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net). |
| 12 | + |
| 13 | +# Blazor Extensions WebUSB |
| 14 | + |
| 15 | +This package wraps [HTML5 WebUSB](https://wicg.github.io/webusb/) APIs. |
| 16 | + |
| 17 | +# Installation |
| 18 | + |
| 19 | +``` |
| 20 | +Install-Package Blazor.Extensions.WebUSB |
| 21 | +``` |
| 22 | + |
| 23 | +# Sample |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +- First add the USB services on Blazor `IServiceCollection`: |
| 28 | + |
| 29 | +```c# |
| 30 | +public void ConfigureServices(IServiceCollection services) |
| 31 | +{ |
| 32 | + services.UseWebUSB(); // Makes IUSB available to the DI container |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### To consume on your `.cshtml`: |
| 37 | + |
| 38 | +- On your `_ViewImports.cshtml` add the using entry: |
| 39 | + |
| 40 | +```c# |
| 41 | +@using Blazor.Extensions.WebUSB |
| 42 | +``` |
| 43 | + |
| 44 | +- Then, on your `.cshtml` inject the `IUSB`: |
| 45 | + |
| 46 | +```c# |
| 47 | +@inject IUSB usb |
| 48 | +``` |
| 49 | + |
| 50 | +And then use the `usb` object to interact with connected USB devices thru your Blazor application. |
| 51 | + |
| 52 | +### To inject on a `BlazorComponent` class: |
| 53 | + |
| 54 | +Define a property of type `IUSB` and mark it as `[Injectable]`: |
| 55 | + |
| 56 | +```c# |
| 57 | +[Inject] private IUSB _usb { get; set; } |
| 58 | +``` |
| 59 | + |
| 60 | +Then use the `_usb` variable to interact with the connected USB devices. |
| 61 | + |
| 62 | +**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. |
| 63 | + |
| 64 | +# Contributions and feedback |
| 65 | + |
| 66 | +Please feel free to use the component, open issues, fix bugs or provide feedback. |
| 67 | + |
| 68 | +# Contributors |
| 69 | + |
| 70 | +The following people are the maintainers of the Blazor Extensions projects: |
| 71 | + |
| 72 | +- [Attila Hajdrik](https://github.com/attilah) |
| 73 | +- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
0 commit comments