File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
src/BootstrapBlazor.Server/Components/Samples/SerialPorts Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ @page " /serial-port-factory"
2+ @inject IStringLocalizer <SerialPortFactories > Localizer
3+
4+ <h3 >SerialPort 串行通信服务 <code >ISerialPortFactory</code ></h3 >
5+ <h4 >组件库内置了 SerialPort 串口通信服务</h4 >
6+
7+ <PackageTips Name =" Longbow.SerialPort" />
8+
9+ <Tips ><div >特别注意:本服务不支持 <code >wasm</code > 模式</div ></Tips >
10+
11+ <p class =" code-label" >1. 服务注入</p >
12+
13+ <Pre >services.AddSerialPortFactory();</Pre >
14+
15+ <Pre >[Inject]
16+ [NotNull]
17+ private ISerialPortFactory? SerialPortFactory { get ; set ; } </Pre >
18+
19+ <p class =" code-label" >2. 使用服务</p >
20+ <p >调用 <code >SerialPortFactory</code > 实例方法 <code >GetOrCreate</code > 即可得到一个 <code >ISerialPortClient</code > 实例。内部提供复用机制,调用两次得到的 <code >ISerialPortClient</code > 为同一对象</p >
21+
22+ <p class =" code-label" >3. 通过工厂获得相对应协议 <code >ISerialPortClient</code > 实例</p >
23+
24+ <p ><code >ISerialPortFactory</code > 实例方法</p >
25+
26+ <ul class =" ul-demo" >
27+ <li >通过 <code >GetOrCreate</code > 获得 <code >ISerialPortClient</code > 实例</li >
28+ <li >通过 <code >Remove</code > 移除指定名称的 <code >ISerialPortClient</code > 实例</li >
29+ </ul >
30+
31+ <Pre >SerialPortFactory.Remove("test");</Pre >
32+
33+ <p >可以通过注入服务直接获得 <code >ISerialPortClient</code > 实例</p >
34+
35+ <Pre >[Inject]
36+ [NotNull]
37+ private ISerialPortClient? SerialPortClient { get ; set ; } </Pre >
38+
39+ <p ><code >ISerialPortClient</code > 实例方法</p >
40+
41+ <ul class =" ul-demo" >
42+ <li >打开端口方法 <code >OpenAsync</code ></li >
43+ <li >发送数据方法 <code >SendAsync</code ></li >
44+ <li >接收数据方法 <code >ReceiveAsync</code ></li >
45+ <li >关闭端口方法 <code >CloseAsync</code ></li >
46+ </ul >
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the Apache 2.0 License
3+ // See the LICENSE file in the project root for more information.
4+ // Maintainer: Argo Zhang([email protected] ) Website: https://www.blazor.zone 5+
6+ namespace BootstrapBlazor . Server . Components . Samples . SerialPorts ;
7+
8+ /// <summary>
9+ /// ISerialPortFactory 服务说明文档
10+ /// </summary>
11+ public partial class SerialPortFactories
12+ {
13+
14+ }
You can’t perform that action at this time.
0 commit comments