Skip to content

Commit 8eed2b8

Browse files
committed
doc: 更新示例
1 parent c80b64c commit 8eed2b8

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/BootstrapBlazor.Server/Components/Samples/WebSerials.razor

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ private ISerialService? SerialService { get; set; }</Pre>
6767
<div class="col-12">
6868
<Button IsDisabled="CheckClose" OnClick="Write" Text="@Localizer["WriteButtonText"]"></Button>
6969
</div>
70+
<div class="col-12 col-sm-6">
71+
<Checkbox Value="_ring" ShowAfterLabel="true" DisplayText="RING"></Checkbox>
72+
<Checkbox Value="_dsr" ShowAfterLabel="true" DisplayText="DSR" class="ms-3"></Checkbox>
73+
</div>
74+
<div class="col-12 col-sm-6">
75+
<Checkbox Value="_cts" ShowAfterLabel="true" DisplayText="CTS"></Checkbox>
76+
<Checkbox Value="_dcd" ShowAfterLabel="true" DisplayText="DCD" class="ms-3"></Checkbox>
77+
</div>
78+
<div class="col-12">
79+
<Button IsDisabled="CheckClose" OnClick="GetSignals" Text="@Localizer["GetSignalsButtonText"]"></Button>
80+
</div>
81+
<div class="col-12 col-sm-6">
82+
<Display Value="@_usbInfo?.UsbVendorId" ShowLabel="true" DisplayText="VendorId"></Display>
83+
</div>
84+
<div class="col-12 col-sm-6">
85+
<Display Value="@_usbInfo?.UsbProductId" ShowLabel="true" DisplayText="ProductId"></Display>
86+
</div>
87+
<div class="col-12">
88+
<Button IsDisabled="CheckClose" OnClick="GetInfo" Text="@Localizer["GetInfoButtonText"]"></Button>
89+
</div>
7090
</div>
7191
</GroupBox>
7292
</DemoBlock>
@@ -90,7 +110,7 @@ if (SerialService.IsSupport == false)
90110

91111
<ul class="ul-demo">
92112
<li>如果需要读取数据,请先设置 <code>ISerialPort</code> 实例 <code>DataReceive</code> 参数</li>
93-
<li>调用 <code>ISerialPort</code> 实例方法 <code>Open</code> 打开串口,可通过参数设置 <code>波特率</code> 等信息</li>
113+
<li>调用 <code>ISerialPort</code> 实例方法 <code>Open</code> 打开串口,可通过 <code>SerialPortOptions</code> 参数设置 <code>波特率</code> 等信息</li>
94114
</ul>
95115

96116
<Pre>private async Task OpenPort()

src/BootstrapBlazor.Server/Components/Samples/WebSerials.razor.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public partial class WebSerials : IAsyncDisposable
4848

4949
private ISerialPort? _serialPort;
5050

51-
private readonly SerialOptions _serialOptions = new();
51+
private readonly SerialPortOptions _serialOptions = new();
5252

5353
private bool CheckOpen => _serialPort is not { IsOpen: false };
5454

@@ -149,6 +149,38 @@ private static byte[] ConvertToHex(string data)
149149
return [.. ret];
150150
}
151151

152+
private SerialPortSignals? _signals;
153+
154+
private bool _ring => _signals?.RING ?? false;
155+
156+
private bool _dsr => _signals?.DSR ?? false;
157+
158+
private bool _dcd => _signals?.DCD ?? false;
159+
160+
private bool _cts => _signals?.CTS ?? false;
161+
162+
private async Task GetSignals()
163+
{
164+
if (_serialPort == null)
165+
{
166+
return;
167+
}
168+
169+
_signals = await _serialPort.GetSignals();
170+
}
171+
172+
private SerialPortUsbInfo? _usbInfo;
173+
174+
private async Task GetInfo()
175+
{
176+
if (_serialPort == null)
177+
{
178+
return;
179+
}
180+
181+
_usbInfo = await _serialPort.GetUsbInfo();
182+
}
183+
152184
private async ValueTask DisposeAsync(bool disposing)
153185
{
154186
if (disposing)

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6323,7 +6323,9 @@
63236323
"NotSupportSerialTitle": "Get Port",
63246324
"NotSupportSerialContent": "The current browser does not support serial port operations. Please change to Edge or Chrome browser.",
63256325
"OpenPortSerialTitle": "Open Port",
6326-
"OpenPortSerialContent": "Failed to open the serial port"
6326+
"OpenPortSerialContent": "Failed to open the serial port",
6327+
"GetSignalsButtonText": "Signals",
6328+
"GetInfoButtonText": "Infos"
63276329
},
63286330
"BootstrapBlazor.Server.Components.Samples.MindMaps": {
63296331
"MindMapTitle": "Mind Map",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6323,7 +6323,9 @@
63236323
"NotSupportSerialTitle": "申请串口权限",
63246324
"NotSupportSerialContent": "当前浏览器不支持串口操作,请更换 Edge 或者 Chrome 浏览器",
63256325
"OpenPortSerialTitle": "打开串口操作",
6326-
"OpenPortSerialContent": "打开串口失败"
6326+
"OpenPortSerialContent": "打开串口失败",
6327+
"GetSignalsButtonText": "串口参数",
6328+
"GetInfoButtonText": "USB 信息"
63276329
},
63286330
"BootstrapBlazor.Server.Components.Samples.MindMaps": {
63296331
"MindMapTitle": "Mind Map 思维导图",

0 commit comments

Comments
 (0)