Compare commits

...

15 Commits
2.0.1 ... 2.0.4

Author SHA1 Message Date
Kimdiego2098
f0fe1b23dc 更新2.0.4 2023-08-09 13:00:10 +08:00
Kimdiego2098
aaf2006401 更新opcua写入 2023-08-09 12:43:05 +08:00
Kimdiego2098
b821e26935 更新opcua调试页面 2023-08-09 12:01:23 +08:00
Kimdiego2098
7ae4287157 更新opcua 2023-08-09 11:47:04 +08:00
Kimdiego2098
c6fcc38a65 修复中间变量导入错误 2023-08-09 09:00:49 +08:00
Kimdiego2098
ab2d5c8853 修正错误注释 2023-08-08 18:09:23 +08:00
Kimdiego2098
5e557ff0bc opcua添加初始化连接错误重试 2023-08-08 18:04:24 +08:00
Kimdiego2098
918ca449a1 更新readme 2023-08-08 16:14:06 +08:00
Kimdiego2098
8e73368008 优化大量设备线程重启的耗时 2023-08-08 14:02:00 +08:00
Kimdiego2098
f3c1faf672 2.0.3 2023-08-08 12:59:14 +08:00
Kimdiego2098
d6df04dd6a 底层部分方法更改 2023-08-08 12:31:42 +08:00
Kimdiego2098
b1b9e51ab6 报警/历史值查询时区转换 2023-08-08 09:05:15 +08:00
Kimdiego2098
e49d4770ac 时间最小最大值时不再转换时区 2023-08-08 08:39:20 +08:00
Kimdiego2098
8fa1075511 Merge branch 'master' of https://gitee.com/dotnetchina/ThingsGateway 2023-08-08 08:28:37 +08:00
Kimdiego2098
9a70169b94 默认不启用单用户登录 2023-08-08 08:28:27 +08:00
66 changed files with 382 additions and 201 deletions

5
.gitignore vendored
View File

