|
|
@@ -232,7 +232,7 @@ namespace YSAI.Opc.ua.client
|
|
|
null,
|
|
|
0,
|
|
|
TimestampsToReturn.Neither,
|
|
|
- nodesToRead, new CancellationToken()).Result;
|
|
|
+ nodesToRead, CancellationToken.None).Result;
|
|
|
|
|
|
return readResponse.Results[0];
|
|
|
}
|
|
|
@@ -384,7 +384,7 @@ namespace YSAI.Opc.ua.client
|
|
|
AttributeId = Attributes.Description
|
|
|
});
|
|
|
}
|
|
|
- return clientSession?.ReadAsync(null, 0, TimestampsToReturn.Neither, nodesToRead, new CancellationToken()).Result.Results.ToArray();
|
|
|
+ return clientSession?.ReadAsync(null, 0, TimestampsToReturn.Neither, nodesToRead, CancellationToken.None).Result.Results.ToArray();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -758,7 +758,7 @@ namespace YSAI.Opc.ua.client
|
|
|
if (Nodes.Count > 0)
|
|
|
{
|
|
|
//先在会话中,移除这个订阅
|
|
|
- if (!clientSession.RemoveSubscriptionAsync(allSubscriptions[Tag]).Result)
|
|
|
+ if (!clientSession.RemoveSubscriptionAsync(allSubscriptions[Tag],CancellationToken.None).WaitAsync(new TimeSpan(0,0,0,0, basics.Timeout)).Result)
|
|
|
{
|
|
|
//如果从会话中异常订阅失败则直接跳出
|
|
|
return Break("AddSubscribe", false, "从会话中移除订阅失败");
|
|
|
@@ -791,10 +791,10 @@ namespace YSAI.Opc.ua.client
|
|
|
//添加订阅
|
|
|
clientSession?.AddSubscription(allSubscriptions[Tag]);
|
|
|
//在服务器端创建订阅
|
|
|
- if (allSubscriptions[Tag].CreateAsync().Wait(60000))
|
|
|
+ if (allSubscriptions[Tag].CreateAsync().Wait(basics.Timeout))
|
|
|
{
|
|
|
// 在服务器端创建监控项
|
|
|
- if (allSubscriptions[Tag].ApplyChangesAsync().Wait(60000))
|
|
|
+ if (allSubscriptions[Tag].ApplyChangesAsync().Wait(basics.Timeout))
|
|
|
{
|
|
|
return Break("AddSubscribe", true);
|
|
|
}
|
|
|
@@ -844,10 +844,10 @@ namespace YSAI.Opc.ua.client
|
|
|
//添加订阅
|
|
|
clientSession?.AddSubscription(allSubscriptions[Tag]);
|
|
|
//在服务器端创建订阅
|
|
|
- if (allSubscriptions[Tag].CreateAsync().Wait(60000))
|
|
|
+ if (allSubscriptions[Tag].CreateAsync().Wait(basics.Timeout))
|
|
|
{
|
|
|
// 在服务器端创建监控项
|
|
|
- if (allSubscriptions[Tag].ApplyChangesAsync().Wait(60000))
|
|
|
+ if (allSubscriptions[Tag].ApplyChangesAsync().Wait(basics.Timeout))
|
|
|
{
|
|
|
return Break("AddSubscribe", true);
|
|
|
}
|
|
|
@@ -928,7 +928,7 @@ namespace YSAI.Opc.ua.client
|
|
|
{
|
|
|
if (alls2.Key.Equals(alls.Key))
|
|
|
{
|
|
|
- if (!clientSession.RemoveSubscriptionAsync(alls.Value).Wait(10000))
|
|
|
+ if (!clientSession.RemoveSubscriptionAsync(alls.Value).Wait(basics.Timeout))
|
|
|
{
|
|
|
LogHelper.Error("移除订阅超时");
|
|
|
}
|
|
|
@@ -981,7 +981,7 @@ namespace YSAI.Opc.ua.client
|
|
|
NodeId = new NodeId(Key),
|
|
|
};
|
|
|
|
|
|
- DeleteNodesResponse? deleteNodesResponse = clientSession?.DeleteNodesAsync(null, waitDelete, new CancellationToken()).Result;
|
|
|
+ DeleteNodesResponse? deleteNodesResponse = clientSession?.DeleteNodesAsync(null, waitDelete, CancellationToken.None).Result;
|
|
|
|
|
|
foreach (var item in deleteNodesResponse.Results)
|
|
|
{
|
|
|
@@ -1162,7 +1162,7 @@ namespace YSAI.Opc.ua.client
|
|
|
UserIdentity = new UserIdentity(basics.UserName, basics.Password);
|
|
|
}
|
|
|
//通过调用CreateSession服务创建与服务器的新通信会话
|
|
|
- clientSession = Session.Create(AC, endpoint, false, false, AC.ApplicationName, 1800000, UserIdentity, null).Result;
|
|
|
+ clientSession = Session.Create(AC, endpoint, false, false, AC.ApplicationName, (uint)basics.Timeout, UserIdentity, null).WaitAsync(new TimeSpan(0,0,0,0, basics.Timeout)).Result;
|
|
|
|
|
|
//当会话关闭,则关闭订阅
|
|
|
clientSession.DeleteSubscriptionsOnClose = true;
|
|
|
@@ -1224,9 +1224,15 @@ namespace YSAI.Opc.ua.client
|
|
|
|
|
|
if (clientSession != null)
|
|
|
{
|
|
|
- clientSession.Close(true);
|
|
|
- clientSession.Dispose();
|
|
|
- clientSession = null;
|
|
|
+ if (StatusCode.IsGood(clientSession.Close(true)))
|
|
|
+ {
|
|
|
+ clientSession.Dispose();
|
|
|
+ clientSession = null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Break("Off", false,"关闭失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//任务清空
|
|
|
@@ -1384,7 +1390,7 @@ namespace YSAI.Opc.ua.client
|
|
|
WriteValueCollection writeValues = new WriteValueCollection { writeValue };
|
|
|
|
|
|
// 写入当前的值
|
|
|
- WriteResponse? writeResponse = clientSession?.WriteAsync(null, writeValues, new CancellationToken()).Result;
|
|
|
+ WriteResponse? writeResponse = clientSession?.WriteAsync(null, writeValues, CancellationToken.None).Result;
|
|
|
|
|
|
foreach (var scc in writeResponse.Results)
|
|
|
{
|