BlazorSerial is a library that wraps the serial API in chrome based browsers check it here
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();
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!");
}
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.