我是 OPC-UA 的新手。目前在学习了统一自动化文档提供的演示和示例之后。我能够编写一个连接到服务器端点并调用方法的简单代码。但遗憾的是,该方法并没有返回预期的结果。此外,如果我通过UAExpert 在同一服务器上调用相同的方法和具有相同参数的相同URL,我会得到预期的结果。我束手无策,希望下面的任何帮助都是我目前编写的代码。
如果我遗漏了代码中的任何内容,请告诉我。
public void Connect(string endpointUrl)
{
AppSession.UserIdentity = new UserIdentity();
AppSession.SessionName = "urn:ACGIDT053:UnifiedAutomation:UaExpert";
//AppSession.Application.CertificateGroups[0];
//string endpointUrl = "opc.tcp://212.43.72.27:51510/UA/WipotecServer/";
AppSession.Connect(endpointUrl, SecuritySelection.None);
ICertificate certificateServer = SecurityUtils.LoadCertificate(AppSession.EndpointDescription.ServerCertificate);
AppSession.Application.TrustedStore.Add(certificateServer, true);
/// [Step 1]
// parse the object id.
NodeId objectId = NodeId.Parse("ns=2;i=15108");
// get the selected method id.
NodeId methodId = NodeId.Parse("ns=2;i=15057");
// get input arguments.
UInt32 a = 2;
List<Variant> inputArguments = new List<Variant>
{
new Variant(string.Empty, TypeInfo.Scalars.String), new Variant(a,TypeInfo.Scalars.UInt32), new Variant(string.Empty, TypeInfo.Scalars.String),
new Variant(null, TypeInfo.Arrays.ExtensionObject), new Variant(string.Empty, TypeInfo.Scalars.String)
};
/// [Step 2]
List<StatusCode> inputArgumentErrors;
List<Variant> outputArguments = null;
// call the method on the server.
StatusCode error = AppSession.Call(
objectId,
methodId,
inputArguments,
out inputArgumentErrors,
out outputArguments);
AppSession.Disconnect();
}
服务器在代码中没有返回异常,所有输入参数都是好的,错误状态也是如此。
更新:过滤器表达式应该是:(ip.src == 172.16.55.144 && ip.dst == 212.43.72.27) || (ip.dst == 172.16.55.144 && ip.src == 212.43.72.27) 请在以下链接中找到来自 Wireshark 的数据包: uaexpert: https://1drv.ms/u/s!ArxC3dVLzVTqhUGxsO1aDssb45er?e=tBcBRz localClient: https://1drv.ms/u/s!ArxC3dVLzVTqhUANVvKmHG5ULW6_?e=cAO5C8
更新:根据评论的建议更新代码。来自wireshark的更新代码包:https ://1drv.ms/u/s!ArxC3dVLzVTqhUIuqudrkrjMn8kn?e=fAZOtd