convertersystems / opc-ua-samples

Sample HMIs using OPC Unified Architecture (OPC UA) and Visual Studio.
MIT License
107 stars 43 forks source link

OPC UA samples for opc-ua client 2.0.0* prerelease #35

Closed abrasat closed 7 years ago

abrasat commented 7 years ago

Are there any opc-ua samples compatible with the new opc-ua client 2.0.0* prerelease available ? When do you plan to "officialize" the opc-ua client 2.0.0 version ?

awcullen commented 7 years ago

The samples in this repo are using the latest 2.0.0* pre-release versions.

Do you like the new api? I am looking for feedback before "officializing".

tejasklodha commented 7 years ago

@awcullen ... New version is very good and also easy to understand....

I m using it without any issue....

Tejas Lodha

abrasat commented 7 years ago

Does the new version support also ExpandedNodeIds as MonitoredItemAttributes ?

abrasat commented 7 years ago

I have an application where I used the UaTcpSessionClient and the Subscribe() method to register the monitored items from a ViewModel. What is the equivalent code with the new opc-ua client version, as UaTcpSessionClient does not exist anymore?

Also for the UaTcpSessionClient I selected "manually" which endpoint to connect (I did not want to always have the "default" one with the highest security)

    // discover available endpoints of server.
     var getEndpointsRequest = new GetEndpointsRequest
      {
            EndpointUrl = this.discoveryUrl,
             ProfileUris = new[] { TransportProfileUris.UaTcpTransport }
      };
      this.logger.LogDebug($"Discovering endpoints of '{getEndpointsRequest.EndpointUrl}'.");
      var getEndpointsResponse = UaTcpDiscoveryClient.GetEndpointsAsync(getEndpointsRequest).Result;
      var selectedEndpoint = getEndpointsResponse.Endpoints.OrderByDescending(e => e.SecurityLevel).Last();

      this.session = new UaTcpSessionClient(
          new ApplicationDescription()
          {
            ApplicationName = "AlarmUI",
            ApplicationUri = $"urn:{System.Net.Dns.GetHostName()}:OpcUa.AlarmUI",
            ApplicationType = ApplicationType.Client
          },
          new DirectoryStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "pki"),
              loggerFactory: this.loggerFactory),
          this.ProvideUserIdentity,
          selectedEndpoint,
          this.loggerFactory);

How can all the available endpoints be discovered with the new opc-ua client ? How can be selected the endpoint to be used in the session, without having the UaTcpSessionClient ? In my application I have for instance only the discovery url, and want to open a session to the endpoint with the lowest security.

abrasat commented 7 years ago

What exactly is the meaning of/difference between the requestedUrl and the endpointUrl parameters from the Map() method in UaApplicationBuilder ?

I also debugged the MobileHmi.Droid application, and after the creation of the UaApplication the MappedPoints contain one MappedPoint record. In the EndpointDescription for this one record only the EndpointUrl is set ("opc.tcp://10.0.2.2:26543"), the other properties (SecurityLevel, SecurityMode, SecurityPolicyUri, ...) are either 0, null or invalid. The Map() method does definitely not seem to work correctly if the parameter SecurityPolicyUri is set (for example to "http://opcfoundation.org/UA/SecurityPolicy#None"). And if not set, the caller cannot take any influence on which endpoint is chosen at the endpoint discovery. Can you please take a look at this ?

awcullen commented 7 years ago

In the MobileHmi sample, I added:

.Map("opc.tcp://localhost:26543", "opc.tcp://10.0.2.2:26543")

That was because I wanted requests for "opc.tcp://localhost:26543" to be directed to "opc.tcp://10.0.2.2:26543". (There is also a version that takes a config file, see sample RobotHmi). If you don't set the SecurityPolicyUri, then the endpoint will be selected with the highest security. If you also set SecurityPolicyUri (for example to "http://opcfoundation.org/UA/SecurityPolicy#None"), then you will find that the endpoint selected will be restricted to only endpoints with "None" security. In your case, maybe the 'None' security was turned off at the server?

abrasat commented 7 years ago

With redirection you mean some kind of routing mechanism ? With the 1.5.12 release and UaTcpSessionClient I can connect to the "None" security endpoint. The problems occur only with the 2.0.0 prerelease. What parameters should be put in the Map() call if I want to access directly (without any redirection) a server with the address "opc.tcp://192.168.1.1:4444" and connect to the endpoint with the SecurityPolicyUri "http://opcfoundation.org/UA/SecurityPolicy#None" ? Where/how can be set the values for SecurityLevel, SecurityMode, SecurityPolicyUri ? Actually they dont seem to be set correctly.

awcullen commented 7 years ago

You could use:

                .Map("opc.tcp://192.168.1.1:4444", "opc.tcp://192.168.1.1:4444", SecurityPolicyUris.None)