Blazor Client-side. Is it possible to access the Serial ports (COM) from browser?

Nikolay Renziglov 21 Reputation points
2021-02-15T14:33:26.077+00:00

Hi there
Is it possible to communicate to a Serial ports of a client machine making use of Blazor Client?
If yes, any clue or links?
Thanks

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,451 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Wang-MSFT 1,056 Reputation points
    2021-02-16T08:46:03.547+00:00

    Hi, @Nikolay Renziglov ,

    Blazor WebAssembly doesn't support to access local serial port on client. You will get the error below.

    68498-image.png

    It's danger and illegal for accessing the serial port from client side. You could try another approach:

    1. Write a Windows Service (I assume your machine runs Windows), configure it with necessary privileges. You will have to install something on the machine anyway. The service can be implemented in any language.
    2. Add HTTP(S) server capabilities to it and choose communication protocol over HTTP. You could use JSON, Ajax, WebSockets, SignalR, etc.
      · Send data byte from serial port to /.
      · Recieve command byte from serve to serial port .
    3. Build a web server to process the data with client.
    4. Create a front page to display your data and control it.

    ---
    If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Michael Wang


  2. John Flaherty 1 Reputation point
    2021-05-07T17:45:03.15+00:00

    You can in in Chrome since 89. Maybe chromium based but I haven't looked. See https://web.dev/serial/. You'll need to write js adaptors.

    0 comments No comments