diff --git a/Plugins/Drivers/DriverOPCUaClient/OPCUaClient.cs b/Plugins/Drivers/DriverOPCUaClient/OPCUaClient.cs index aea8d90..03a79ce 100644 --- a/Plugins/Drivers/DriverOPCUaClient/OPCUaClient.cs +++ b/Plugins/Drivers/DriverOPCUaClient/OPCUaClient.cs @@ -1,38 +1,28 @@ using PluginInterface; -using System; -using System.Collections; -using System.IO; using Opc.Ua; -using Opc.Ua.Client; -using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Opc.Ua.Configuration; using OpcUaHelper; namespace DriverOPCUaClient { [DriverSupported("OPC UA")] - [DriverInfoAttribute("OPCUaClient", "V1.0.0", "Copyright IoTGateway© 2021-12-19")] + [DriverInfo("OPCUaClient", "V1.0.0", "Copyright IoTGateway© 2021-12-19")] public class OPCUaClient : IDriver { - OpcUaClientHelper opcUaClient = null; - + private OpcUaClientHelper? opcUaClient; public ILogger _logger { get; set; } private readonly string _device; + #region 配置参数 - [ConfigParameter("设备Id")] - public Guid DeviceId { get; set; } + [ConfigParameter("设备Id")] public string DeviceId { get; set; } [ConfigParameter("uri")] public string Uri { get; set; } = "opc.tcp://localhost:62541/Quickstarts/ReferenceServer"; - [ConfigParameter("超时时间ms")] - public int Timeout { get; set; } = 3000; + [ConfigParameter("超时时间ms")] public int Timeout { get; set; } = 3000; - [ConfigParameter("最小通讯周期ms")] - public uint MinPeriod { get; set; } = 3000; + [ConfigParameter("最小通讯周期ms")] public uint MinPeriod { get; set; } = 3000; #endregion @@ -47,11 +37,7 @@ namespace DriverOPCUaClient public bool IsConnected { - get - { - - return opcUaClient != null && opcUaClient.Connected; - } + get { return opcUaClient != null && opcUaClient.Connected; } } public bool Connect() @@ -65,6 +51,7 @@ namespace DriverOPCUaClient { return false; } + return IsConnected; } @@ -77,7 +64,6 @@ namespace DriverOPCUaClient } catch (Exception) { - return false; } } @@ -90,7 +76,6 @@ namespace DriverOPCUaClient } catch (Exception) { - } } @@ -104,9 +89,9 @@ namespace DriverOPCUaClient { try { - var dataValue = opcUaClient.ReadNode(new NodeId(ioarg.Address)); + var dataValue = opcUaClient?.ReadNode(new NodeId(ioarg.Address)); if (DataValue.IsGood(dataValue)) - ret.Value = dataValue.Value; + ret.Value = dataValue?.Value; } catch (Exception ex) { @@ -119,6 +104,7 @@ namespace DriverOPCUaClient ret.StatusType = VaribaleStatusTypeEnum.Bad; ret.Message = "连接失败"; } + return ret; } @@ -134,13 +120,14 @@ namespace DriverOPCUaClient ret.StatusType = VaribaleStatusTypeEnum.Bad; ret.Message = "连接失败"; } + return ret; } - public async Task WriteAsync(string RequestId, string Method, DriverAddressIoArgModel Ioarg) + public async Task WriteAsync(string requestId, string method, DriverAddressIoArgModel ioarg) { RpcResponse rpcResponse = new() { IsSuccess = false, Description = "设备驱动内未实现写入功能" }; return rpcResponse; } } -} +} \ No newline at end of file