Skip to content

Latest commit

 

History

History
52 lines (35 loc) · 1.25 KB

README.md

File metadata and controls

52 lines (35 loc) · 1.25 KB

BlazorSerial

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!");
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT