File tree Expand file tree Collapse file tree 3 files changed +43
-5
lines changed
src/BootstrapBlazor.Server Expand file tree Collapse file tree 3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change 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.0 " />
63+ <PackageReference Include =" BootstrapBlazor.OpcDa" Version =" 9.0.1 " />
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" />
Original file line number Diff line number Diff line change 77
88<PackageTips Name =" BootstrapBlazor.OpcDa" />
99
10- <DemoBlock Title =" @Localizer[" OpcDaNormalTitle " ]" Introduction =" @Localizer[" OpcDaNormalIntro " ]" Name =" Normal" >
10+ <DemoBlock Title =" @Localizer[" OpcDaNormalTitle " ]" Introduction =" @Localizer[" OpcDaNormalIntro " ]" ShowCode = " false " Name =" Normal" >
1111 <p class =" code-label" >1. 点击 <b >连接</b > 按钮与 <code >OpcDa</code > 服务器建立通讯连接</p >
1212 <p >
1313 <BootstrapInputGroup >
4242
4343 <p class =" code-label" >3. 订阅功能</p >
4444 <p >通过订阅可以监控一组 <b >位号</b > 数据改变情况,当数据改变时通过 <code >DataChanged</code > 回调方法通知订阅者</p >
45- <div class =" row g-3" >
45+ <p class =" row g-3" >
4646 <div class =" col-12 col-sm-6" >
4747 <BootstrapInputGroup >
4848 <BootstrapInputGroupLabel DisplayText =" 订阅名称" ></BootstrapInputGroupLabel >
7373 <Button OnClick =" OnCreateSubscription" Text =" 订阅" IsDisabled =" @(!OpcDaServer.IsConnected || _subscribed)" ></Button >
7474 <Button OnClick =" OnCancelSubscription" Text =" 取消" IsDisabled =" !_subscribed" ></Button >
7575 </div >
76- </div >
76+ </p >
77+
78+ <p class =" code-label" >4. 浏览</p >
79+ <p >通过调用 <code >OpcDaServer</code > 的 <code >Browse</code > 方法可以构建一个节点树状结构</p >
80+ <p >
81+ <Button OnClick =" OnBrowse" Text =" 浏览" IsDisabled =" !OpcDaServer.IsConnected" ></Button >
82+ </p >
83+ <p >
84+ <TreeView Items =" _roots" AutoCheckChildren =" true" AutoCheckParent =" true" ShowIcon =" true"
85+ OnExpandNodeAsync =" OnExpandNodeAsync" ></TreeView >
86+ </p >
7787</DemoBlock >
Original file line number Diff line number Diff line change @@ -82,5 +82,33 @@ private void UpdateValues(List<OpcReadItem> items)
8282
8383 InvokeAsync ( StateHasChanged ) ;
8484 }
85- }
8685
86+ private List < TreeViewItem < OpcBrowseElement > > _roots = [ ] ;
87+
88+ private void OnBrowse ( )
89+ {
90+ var elements = OpcDaServer . Browse ( "" , new OpcBrowseFilters ( ) , out _ ) ;
91+ _roots = elements . Select ( element => new TreeViewItem < OpcBrowseElement > ( element )
92+ {
93+ Text = element . Name ,
94+ HasChildren = element . HasChildren ,
95+ Icon = "fa-solid fa-fw fa-cubes"
96+ } ) . ToList ( ) ;
97+ }
98+
99+ private Task < IEnumerable < TreeViewItem < OpcBrowseElement > > > OnExpandNodeAsync ( TreeViewItem < OpcBrowseElement > element )
100+ {
101+ var children = OpcDaServer . Browse ( element . Value . ItemName , new OpcBrowseFilters ( ) , out _ ) ;
102+ var items = children . Select ( i => new TreeViewItem < OpcBrowseElement > ( i )
103+ {
104+ Text = i . Name ,
105+ HasChildren = i . HasChildren ,
106+ Icon = i . HasChildren ? "fa-solid fa-fw fa-cube" : "fa-solid fa-fw fa-wrench"
107+ } ) ;
108+ if ( ! items . Any ( ) )
109+ {
110+ element . HasChildren = false ;
111+ }
112+ return Task . FromResult ( items ) ;
113+ }
114+ }
You can’t perform that action at this time.
0 commit comments