Skip to content

Commit 275043a

Browse files
authored
feat(OpcDa): bump version 9.0.3 (#6600)
* chore: bump version 9.0.3 * doc: 更新示例兼容 widows 平台
1 parent e6afb4f commit 275043a

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<PackageReference Include="BootstrapBlazor.OctIcon" Version="9.0.4" />
6161
<PackageReference Include="BootstrapBlazor.OfficeViewer" Version="9.0.0" />
6262
<PackageReference Include="BootstrapBlazor.OnScreenKeyboard" Version="9.0.1" />
63-
<PackageReference Include="BootstrapBlazor.OpcDa" Version="9.0.2" />
63+
<PackageReference Include="BootstrapBlazor.OpcDa" Version="9.0.3" />
6464
<PackageReference Include="BootstrapBlazor.PdfReader" Version="9.0.1" />
6565
<PackageReference Include="BootstrapBlazor.PdfViewer" Version="9.0.6" />
6666
<PackageReference Include="BootstrapBlazor.Player" Version="9.0.1" />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
<div class="col-12 col-sm-6">
5959
<BootstrapInputGroup>
6060
<BootstrapInputGroupLabel DisplayText="转速"></BootstrapInputGroupLabel>
61-
<BootstrapInputGroupLabel DisplayText="@Tag3"></BootstrapInputGroupLabel>
61+
<BootstrapInputGroupLabel DisplayText="@Tag1"></BootstrapInputGroupLabel>
6262
<Display @bind-Value="@_tagValue3"></Display>
6363
</BootstrapInputGroup>
6464
</div>
6565
<div class="col-12 col-sm-6">
6666
<BootstrapInputGroup>
6767
<BootstrapInputGroupLabel DisplayText="流速"></BootstrapInputGroupLabel>
68-
<BootstrapInputGroupLabel DisplayText="@Tag4"></BootstrapInputGroupLabel>
68+
<BootstrapInputGroupLabel DisplayText="@Tag2"></BootstrapInputGroupLabel>
6969
<Display @bind-Value="@_tagValue4"></Display>
7070
</BootstrapInputGroup>
7171
</div>

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using BootstrapBlazor.OpcDa;
7-
using System.Globalization;
87

98
namespace BootstrapBlazor.Server.Components.Samples;
109

@@ -17,12 +16,10 @@ public partial class OpcDa : ComponentBase
1716
[NotNull]
1817
private IOpcDaServer? OpcDaServer { get; set; }
1918

20-
private string? _serverName = "opcda://localhost/Kepware.KEPServerEX.V6/Mock";
19+
private string? _serverName = "opcda://localhost/Kepware.KEPServerEX.V6";
2120

2221
private const string Tag1 = "Channel1.Device1.Tag1";
2322
private const string Tag2 = "Channel1.Device1.Tag2";
24-
private const string Tag3 = "Channel1.Device1.Tag3";
25-
private const string Tag4 = "Channel1.Device1.Tag4";
2623

2724
private string? _tagValue1;
2825
private string? _tagValue2;
@@ -49,19 +46,25 @@ private void OnDisConnect()
4946

5047
private void OnRead()
5148
{
52-
var values = OpcDaServer.Read(Tag1, Tag2);
53-
_tagValue1 = values.ElementAt(0).Value?.ToString();
54-
55-
var v = (int)values.ElementAt(1).Value! / 100d;
56-
_tagValue2 = v.ToString(CultureInfo.InvariantCulture);
49+
var items = OpcDaServer.Read(Tag1, Tag2);
50+
var value1 = items.FirstOrDefault(i => i.Name == Tag1).Value;
51+
if (value1 != null)
52+
{
53+
_tagValue1 = value1.ToString();
54+
}
55+
var value2 = items.FirstOrDefault(i => i.Name == Tag2).Value;
56+
if (value2 != null)
57+
{
58+
_tagValue2 = value2.ToString();
59+
}
5760
}
5861

5962
private void OnCreateSubscription()
6063
{
6164
_subscribed = true;
6265
_subscription = OpcDaServer.CreateSubscription("Subscription1", 1000, true);
6366
_subscription.DataChanged += UpdateValues;
64-
_subscription.AddItems([Tag3, Tag4]);
67+
_subscription.AddItems([Tag1, Tag2]);
6568
}
6669

6770
private void OnCancelSubscription()
@@ -76,9 +79,16 @@ private void OnCancelSubscription()
7679

7780
private void UpdateValues(List<OpcReadItem> items)
7881
{
79-
_tagValue3 = items[0].Value?.ToString();
80-
var v = (int)items[1].Value! / 100d;
81-
_tagValue4 = v.ToString(CultureInfo.InvariantCulture);
82+
var value1 = items.Find(i => i.Name == Tag1).Value;
83+
if (value1 != null)
84+
{
85+
_tagValue3 = value1.ToString();
86+
}
87+
var value2 = items.Find(i => i.Name == Tag2).Value;
88+
if (value2 != null)
89+
{
90+
_tagValue4 = value2.ToString();
91+
}
8292

8393
InvokeAsync(StateHasChanged);
8494
}
@@ -88,12 +98,12 @@ private void UpdateValues(List<OpcReadItem> items)
8898
private void OnBrowse()
8999
{
90100
var elements = OpcDaServer.Browse("", new OpcBrowseFilters(), out _);
91-
_roots = elements.Select(element => new TreeViewItem<OpcBrowseElement>(element)
101+
_roots = [.. elements.Select(element => new TreeViewItem<OpcBrowseElement>(element)
92102
{
93103
Text = element.Name,
94104
HasChildren = element.HasChildren,
95105
Icon = "fa-solid fa-fw fa-cubes"
96-
}).ToList();
106+
})];
97107
}
98108

99109
private Task<IEnumerable<TreeViewItem<OpcBrowseElement>>> OnExpandNodeAsync(TreeViewItem<OpcBrowseElement> element)

0 commit comments

Comments
 (0)