-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(OpcDa): add OpcDa lib #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
01c42a2
chore: 增加 OpcUa 工程
ArgoZhang 38fc7e9
feat: 增加扩展服务
ArgoZhang 18eb880
test: 增加单元测试
ArgoZhang f07957c
test: 增加测试工程
ArgoZhang e040600
feat: 增加基金会 OpcDa 组件
ArgoZhang 6c20386
chore: 增加 OpcDa 工程
ArgoZhang 61eea9e
refactor: 重构扩展方法
ArgoZhang d633fa3
chore: 更新依赖包
ArgoZhang 996851d
feat: 新增 OpcItemEqualityComparer 比较器
ArgoZhang ab5bb23
refactor: 精简代码
ArgoZhang 5723e03
test: 更新单元测试
ArgoZhang 459473c
feat: 增加 Opc 服务
ArgoZhang 0911d5d
test: 更新单元测试
ArgoZhang 026fbad
refactor: 增加 OpcWriteItem 类
ArgoZhang 2480fdf
test: 增加单元测试
ArgoZhang d2b6bce
feat: 实现订阅数据回调功能
ArgoZhang 83a020c
test: 增加单元测试
ArgoZhang e9f00c3
refactor: 更改为 Action 回调
ArgoZhang a6118e5
test: 更新单元测试
ArgoZhang a148f11
chore: 增加依赖
ArgoZhang acf7bda
chore: 增加 targets 脚本
ArgoZhang 6a5dfea
chore: 增加打包配置
ArgoZhang 9a4f3f7
chore: 更改 dll 包路径
ArgoZhang 8aa2ee0
Merge branch 'master' into feat-opc-ua
ArgoZhang 758ee79
revert: 撤销包源更新
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/components/BootstrapBlazor.OpcUa/BootstrapBlazor.OpcUa.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
|
||
| <PropertyGroup> | ||
| <Version>9.0.1</Version> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Opc Ua Client</PackageTags> | ||
| <Description>Bootstrap UI components extensions of OpcUa</Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BootstrapBlazor" Version="$(BBVersion)" /> | ||
| <PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.5.376.235" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="BootstrapBlazor.Components" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
21 changes: 21 additions & 0 deletions
21
src/components/BootstrapBlazor.OpcUa/Extensions/ServiceCollectionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| /// <summary> | ||
| /// OpcUa 服务扩展类 | ||
| /// </summary> | ||
| public static class ServiceCollectionExtensions | ||
| { | ||
| /// <summary> | ||
| /// 增加 OpcUa 数据服务 | ||
| /// </summary> | ||
| /// <param name="services"></param> | ||
| /// <returns></returns> | ||
| public static IServiceCollection AddBootstrapBlazorOpcUaService(this IServiceCollection services) | ||
| { | ||
| return services; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @using Microsoft.AspNetCore.Components.Web |
51 changes: 51 additions & 0 deletions
51
src/extensions/BootstrapBlazor.OpcDa/BootstrapBlazor.OpcDa.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <Version>9.0.0-beta01</Version> | ||
| <RootNamespace>BootstrapBlazor.OpcDa</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <PackageTags>Bootstrap Blazor WebAssembly wasm UI Components SqlSugar</PackageTags> | ||
| <Description>Bootstrap UI components extensions of SqlSugar</Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFramework)' == 'net6.0'"> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.*" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFramework)' == 'net7.0'"> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.*" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFramework)' == 'net8.0'"> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.*" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFramework)' == 'net9.0'"> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.*" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="lib\OpcComRcw.dll" Pack="true" PackagePath="lib\net6.0" /> | ||
| <None Include="lib\OpcNetApi.dll" Pack="true" PackagePath="lib\net6.0" /> | ||
| <None Include="lib\OpcNetApi.Com.dll" Pack="true" PackagePath="lib\net6.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="OpcComRcw" HintPath="lib\OpcComRcw.dll" Private="true" PackageCopyToOutput="true" /> | ||
| <Reference Include="OpcNetApi" HintPath="lib\OpcComRcw.dll" Private="true" PackageCopyToOutput="true" /> | ||
| <Reference Include="OpcNetApi.Com" HintPath="lib\OpcComRcw.dll" Private="true" PackageCopyToOutput="true" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="build\*.targets" PackagePath="build" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Remove="BootstrapBlazor.Components" /> | ||
| <Using Remove="Microsoft.AspNetCore.Components" /> | ||
| <Using Remove="Microsoft.Extensions.DependencyInjection" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
23 changes: 23 additions & 0 deletions
23
src/extensions/BootstrapBlazor.OpcDa/Extensions/Extensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.OpcDa; | ||
|
|
||
| /// <summary> | ||
| /// 扩展方法类 | ||
| /// </summary> | ||
| internal static class Extensions | ||
| { | ||
| public static Quality ToQuality(this Opc.Da.Quality quality) | ||
| { | ||
| return quality.QualityBits == Opc.Da.qualityBits.good | ||
| ? Quality.Good | ||
| : Quality.Bad; | ||
| } | ||
|
|
||
| public static ISubscription ToOpcSubscription(this Opc.Da.ISubscription subscription) | ||
| { | ||
| return new OpcSubscription(subscription); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/extensions/BootstrapBlazor.OpcDa/Extensions/ServiceCollectionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| using BootstrapBlazor.OpcDa; | ||
| using System.Runtime.Versioning; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| /// <summary> | ||
| /// Opc Da 服务扩展类 | ||
| /// </summary> | ||
| public static class ServiceCollectionExtensions | ||
| { | ||
| /// <summary> | ||
| /// 增加 Opc 操作服务 | ||
| /// </summary> | ||
| /// <param name="services"></param> | ||
| /// <returns></returns> | ||
| [SupportedOSPlatform("windows")] | ||
| public static IServiceCollection AddOpcServer(this IServiceCollection services) | ||
| { | ||
| services.AddSingleton<IOpcServer, OpcServer>(); | ||
| return services; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.OpcDa; | ||
|
|
||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| public interface IOpcItem | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| string Name { get; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.OpcDa; | ||
|
|
||
| /// <summary> | ||
| /// Opc Server 接口定义 | ||
| /// </summary> | ||
| public interface IOpcServer : IDisposable | ||
| { | ||
| /// <summary> | ||
| /// 获得 OPC Server 是否已连接 | ||
| /// </summary> | ||
| bool IsConnected { get; } | ||
|
|
||
| /// <summary> | ||
| /// 获得 OPC Server 名称 | ||
| /// </summary> | ||
| string? ServerName { get; } | ||
|
|
||
| /// <summary> | ||
| /// 连接到 OPC Server 方法 | ||
| /// </summary> | ||
| /// <param name="serverName"></param> | ||
| /// <returns></returns> | ||
| bool Connect(string serverName); | ||
|
|
||
| /// <summary> | ||
| /// 断开连接方法 | ||
| /// </summary> | ||
| void Disconnect(); | ||
|
|
||
| /// <summary> | ||
| /// 取消订阅方法 | ||
| /// </summary> | ||
| /// <param name="subscription"></param> | ||
| void CancelSubscription(ISubscription subscription); | ||
|
|
||
| /// <summary> | ||
| /// 创建订阅方法 | ||
| /// </summary> | ||
| /// <param name="name">订阅名称</param> | ||
| /// <param name="updateRate">更新频率 默认 1000 毫秒</param> | ||
| /// <param name="active">是否激活 默认 true</param> | ||
| /// <returns></returns> | ||
| ISubscription CreateSubscription(string name, int updateRate = 1000, bool active = true); | ||
|
|
||
| /// <summary> | ||
| /// 读取 Item 值方法 | ||
| /// </summary> | ||
| /// <param name="items"></param> | ||
| /// <returns></returns> | ||
| HashSet<OpcReadItem> Read(params HashSet<string> items); | ||
|
|
||
| /// <summary> | ||
| /// 读取 Item 值方法 | ||
| /// </summary> | ||
| /// <param name="items"></param> | ||
| /// <returns></returns> | ||
| HashSet<OpcWriteItem> Write(params HashSet<OpcWriteItem> items); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.OpcDa; | ||
|
|
||
| /// <summary> | ||
| /// 订阅接口定义 | ||
| /// </summary> | ||
| public interface ISubscription | ||
| { | ||
| /// <summary> | ||
| /// 获得/设置 是否保留最后一个值 | ||
| /// </summary> | ||
| public bool KeepLastValue { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 数据变更回调 | ||
| /// </summary> | ||
| Action<List<OpcReadItem>>? DataChanged { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得 <see cref="Opc.Da.ISubscription"/> 实例 | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| Opc.Da.ISubscription GetSubscription(); | ||
|
|
||
| /// <summary> | ||
| /// 增加数据项 | ||
| /// </summary> | ||
| /// <param name="items"></param> | ||
| void AddItems(IEnumerable<string> items); | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/extensions/BootstrapBlazor.OpcDa/OpcItemEqualityComparer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.OpcDa; | ||
|
|
||
| /// <summary> | ||
| /// <see cref="IOpcItem"/> 比较器 | ||
| /// </summary> | ||
| public class OpcItemEqualityComparer<TItem> : IEqualityComparer<TItem> where TItem : IOpcItem | ||
| { | ||
| /// <summary> | ||
| /// 获得 <see cref="OpcItemEqualityComparer{TItem}"/> 实例 | ||
| /// </summary> | ||
| public static OpcItemEqualityComparer<TItem> Default { get; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| /// <param name="x"></param> | ||
| /// <param name="y"></param> | ||
| /// <returns></returns> | ||
| public bool Equals(TItem? x, TItem? y) => x?.Name == y?.Name; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| /// <param name="item"></param> | ||
| /// <returns></returns> | ||
| public int GetHashCode([DisallowNull] TItem item) => item.Name.GetHashCode(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.OpcDa; | ||
|
|
||
| /// <summary> | ||
| /// OPC Item 读取实体类 | ||
| /// </summary> | ||
| public record struct OpcReadItem(string Name, Quality Quality, DateTime Timestamp, object? Value) : IOpcItem | ||
| { | ||
| /// <summary> | ||
| /// 获得 Opc Item 上次值 | ||
| /// </summary> | ||
| public object? LastValue { get; set; } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: GetHashCode does not handle null Name property.
Add a null check for Name or enforce that Name cannot be null to prevent NullReferenceException.