Blazor-BlazorSerial

[删除(380066935@qq.com或微信通知)]

BlazorSerial

jasniec/BlazorSerial (github.com)

BlazorSerial is a library that wraps the serial API in chrome based browsers check it here

Installation

Use the package manager to install BlazorSerial.

PM> Install-Package BlazorSerial

Or add nuget instead

Then, in your index file (wwwroot/index.html) add a line at the bottom of the body

<script src="_content/BlazorSerial/blazorSerial.js"></script>

And register dependency in Program.cs file

builder.Services.AddBlazorSerial();

Usage

To write text to the serial port, you have to ask user to choose a port, if successfully chosen, you have to connect and then send some text.

@inject ISerialPort Serial

// ...

@code{
private async Task WriteHelloWorld()
{
    if (await Serial.RequestPort() == BlazorSerial.Enums.RequestPortResponseEnum.Ok
     && await Serial.Open(115200) == BlazorSerial.Enums.ConnectResponseEnum.Ok)
    {
        await Serial.Write("Hello World!");
    }
}