@@ -360,4 +360,7 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/framework/*Pro*

View File

@@ -5,12 +5,11 @@
**NetCore** 跨平台边缘采集网关(工业设备采集)
**ThingsGateway** 存储库同时提供 [**设备采集驱动**](https://www.nuget.org/profiles/KimDiego)
**ThingsGateway** 存储库同时提供 [**设备采集驱动**](https://www.nuget.org/packages?q=Tags%3A%22ThingsGateway%22)
**ThingsGateway** 存储库同时提供 **基于Blazor的权限框架** 查看 [**ThingsGateway.Admin**](https://gitee.com/dotnetchina/ThingsGateway/blob/master/framework/ThingsGateway.Admin.sln)
## 文档
[ThingsGateway](https://diego2098.gitee.io/thingsgateway-docs/) 文档。

View File

@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Version>2.0.0.0</Version>
<Version>2.0.4.0</Version>
<Authors>Diego</Authors>
<Product>ThingsGateway</Product>
<Copyright>© 2023-present Diego</Copyright>

View File

@@ -19,7 +19,7 @@ using ThingsGateway.Admin.Core;
namespace ThingsGateway.Admin.Application;
/// <summary>
/// 后台登录控制器
/// 文件下载
/// </summary>
[ApiDescriptionSettings(CateGoryConst.ThingsGatewayAdmin, Order = 200)]
[Route("file")]

View File

@@ -46,7 +46,7 @@ namespace ThingsGateway.Admin.Application
[AllowAnonymous, NonUnify]
public async Task<int> SwaggerCheckUrlAsync()
{
var enable = (await _configService.GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_SWAGGERLOGIN_OPEN)).ConfigValue.ToBool();
var enable = (await _configService.GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_SWAGGERLOGIN_OPEN)).ConfigValue.ToBoolean();
return enable ? 401 : 200;
}

View File

@@ -30,7 +30,7 @@
</member>
<member name="T:ThingsGateway.Admin.Application.FileController">
<summary>
后台登录控制器
文件下载
</summary>
</member>
<member name="M:ThingsGateway.Admin.Application.FileController.#ctor(ThingsGateway.Admin.Application.IFileService,ThingsGateway.Admin.Application.IOperateLogService,ThingsGateway.Admin.Application.IVisitLogService)">

View File

@@ -149,7 +149,7 @@ public class OpenApiAuthService : IOpenApiAuthService, ITransient
{
bool isSingle = false;//默认不开启单用户登录
var singleConfig = await _configService.GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_SINGLE_OPEN);//获取系统单用户登录选项
if (singleConfig != null) isSingle = singleConfig.ConfigValue.ToBool();//如果配置不为空则设置单用户登录选项为系统配置的值
if (singleConfig != null) isSingle = singleConfig.ConfigValue.ToBoolean();//如果配置不为空则设置单用户登录选项为系统配置的值
//判断是否单用户登录
if (isSingle)

View File

@@ -77,7 +77,7 @@
"Id": "22222222222232",
"Category": "SYS_CONFIGBASEDEFAULT",
"ConfigKey": "CONFIG_SINGLE_OPEN",
"ConfigValue": "true",
"ConfigValue": "false",
"Remark": "单用户登录开关",
"SortCode": "10",
"IsDelete": "false"

View File

@@ -79,7 +79,7 @@ public class AuthService : IAuthService
if (sysBase != null)//如果有这个配置项
{
if (sysBase.ConfigValue.ToBool())//如果需要验证码
if (sysBase.ConfigValue.ToBoolean())//如果需要验证码
{
//如果没填验证码,提示验证码不能为空
if (input.ValidCode.IsNullOrEmpty() || input.ValidCodeReqNo == 0) throw Oops.Bah("验证码不能为空").StatusCode(410);
@@ -217,7 +217,7 @@ public class AuthService : IAuthService
bool isSingle = false;//默认不开启单用户登录
var singleConfig = await _configService.GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_SINGLE_OPEN);//获取系统单用户登录选项
if (singleConfig != null) isSingle = singleConfig.ConfigValue.ToBool();//如果配置不为空则设置单用户登录选项为系统配置的值
if (singleConfig != null) isSingle = singleConfig.ConfigValue.ToBoolean();//如果配置不为空则设置单用户登录选项为系统配置的值
if (isSingle)//判断是否单用户登录
{
await _noticeService.LogoutAsync(loginEvent.SysUser.Id, verificatInfos.Where(it => it.Device == loginEvent.Device.ToString()).ToList(), "该账号已在别处登录!");//通知其他用户下线

View File

@@ -294,7 +294,7 @@ public partial class AppDateTimePicker
Value = dateTime;
if (ValueChanged.HasDelegate)
{
await ValueChanged.InvokeAsync(dateTime);
await ValueChanged.InvokeAsync(DateTime.SpecifyKind(dateTime.Value, DateTimeKind.Utc));
}
}

View File

@@ -133,7 +133,7 @@ public partial class Login
GetCaptchaInfo();
CONFIG_TITLE = (await App.GetService<IConfigService>().GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_TITLE))?.ConfigValue;
CONFIG_REMARK = (await App.GetService<IConfigService>().GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_REMARK))?.ConfigValue;
_showCaptcha = (await App.GetService<IConfigService>().GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_CAPTCHA_OPEN))?.ConfigValue?.ToBool() == true;
_showCaptcha = (await App.GetService<IConfigService>().GetByConfigKeyAsync(ConfigConst.SYS_CONFIGBASEDEFAULT, ConfigConst.CONFIG_CAPTCHA_OPEN))?.ConfigValue?.ToBoolean() == true;
Welcome = "欢迎使用" + CONFIG_TITLE + "!";
await base.OnParametersSetAsync();
}

View File

@@ -22,7 +22,7 @@ public class UserManager
/// <summary>
/// 是否超级管理员
/// </summary>
public static bool IsSuperAdmin => (App.User?.FindFirst(ClaimConst.IsSuperAdmin)?.Value).ToBool();
public static bool IsSuperAdmin => (App.User?.FindFirst(ClaimConst.IsSuperAdmin)?.Value).ToBoolean();
/// <summary>
/// 当前用户账号

View File

@@ -330,7 +330,7 @@ public static class ObjectExtensions
/// 转换布尔值
/// </summary>
/// <returns></returns>
public static bool ToBool(this object value, bool defaultValue = false) => value?.ToString().ToUpper() switch
public static bool ToBoolean(this object value, bool defaultValue = false) => value?.ToString().ToUpper() switch
{
"1" or "TRUE" => true,
_ => defaultValue,
@@ -356,10 +356,22 @@ public static class ObjectExtensions
{
return Double.IsNaN(d) ? defaultValue : (Decimal)d;
}
var str = value.ToString();
var str = value?.ToString();
return str.IsNullOrEmpty() ? defaultValue : Decimal.TryParse(str, out var n) ? n : defaultValue;
}
/// <summary>
/// ToDecimal
/// </summary>
/// <returns></returns>
public static double ToDouble(this object value, double defaultValue = 0)
{
if (value is Double d)
{
return Double.IsNaN(d) ? defaultValue : (Double)d;
}
var str = value?.ToString();
return str.IsNullOrEmpty() ? defaultValue : double.TryParse(str, out var n) ? n : defaultValue;
}
/// <summary>
/// JsonElement 转 Object

View File

@@ -97,7 +97,7 @@ public static class StringExtensions
/// 转换布尔值
/// </summary>
/// <returns></returns>
public static bool ToBool(this string value, bool defaultValue = false) => value?.ToUpper() switch
public static bool ToBoolean(this string value, bool defaultValue = false) => value?.ToUpper() switch
{
"1" or "TRUE" => true,
_ => defaultValue,

View File

@@ -31,8 +31,10 @@ public static class SysDateTimeExtensions
/// </summary>
public static string ToDefaultDateTimeFormat(this in DateTime dt, TimeSpan offset)
{
if(dt.Kind==DateTimeKind.Utc)
if (dt.Kind == DateTimeKind.Utc)
return new DateTimeOffset(dt.ToLocalTime(), offset).ToString("yyyy-MM-dd HH:mm:ss:fff zz");
else if (dt == DateTime.MinValue || dt == DateTime.MaxValue)
return dt.ToString("yyyy-MM-dd HH:mm:ss:fff zz");
else
return new DateTimeOffset(dt, offset).ToString("yyyy-MM-dd HH:mm:ss:fff zz");
}
@@ -50,8 +52,8 @@ public static class SysDateTimeExtensions
{
return dt.ToString("yyyy-MM-dd HH-mm-ss-fff zz");
}
/// <summary>

View File

@@ -1026,7 +1026,7 @@
<param name="str"></param>
<returns></returns>
</member>
<member name="M:ThingsGateway.Admin.Core.ObjectExtensions.ToBool(System.Object,System.Boolean)">
<member name="M:ThingsGateway.Admin.Core.ObjectExtensions.ToBoolean(System.Object,System.Boolean)">
<summary>
转换布尔值
</summary>
@@ -1050,6 +1050,12 @@
</summary>
<returns></returns>
</member>
<member name="M:ThingsGateway.Admin.Core.ObjectExtensions.ToDouble(System.Object,System.Double)">
<summary>
ToDecimal
</summary>
<returns></returns>
</member>
<member name="M:ThingsGateway.Admin.Core.ObjectExtensions.ToObject(System.Text.Json.JsonElement)">
<summary>
JsonElement 转 Object
@@ -1142,7 +1148,7 @@
<param name="input"></param>
<returns></returns>
</member>
<member name="M:ThingsGateway.Admin.Core.StringExtensions.ToBool(System.String,System.Boolean)">
<member name="M:ThingsGateway.Admin.Core.StringExtensions.ToBoolean(System.String,System.Boolean)">
<summary>
转换布尔值
</summary>

View File

@@ -21,7 +21,7 @@ using ThingsGateway.Application;
namespace ThingsGateway.ApiController;
/// <summary>
/// 后台登录控制器
/// 文件下载
/// </summary>
[ApiDescriptionSettings(CateGoryConst.ThingsGatewayAdmin, Order = 200)]
[Route("gatewayFile")]

View File

@@ -26,7 +26,7 @@
</member>
<member name="T:ThingsGateway.ApiController.FileController">
<summary>
后台登录控制器
文件下载
</summary>
</member>
<member name="M:ThingsGateway.ApiController.FileController.#ctor(ThingsGateway.Application.IRpcLogService,ThingsGateway.Application.IBackendLogService,ThingsGateway.Application.ICollectDeviceService,ThingsGateway.Application.IUploadDeviceService,ThingsGateway.Application.IVariableService)">

View File

@@ -31,7 +31,7 @@ public class DeviceVariable : MemoryVariable
public virtual long DeviceId { get; set; }
/// <summary>
/// 写入表达式
/// 单位
/// </summary>
[SugarColumn(ColumnName = "Unit", ColumnDescription = "单位", Length = 200, IsNullable = true)]
[DataTable(Order = 3, IsShow = true, Sortable = true)]
@@ -59,12 +59,7 @@ public class DeviceVariable : MemoryVariable
[DataTable(Order = 3, IsShow = true, Sortable = true)]
public string VariableAddress { get; set; }
/// <summary>
/// 写入表达式
/// </summary>
[SugarColumn(ColumnName = "WriteExpressions", ColumnDescription = "写入表达式", Length = 200, IsNullable = true)]
[DataTable(Order = 7, IsShow = true, Sortable = true)]
public string WriteExpressions { get; set; }
/// <summary>
/// 是否中间变量

View File

@@ -51,7 +51,12 @@ public class MemoryVariable : BaseEntity
[SugarColumn(ColumnName = "ReadExpressions", ColumnDescription = "读取表达式", Length = 200, IsNullable = true)]
[DataTable(Order = 7, IsShow = true, Sortable = true, CellClass = " table-text-truncate ")]
public string ReadExpressions { get; set; }
/// <summary>
/// 写入表达式
/// </summary>
[SugarColumn(ColumnName = "WriteExpressions", ColumnDescription = "写入表达式", Length = 200, IsNullable = true)]
[DataTable(Order = 7, IsShow = true, Sortable = true)]
public string WriteExpressions { get; set; }
/// <summary>
/// 是否中间变量
/// </summary>

View File

@@ -17,8 +17,6 @@ using Newtonsoft.Json.Linq;
using ThingsGateway.Foundation;
using ThingsGateway.Foundation.Serial;
using TouchSocket.Core;
namespace ThingsGateway.Application;
/// <summary>
/// <para></para>

View File

@@ -360,7 +360,7 @@
</member>
<member name="P:ThingsGateway.Application.DeviceVariable.Unit">
<summary>
写入表达式
单位
</summary>
</member>
<member name="P:ThingsGateway.Application.DeviceVariable.IntervalTime">
@@ -378,11 +378,6 @@
变量地址,可能带有额外的信息,比如<see cref="T:ThingsGateway.Foundation.DataFormat"/> ,以;分割
</summary>
</member>
<member name="P:ThingsGateway.Application.DeviceVariable.WriteExpressions">
<summary>
写入表达式
</summary>
</member>
<member name="P:ThingsGateway.Application.DeviceVariable.IsMemoryVariable">
<summary>
是否中间变量
@@ -524,6 +519,11 @@
读取表达式
</summary>
</member>
<member name="P:ThingsGateway.Application.MemoryVariable.WriteExpressions">
<summary>
写入表达式
</summary>
</member>
<member name="P:ThingsGateway.Application.MemoryVariable.IsMemoryVariable">
<summary>
是否中间变量
@@ -1816,7 +1816,7 @@
<inheritdoc cref="P:ThingsGateway.Application.MemoryVariable.ReadExpressions"/>
</member>
<member name="P:ThingsGateway.Application.VariableData.WriteExpressions">
<inheritdoc cref="P:ThingsGateway.Application.DeviceVariable.WriteExpressions"/>
<inheritdoc cref="!:DeviceVariable.WriteExpressions"/>
</member>
<member name="P:ThingsGateway.Application.VariableData.IntervalTime">
<inheritdoc cref="P:ThingsGateway.Application.DeviceVariable.IntervalTime"/>
@@ -3561,6 +3561,11 @@
开始采集
</summary>
</member>
<member name="M:ThingsGateway.Application.CollectDeviceThread.BeforeStopThreadAsync">
<summary>
停止采集前提前取消Token
</summary>
</member>
<member name="M:ThingsGateway.Application.CollectDeviceThread.StopThreadAsync">
<summary>
停止采集
@@ -3934,6 +3939,11 @@
开始上传
</summary>
</member>
<member name="M:ThingsGateway.Application.UploadDeviceThread.BeforeStopThreadAsync">
<summary>
停止采集前提前取消Token
</summary>
</member>
<member name="M:ThingsGateway.Application.UploadDeviceThread.StopThreadAsync">
<summary>
停止上传

View File

@@ -74,7 +74,7 @@ public class AlarmWorker : BackgroundService
public async Task<OperResult<SqlSugarClient>> GetAlarmDbAsync()
{
var ConfigService = ServiceHelper.Services.GetService<IConfigService>();
var alarmEnable = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_AlarmConfig_Base, ThingsGatewayConfigConst.Config_Alarm_Enable))?.ConfigValue?.ToBool();
var alarmEnable = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_AlarmConfig_Base, ThingsGatewayConfigConst.Config_Alarm_Enable))?.ConfigValue?.ToBoolean();
var alarmDbType = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_AlarmConfig_Base, ThingsGatewayConfigConst.Config_Alarm_DbType))?.ConfigValue;
var alarmConnstr = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_AlarmConfig_Base, ThingsGatewayConfigConst.Config_Alarm_ConnStr))?.ConfigValue;
@@ -132,14 +132,14 @@ public class AlarmWorker : BackgroundService
limit = string.Empty;
expressions = string.Empty;
text = string.Empty;
if (tag.BoolCloseAlarmEnable && tag.Value.ToBool() == false)
if (tag.BoolCloseAlarmEnable && tag.Value.ToBoolean() == false)
{
limit = false.ToString();
expressions = tag.BoolCloseRestrainExpressions;
text = tag.BoolCloseAlarmText;
return AlarmEnum.Close;
}
if (tag.BoolOpenAlarmEnable && tag.Value.ToBool() == true)
if (tag.BoolOpenAlarmEnable && tag.Value.ToBoolean() == true)
{
limit = true.ToString();
expressions = tag.BoolOpenRestrainExpressions;

View File

@@ -85,6 +85,29 @@ public class CollectDeviceThread : IAsyncDisposable
easyLock.Release();
}
}
/// <summary>
/// 停止采集前提前取消Token
/// </summary>
public virtual async Task BeforeStopThreadAsync()
{
try
{
await easyLock.WaitAsync();
if (DeviceTask == null)
{
return;
}
foreach (var token in StoppingTokens)
{
token.Cancel();
}
}
finally
{
easyLock.Release();
}
}
/// <summary>
/// 停止采集
@@ -173,7 +196,10 @@ public class CollectDeviceThread : IAsyncDisposable
foreach (var device in CollectDeviceCores)
{
try
{//初始化成功才能执行
{
if (stoppingToken.IsCancellationRequested)
break;
//初始化成功才能执行
if (device.IsInitSuccess)
{
//如果是共享通道类型,需要每次转换时切换适配器

View File

@@ -328,6 +328,18 @@ public class CollectDeviceWorker : BackgroundService
/// </summary>
private async Task RemoveAllDeviceThreadAsync()
{
await CollectDeviceThreads.ParallelForEachAsync(async (deviceThread, token) =>
{
try
{
await deviceThread.BeforeStopThreadAsync();
}
catch (Exception ex)
{
_logger?.LogError(ex, deviceThread.ToString());
}
}, 10);
await CollectDeviceThreads.ParallelForEachAsync(async (deviceThread, token) =>
{
try

View File

@@ -60,7 +60,7 @@ public class HistoryValueWorker : BackgroundService
public async Task<OperResult<SqlSugarClient>> GetHisDbAsync()
{
var ConfigService = ServiceHelper.Services.GetService<IConfigService>();
var hisEnable = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_HisConfig_Base, ThingsGatewayConfigConst.Config_His_Enable))?.ConfigValue?.ToBool();
var hisEnable = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_HisConfig_Base, ThingsGatewayConfigConst.Config_His_Enable))?.ConfigValue?.ToBoolean();
var hisDbType = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_HisConfig_Base, ThingsGatewayConfigConst.Config_His_DbType))?.ConfigValue;
var hisConnstr = (await ConfigService.GetByConfigKeyAsync(ThingsGatewayConfigConst.ThingGateway_HisConfig_Base, ThingsGatewayConfigConst.Config_His_ConnStr))?.ConfigValue;
@@ -458,7 +458,7 @@ public class HistoryValueMapper : IRegister
{
if (src.Value?.ToString()?.IsBoolValue() == true)
{
if (src.Value.ToBool())
if (src.Value.ToBoolean())
{
return 1;
}

View File

@@ -74,6 +74,29 @@ public class UploadDeviceThread : IAsyncDisposable
easyLock.Release();
}
}
/// <summary>
/// 停止采集前提前取消Token
/// </summary>
public virtual async Task BeforeStopThreadAsync()
{
try
{
await easyLock.WaitAsync();
if (DeviceTask == null)
{
return;
}
foreach (var token in StoppingTokens)
{
token.Cancel();
}
}
finally
{
easyLock.Release();
}
}
/// <summary>
/// 停止上传
@@ -152,7 +175,10 @@ public class UploadDeviceThread : IAsyncDisposable
foreach (var device in UploadDeviceCores)
{
try
{//初始化成功才能执行
{
if (stoppingToken.IsCancellationRequested)
break;
//初始化成功才能执行
if (device.IsInitSuccess)
{

View File

@@ -239,6 +239,17 @@ public class UploadDeviceWorker : BackgroundService
/// </summary>
private async Task RemoveAllDeviceThreadAsync()
{
await UploadDeviceThreads.ParallelForEachAsync(async (deviceThread, token) =>
{
try
{
await deviceThread.BeforeStopThreadAsync();
}
catch (Exception ex)
{
_logger?.LogError(ex, deviceThread.ToString());
}
}, 10);
await UploadDeviceThreads.ParallelForEachAsync(async (deviceThread, token) =>
{
try

View File

@@ -102,44 +102,6 @@
}
@foreach (var item in ImportPreviews)
{
<MSubheader Class="mt-2 font-weight-black">
@(
$"{item.Key},预计导入{item.Value.DataCount}条数据"
)
</MSubheader>
<MSubheader Class=@((item.Value.HasError?"mt-2 red--text":"mt-2 green--text"))>
@(
(item.Value.HasError ? "出现错误" : "验证成功")
)
</MSubheader>
<MVirtualScroll Context="item1" Height=300 OverscanCount=2 ItemSize="60" Items="item.Value.Results">
<ItemContent>
<MListItem>
<MListItemAction>
<MChip Class="ma-2">
@(
$"第{item1.row}行"
)
</MChip>
</MListItemAction>
<MListItemContent>
<MListItemTitle Class=@((item1.isSuccess?"green--text":"red--text"))>
<strong>@item1.resultString</strong>
</MListItemTitle>
</MListItemContent>
</MListItem>
<MDivider></MDivider>
</ItemContent>
</MVirtualScroll>
}
</div>
<div class="mt-6">
<MButton Color="primary" Disabled=@ImportPreviews.Any(it=>it.Value.HasError) OnClick="()=>Step=3">下一步</MButton>

View File

@@ -21,9 +21,9 @@ public class HisPageInput : VariablePageInput
/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime { get; set; } = DateTime.Now.AddDays(-1);
public DateTime? StartTime { get; set; } = DateTime.UtcNow.AddDays(-1);
/// <summary>
/// 结束时间
/// </summary>
public DateTime? EndTime { get; set; } = DateTime.Now.AddDays(1);
public DateTime? EndTime { get; set; } = DateTime.UtcNow.AddDays(1);
}

View File

@@ -62,6 +62,7 @@
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_collectDeviceGroupSearchName"
Outlined Label=@typeof(CollectDevice).GetDescription(nameof(CollectDevice.DeviceGroup)) />
</MCardTitle>
<MTreeview Style=@($"height: calc(100vh - {BlazorResourceConst.DefaultHeight + 240}px; overflow-y:auto)") Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
{
if(_collectDeviceGroup!=a.FirstOrDefault())

View File

@@ -199,7 +199,6 @@ public partial class DeviceStatusPage : IDisposable
// await MainLayout.StateHasChangedAsync();
// }
//}
private async Task RunTimerAsync()
{
while (await _periodicTimer.WaitForNextTickAsync())

View File

@@ -61,6 +61,7 @@ else
</span>
</LabelContent>
</MTreeview>
</MCard>
</MCol>
<MCol Md=10 Cols="12">

View File

@@ -40,22 +40,22 @@
<MMenu CloseOnContentClick="false" OffsetY Context="menu">
<ActivatorContent>
<MTextField Dense Readonly Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 "
Value="context.StartTime"
Value="context.StartTime.Value.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset)"
@attributes="menu.Attrs" Outlined Label=@context.Description(x => x.StartTime) />
</ActivatorContent>
<ChildContent>
<AppDateTimePicker OutputTimezoneOffset="DateTimeOffset.Now.Offset" @bind-Value="context.StartTime"></AppDateTimePicker>
<AppDateTimePicker @bind-Value="context.StartTime"></AppDateTimePicker>
</ChildContent>
</MMenu>
<MMenu CloseOnContentClick="false" OffsetY Context="menu">
<ActivatorContent>
<MTextField Dense Readonly Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 "
Value="context.EndTime"
<MTextField Dense Readonly Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 "
Value="context.EndTime.Value.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset)" Clearable
@attributes="menu.Attrs" Outlined Label=@context.Description(x => x.EndTime) />
</ActivatorContent>
<ChildContent>
<AppDateTimePicker OutputTimezoneOffset="DateTimeOffset.Now.Offset" @bind-Value="context.EndTime"></AppDateTimePicker>
<AppDateTimePicker @bind-Value="context.EndTime"></AppDateTimePicker>
</ChildContent>
</MMenu>

View File

@@ -63,8 +63,8 @@ public partial class HistoryAlarmPage
var query = result.Content.CopyNew().Queryable<HistoryAlarm>().
WhereIF(!input.DeviceName.IsNullOrEmpty(), a => a.DeviceName.Contains(input.DeviceName))
.WhereIF(!input.Name.IsNullOrEmpty(), a => a.Name.Contains(input.Name))
.WhereIF(input.StartTime != null, a => a.EventTime >= input.StartTime.Value)
.WhereIF(input.EndTime != null, a => a.EventTime <= input.EndTime.Value);
.WhereIF(input.StartTime != null, a => a.EventTime >= input.StartTime.Value.ToLocalTime())
.WhereIF(input.EndTime != null, a => a.EventTime <= input.EndTime.Value.ToLocalTime());
for (int i = 0; i < input.SortField.Count; i++)
{

View File

@@ -42,23 +42,23 @@
<MMenu CloseOnContentClick="false" OffsetY Context="menu">
<ActivatorContent>
<MTextField Dense Readonly Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 "
Value="context.StartTime"
Value="context.StartTime.Value.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset)"
Clearable
@attributes="menu.Attrs" Outlined Label=@context.Description(x => x.StartTime) />
</ActivatorContent>
<ChildContent>
<AppDateTimePicker OutputTimezoneOffset="DateTimeOffset.Now.Offset" @bind-Value="context.StartTime"></AppDateTimePicker>
<AppDateTimePicker @bind-Value="context.StartTime"></AppDateTimePicker>
</ChildContent>
</MMenu>
<MMenu CloseOnContentClick="false" OffsetY Context="menu">
<ActivatorContent>
<MTextField Dense Readonly Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 "
Value="context.EndTime" Clearable
Value="context.EndTime.Value.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset)" Clearable
@attributes="menu.Attrs" Outlined Label=@context.Description(x => x.EndTime) />
</ActivatorContent>
<ChildContent>
<AppDateTimePicker OutputTimezoneOffset="DateTimeOffset.Now.Offset" @bind-Value="context.EndTime"></AppDateTimePicker>
<AppDateTimePicker @bind-Value="context.EndTime"></AppDateTimePicker>
</ChildContent>
</MMenu>

View File

@@ -149,6 +149,7 @@
<MTextField Dense Outlined HideDetails="@("auto")" @bind-Value=@context.ReadExpressions />
</MCol>
<MCol Md=6 Cols=12 class="px-1">
<MSubheader Class="font-weight-black"> @(context.Description(x => x.WriteExpressions)) </MSubheader>

View File

@@ -96,7 +96,7 @@ public partial class MemoryVariablePage
Task<Dictionary<string, ImportPreviewOutputBase>> DeviceImportAsync(IBrowserFile file)
{
return VariableService.PreviewAsync(file);
return VariableService.MemoryVariablePreviewAsync(file);
}

View File

@@ -108,11 +108,8 @@ public abstract class ReadWriteDevicesTcpDataHandleAdapter<TRequest> : CustomDat
protected virtual FilterResult GetResponse(ByteBlock byteBlock, TRequest request, byte[] body, byte[] bytes)
{
var unpackbytes = UnpackResponse(request, request.SendBytes, body, bytes);
request.Message = unpackbytes.Message;
request.Content = unpackbytes.Content1;
request.ReceivedBytes = bytes;
request.ResultCode = unpackbytes.ResultCode;
switch (unpackbytes.Content2)
switch (unpackbytes)
{
case FilterResult.Cache:
return FilterResult.Cache;
@@ -121,15 +118,10 @@ public abstract class ReadWriteDevicesTcpDataHandleAdapter<TRequest> : CustomDat
case FilterResult.GoOn:
byteBlock.Pos = byteBlock.Len;
return FilterResult.GoOn;
default:
byteBlock.Pos = byteBlock.Len;
return FilterResult.GoOn;
}
//直接放弃
byteBlock.Pos = byteBlock.Len;
request.ReceivedBytes = bytes;
Logger?.Warning(unpackbytes.Message);
request.ResultCode = ResultCode.Error;
request.Message = unpackbytes.Message;
return FilterResult.GoOn;
}
/// <summary>
/// 发送方法,会重新建立<see cref="Request"/>
@@ -156,5 +148,5 @@ public abstract class ReadWriteDevicesTcpDataHandleAdapter<TRequest> : CustomDat
/// <summary>
/// 报文拆包
/// </summary>
protected abstract OperResult<byte[], FilterResult> UnpackResponse(TRequest request, byte[] send, byte[] body, byte[] response);
protected abstract FilterResult UnpackResponse(TRequest request, byte[] send, byte[] body, byte[] response);
}

View File

@@ -38,6 +38,8 @@ public static class LoggerExtensions
{
logger.Log(TouchSocket.Core.LogLevel.Warning, null, msg, ex);
}
/// <summary>
/// 输出警示日志
/// </summary>

View File

@@ -3,6 +3,11 @@
<PropertyGroup>
<TargetFrameworks>net45;net6.0;net7.0</TargetFrameworks>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://diego2098.gitee.io/thingsgateway-docs/</PackageProjectUrl>
<PackageTags>ThingsGateway;Diego;dotNET China;Blazor;设备采集;边缘网关</PackageTags>
<PackageOutputPath>../nupkgs</PackageOutputPath>
<AssemblyOriginatorKeyFile>..\..\snks\ThingsGateway.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Foundataion\ThingsGateway.Foundation.Adapter.OPCUA\ThingsGateway.Foundation.Adapter.OPCUA.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>OPCUAClientDemo</name>
</assembly>
<members>
</members>
</doc>

View File

@@ -0,0 +1,23 @@
using ThingsGateway.Foundation.Adapter.OPCUA;
using TouchSocket.Core;
namespace ModbusDemo
{
internal class Program
{
static async Task Main(string[] args)
{
OPCUAClient oPCUAClient = new(new EasyLogger(a => Console.WriteLine(a)));
oPCUAClient.OPCNode = new()
{
OPCUrl = "opc.tcp://desktop-p5gb4iq:50001/StandardServer",
IsUseSecurity = true,
};
await oPCUAClient.ConnectAsync();
var testData1 = await oPCUAClient.ReadJTokenValueAsync(new[] { "ns=2;i=2897" });
}
}
}

View File

@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Version>2.0.0.0</Version>
<Version>2.0.4.0</Version>
<Authors>Diego</Authors>
<Product>ThingsGateway</Product>
<Copyright>© 2023-present Diego</Copyright>

View File

@@ -10,7 +10,6 @@
//------------------------------------------------------------------------------
#endregion
using ThingsGateway.Foundation.Extension;
namespace ThingsGateway.Foundation.Adapter.Modbus;
@@ -41,43 +40,52 @@ public class ModbusRtuDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<M
/// <inheritdoc/>
protected override OperResult<byte[], FilterResult> UnpackResponse(ModbusRtuMessage request, byte[] send, byte[] body, byte[] response)
protected override FilterResult UnpackResponse(ModbusRtuMessage request, byte[] send, byte[] body, byte[] response)
{
//理想状态检测
var result = ModbusHelper.GetModbusRtuData(send, response, Crc16CheckEnable);
if (result.IsSuccess)
{
return OperResult.CreateSuccessResult(result.Content, FilterResult.Success);
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Success;
}
else
{
//如果返回错误,具体分析
var op = result.Copy<byte[], FilterResult>();
if (response.Length <= 1)
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
//如果长度不足,返回缓存
op.Content2 = FilterResult.Cache;
return op;
return FilterResult.Cache;
}
if (!(response[1] <= 0x10))
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
//功能码不对,返回放弃
op.Content2 = FilterResult.Success;
return op;
return FilterResult.Success;
}
else
{
if ((response.Length > response[2] + 4))
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
//如果长度已经超了,说明这段报文已经不能继续解析了,直接返回放弃
op.Content2 = FilterResult.Success;
return op;
return FilterResult.Success;
}
else
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
//否则返回缓存
op.Content2 = FilterResult.Cache;
return op;
return FilterResult.Cache;
}
}
}

View File

@@ -10,7 +10,6 @@
//------------------------------------------------------------------------------
#endregion
using ThingsGateway.Foundation.Extension;
using ThingsGateway.Foundation.Extension.Generic;
namespace ThingsGateway.Foundation.Adapter.Modbus;
@@ -69,7 +68,7 @@ public class ModbusServerDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapte
}
/// <inheritdoc/>
protected override OperResult<byte[], FilterResult> UnpackResponse(ModbusServerMessage request, byte[] send, byte[] body, byte[] response)
protected override FilterResult UnpackResponse(ModbusServerMessage request, byte[] send, byte[] body, byte[] response)
{
var result = GetModbusData(response.RemoveBegin(6));
if (result.IsSuccess)
@@ -119,14 +118,15 @@ public class ModbusServerDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapte
Length = ThingsGatewayBitConverter.ToByte(response, 11),
};
}
return OperResult.CreateSuccessResult(request.Content, FilterResult.Success);
request.ResultCode = result.ResultCode;
request.Message = result.Message;
return FilterResult.Success;
}
else
{
var op = result.Copy<byte[], FilterResult>();
op.Content2 = FilterResult.Cache;
return op;
request.ResultCode = result.ResultCode;
request.Message = result.Message;
return FilterResult.Cache;
}
}
}

View File

@@ -50,35 +50,54 @@ public class ModbusTcpDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapter<M
}
/// <inheritdoc/>
protected override OperResult<byte[], FilterResult> UnpackResponse(ModbusTcpMessage request, byte[] send, byte[] body, byte[] response)
protected override FilterResult UnpackResponse(ModbusTcpMessage request, byte[] send, byte[] body, byte[] response)
{
//理想状态检测
var result = ModbusHelper.GetModbusData(send.RemoveBegin(6), response.RemoveBegin(6));
if (result.IsSuccess)
{
return OperResult.CreateSuccessResult(result.Content, FilterResult.Success);
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Success;
}
else
{
//如果返回错误,具体分析
var op = result.Copy<byte[], FilterResult>();
if (response.Length == 9)
{
if (response[7] >= 0x80)//错误码
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Success;
}
}
if (response.Length < 10)
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Cache;
//如果长度不足,返回缓存
op.Content2 = FilterResult.Cache;
return op;
}
if ((response.Length > response[8] + 9))
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Success;
//如果长度已经超了,说明这段报文已经不能继续解析了,直接返回放弃
op.Content2 = FilterResult.Success;
return op;
}
else
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Cache;
//否则返回缓存
op.Content2 = FilterResult.Cache;
return op;
}
}

View File

@@ -31,11 +31,6 @@ public static class JsonUtils
/// <summary>
/// 解析获取DataValue
/// </summary>
/// <param name="Context"></param>
/// <param name="dataTypeId"></param>
/// <param name="builtInType"></param>
/// <param name="valueRank"></param>
/// <param name="json"></param>
/// <returns></returns>
public static DataValue Decode(
IServiceMessageContext Context,
@@ -45,6 +40,7 @@ public static class JsonUtils
JToken json
)
{
var data = DecoderObject(Context, dataTypeId, builtInType, valueRank, json);
var dataValue = new DataValue(new Variant(data));
return dataValue;
@@ -54,11 +50,6 @@ public static class JsonUtils
/// <summary>
/// 解析获取object
/// </summary>
/// <param name="Context"></param>
/// <param name="dataTypeId"></param>
/// <param name="builtInType"></param>
/// <param name="valueRank"></param>
/// <param name="json"></param>
/// <returns></returns>
public static object DecoderObject(
IServiceMessageContext Context,
@@ -76,10 +67,9 @@ public static class JsonUtils
{
Value = new
{
TypeId = new { Id = dataTypeId.Identifier },
TypeId = new { Id = dataTypeId.Identifier, Namespace = dataTypeId.NamespaceIndex },
Body = json
}
}.ToJson();
break;
case BuiltInType.Variant:

View File

@@ -14,6 +14,7 @@ using Newtonsoft.Json.Linq;
using Opc.Ua;
using Opc.Ua.Client;
using Opc.Ua.Client.ComplexTypes;
using Opc.Ua.Configuration;
using System.Collections.Generic;
@@ -454,13 +455,24 @@ public class OPCUAClient : DisposableObject
/// </summary>
public async Task ConnectAsync()
{
m_session = await ConnectAsync(OPCNode.OPCUrl);
await ConnectAsync(OPCNode.OPCUrl);
}
/// <summary>
/// 断开连接。
/// </summary>
public void Disconnect()
{
PrivateDisconnect();
// disconnect any existing session.
if (m_session != null)
{
Log.Debug("断开连接");
m_session = null;
}
}
private void PrivateDisconnect()
{
// stop any reconnect operation.
if (m_reConnectHandler != null)
@@ -468,15 +480,7 @@ public class OPCUAClient : DisposableObject
m_reConnectHandler.SafeDispose();
m_reConnectHandler = null;
}
// disconnect any existing session.
if (m_session != null)
{
Log.Debug("断开连接");
m_session.Close(10000);
m_session = null;
}
m_session?.Close(10000);
}
@@ -508,6 +512,10 @@ public class OPCUAClient : DisposableObject
AttributeId = Attributes.Value,
};
var node = (VariableNode)ReadNode(tag.ToString(), false);
//var expandedNodeId = NodeId.ToExpandedNodeId(node.DataType, m_session.NamespaceUris);
//var type = m_session.Factory.GetSystemType(expandedNodeId);
//var data = value.ToObject(type);
//var dataValue = new DataValue(new Variant(data));
var dataValue = JsonUtils.Decode(
m_session.MessageContext,
node.DataType,
@@ -859,7 +867,7 @@ public class OPCUAClient : DisposableObject
/// <returns>The new session object.</returns>
private async Task<ISession> ConnectAsync(string serverUrl)
{
Disconnect();
PrivateDisconnect();
if (m_configuration == null)
{
@@ -889,7 +897,7 @@ public class OPCUAClient : DisposableObject
60000,
userIdentity,
Array.Empty<string>());
await new ComplexTypeSystem(m_session).Load(false, true).ConfigureAwait(false);
Log.Debug("连接成功");
m_session.KeepAliveInterval = OPCNode.KeepAliveInterval == 0 ? 60000 : OPCNode.KeepAliveInterval;

View File

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.4.371.96" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes" Version="1.4.371.96" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server" Version="1.4.371.96" />
</ItemGroup>

View File

@@ -161,22 +161,12 @@
<summary>
解析获取DataValue
</summary>
<param name="Context"></param>
<param name="dataTypeId"></param>
<param name="builtInType"></param>
<param name="valueRank"></param>
<param name="json"></param>
<returns></returns>
</member>
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.JsonUtils.DecoderObject(Opc.Ua.IServiceMessageContext,Opc.Ua.NodeId,Opc.Ua.BuiltInType,System.Int32,Newtonsoft.Json.Linq.JToken)">
<summary>
解析获取object
</summary>
<param name="Context"></param>
<param name="dataTypeId"></param>
<param name="builtInType"></param>
<param name="valueRank"></param>
<param name="json"></param>
<returns></returns>
</member>
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.JsonUtils.DecodeRawData(Opc.Ua.JsonDecoder,Opc.Ua.BuiltInType,System.Int32,System.String)">

View File

@@ -10,7 +10,6 @@
//------------------------------------------------------------------------------
#endregion
using ThingsGateway.Foundation.Extension;
namespace ThingsGateway.Foundation.Adapter.Siemens;
@@ -35,7 +34,7 @@ public class SiemensS7PLCDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapte
}
/// <inheritdoc/>
protected override OperResult<byte[], FilterResult> UnpackResponse(SiemensMessage request, byte[] send, byte[] body, byte[] response)
protected override FilterResult UnpackResponse(SiemensMessage request, byte[] send, byte[] body, byte[] response)
{
var result = new OperResult<byte[]>();
if (response[2] * 256 + response[3] == 7)
@@ -57,23 +56,29 @@ public class SiemensS7PLCDataHandleAdapter : ReadWriteDevicesTcpDataHandleAdapte
}
if (result.IsSuccess)
{
return OperResult.CreateSuccessResult(result.Content, FilterResult.Success);
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
return FilterResult.Success;
}
else
{
//如果返回错误,具体分析
var op = result.Copy<byte[], FilterResult>();
if (response.Length < 21)
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
//如果长度不足,返回缓存
op.Content2 = FilterResult.Cache;
return op;
return FilterResult.Cache;
}
else
{
request.ResultCode = result.ResultCode;
request.Message = result.Message;
request.Content = result.Content;
//如果长度已经超了,说明这段报文已经不能继续解析了,直接返回放弃
op.Content2 = FilterResult.Success;
return op;
return FilterResult.Success;
}
}
}

View File

@@ -193,7 +193,7 @@ public class ModbusServer : UpLoadBase
if (tag.Value == null) return OperResult.CreateSuccessResult();
var enable =
GetPropertyValue(tag.Value, nameof(variablePropertys.VariableRpcEnable)).ToBool()
GetPropertyValue(tag.Value, nameof(variablePropertys.VariableRpcEnable)).ToBoolean()
&& driverPropertys.DeviceRpcEnable;
if (!enable) return new OperResult("不允许写入");
var type = GetPropertyValue(tag.Value, nameof(ModbusServerVariableProperty.ModbusType));

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<!--<GenerateDocumentationFile>True</GenerateDocumentationFile>-->
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
@@ -12,7 +13,9 @@
</Target>
<ItemGroup>
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" />
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" >
<IncludeAssets>Compile</IncludeAssets>
</ProjectReference>
<ProjectReference Include="..\Foundataion\ThingsGateway.Foundation.Adapter.Modbus\ThingsGateway.Foundation.Adapter.Modbus.csproj" />
</ItemGroup>

View File

@@ -335,7 +335,7 @@ public class IotSharpClient : UpLoadBase
if (tag != null)
{
var rpcEnable =
GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBool()
GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean()
&& driverPropertys.DeviceRpcEnable;
if (rpcEnable == true)
{

View File

@@ -415,7 +415,7 @@ public class MqttClient : UpLoadBase
var tag = _uploadVariables.FirstOrDefault(a => a.Name == nv.Key);
if (tag != null)
{
var rpcEnable = GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBool();
var rpcEnable = GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean();
if (rpcEnable == true)
{
var result = await _rpcCore.InvokeDeviceMethodAsync(ToString() + "-" + arg.ClientId, nv);

View File

@@ -270,7 +270,7 @@ public class MqttServer : UpLoadBase
var tag = _uploadVariables.FirstOrDefault(a => a.Name == nv.Key);
if (tag != null)
{
var rpcEnable = GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBool();
var rpcEnable = GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean();
if (rpcEnable == true)
{
var result = await _rpcCore.InvokeDeviceMethodAsync(ToString() + "-" + IdWithName[arg.ClientId], nv);

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<!--<GenerateDocumentationFile>True</GenerateDocumentationFile>-->
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
@@ -9,7 +10,9 @@
</Target>
<ItemGroup>
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" />
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" >
<IncludeAssets>Compile</IncludeAssets>
</ProjectReference>
<ProjectReference Include="..\Foundataion\ThingsGateway.Foundation.Adapter.OPCDA\ThingsGateway.Foundation.Adapter.OPCDA.csproj" />
</ItemGroup>

View File

@@ -36,6 +36,34 @@ namespace ThingsGateway.OPCUA;
/// </summary>
public class OPCUAClient : CollectBase
{
readonly PeriodicTimer _periodicTimer = new(TimeSpan.FromSeconds(60));
/// <summary>
/// OPCUA客户端
/// </summary>
public OPCUAClient()
{
_ = RunTimerAsync();
}
private async Task RunTimerAsync()
{
while (await _periodicTimer.WaitForNextTickAsync())
{
if (PLC != null && PLC.Session == null)
{
try
{
await PLC.ConnectAsync();
}
catch (Exception ex)
{
LogMessage.Exception(ex);
}
}
}
}
internal CollectDeviceRunTime Device;
internal Foundation.Adapter.OPCUA.OPCUAClient PLC = null;
@@ -73,7 +101,11 @@ public class OPCUAClient : CollectBase
}
/// <inheritdoc/>
public override bool IsConnected() => PLC.Connected;
public override bool IsConnected()
{
return PLC.Connected;
}
/// <inheritdoc/>
public override List<DeviceVariableSourceRead> LoadSourceRead(List<DeviceVariableRunTime> deviceVariables)
@@ -99,7 +131,6 @@ public class OPCUAClient : CollectBase
/// <inheritdoc/>
public override async Task<OperResult<byte[]>> ReadSourceAsync(DeviceVariableSourceRead deviceVariableSourceRead, CancellationToken token)
{
await Task.CompletedTask;
var result = await PLC.ReadJTokenValueAsync(deviceVariableSourceRead.DeviceVariables.Select(a => a.VariableAddress).ToArray(), token);
foreach (var data in result)
{
@@ -163,6 +194,7 @@ public class OPCUAClient : CollectBase
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
_periodicTimer?.Dispose();
if (PLC != null)
{
PLC.DataChangedHandler -= DataChangedHandler;

View File

@@ -115,7 +115,7 @@ public partial class OPCUAClientDebugDriverPage
try
{
var data = await _plc.ReadJTokenValueAsync(new string[] { defalutDebugDriverPage.Address });
defalutDebugDriverPage.Messages.Add((Microsoft.Extensions.Logging.LogLevel.Debug, SysDateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset) + " - " + data.ToJson()));
defalutDebugDriverPage.Messages.Add((Microsoft.Extensions.Logging.LogLevel.Debug, SysDateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset) + " - " + (data[0].Item1 + ":" + data[0].Item3)));
}
catch (Exception ex)
{

View File

@@ -14,7 +14,9 @@
<ItemGroup>
<ProjectReference Include="..\Foundataion\ThingsGateway.Foundation.Adapter.OPCUA\ThingsGateway.Foundation.Adapter.OPCUA.csproj" />
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" />
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" >
<IncludeAssets>Compile</IncludeAssets>
</ProjectReference>
</ItemGroup>

View File

@@ -33,6 +33,11 @@
OPCUA客户端
</summary>
</member>
<member name="M:ThingsGateway.OPCUA.OPCUAClient.#ctor">
<summary>
OPCUA客户端
</summary>
</member>
<member name="P:ThingsGateway.OPCUA.OPCUAClient.DriverDebugUIType">
<inheritdoc/>
</member>

View File

@@ -12,7 +12,6 @@
global using ThingsGateway.Foundation.Adapter.Siemens;
global using TouchSocket.Core;
global using TouchSocket.Sockets;

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<!--<GenerateDocumentationFile>True</GenerateDocumentationFile>-->
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
@@ -13,7 +14,9 @@
<ItemGroup>
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" />
<ProjectReference Include="..\..\ThingsGateway.Blazor\ThingsGateway.Blazor.csproj" >
<IncludeAssets>Compile</IncludeAssets>
</ProjectReference>
<ProjectReference Include="..\Foundataion\ThingsGateway.Foundation.Adapter.Siemens\ThingsGateway.Foundation.Adapter.Siemens.csproj" />
</ItemGroup>

View File

@@ -68,7 +68,7 @@ public class BlazorAuthorizeHandler : AppAuthorizeHandler
//这里鉴别密码是否改变
var userId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.UserId).Value.ToLong();
var isOpenApi = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsOpenApi)?.Value?.ToBool() == true;
var isOpenApi = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsOpenApi)?.Value?.ToBoolean() == true;
if (isOpenApi)
{
var _openApiUserService = App.GetService<OpenApiUserService>();
@@ -91,7 +91,7 @@ public class BlazorAuthorizeHandler : AppAuthorizeHandler
if (user == null) { return false; }
//超级管理员都能访问
if (context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsSuperAdmin)?.Value.ToBool() == true) return true;
if (context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsSuperAdmin)?.Value.ToBoolean() == true) return true;
if (context.Resource is RouteData routeData)
{
// 获取超级管理员特性
@@ -144,7 +144,7 @@ public class BlazorAuthorizeHandler : AppAuthorizeHandler
{
var userId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.UserId).Value;
var verificatId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.VerificatId)?.Value;
var isOpenApi = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsOpenApi)?.Value?.ToBool(false) == true;
var isOpenApi = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.IsOpenApi)?.Value?.ToBoolean(false) == true;
var _verificatService = App.GetService<VerificatService>();
if (isOpenApi)
{