I am trying to connect to an OPC Server. I use the Softing OPC Toolkit and have managed to successfully connect via Cisco Anyconnect but do not manage to do so via Sinema RC Client V2.0.

I have established a VPN connection with the Server, have checked the IP adress and am able to ping the server in my terminal. The port I am using is on 'listening' so this should not be a problem. I did also put in the correct endpoint.

Here is my connect function in c++

EnumStatusCode OpcClient::connect()
{
    EnumStatusCode result;
    std::vector<tstring> transportProfileList;
    std::vector<EndpointDescription> endpointDescriptions;

EnumUserTokenType desiredTokenType = EnumUserTokenType_Anonymous;
EnumMessageSecurityMode desiredSecurityMode = EnumMessageSecurityMode_None;
tstring desiredSecurityPolicy = SecurityPolicyUri_None;

result = pApp->getEndpointsFromServer(serverUrl, transportProfileList, endpointDescriptions);

if(StatusCode::isBad(result))
{
    qDebug() << "No connection to ServerURL:";
}
else if (StatusCode::isGood(result))
{
    for(unsigned int i = 0; i < endpointDescriptions.size(); i++)
    {
       for(unsigned int j = 0; j < endpointDescriptions[i].getUserIdentityTokenCount(); j++)
       {
          if(endpointDescriptions[i].getUserIdentityToken(j)->getTokenType() == desiredTokenType
             && endpointDescriptions[i].getMessageSecurityMode() == desiredSecurityMode
             && endpointDescriptions[i].getSecurityPolicy() == desiredSecurityPolicy)
          {
              _tprintf(_T("Endpoint %d:\n")
                      _T("  URL:                 %s\n")
                      _T("  Message security:    %s\n")
                      _T("  Security policy:     %s\n"),
                      i,
                      endpointDescriptions[i].getEndpointUrl().c_str(),
                      getEnumMessageSecurityModeString(endpointDescriptions[i].getMessageSecurityMode()),
                      endpointDescriptions[i].getSecurityPolicy().c_str());

              const IUserTokenPolicy* pPolicy = endpointDescriptions[i].getUserIdentityToken(j);
              _tprintf(_T("  User token policy %d: %s\n"), j, getEnumUserTokenTypeString(pPolicy->getTokenType()));

              qDebug() << "Trying to connect a new session...";
              session = Client::Session::create();
              session->setSessionTimeout(60 * 1000); // in milliseconds
              session->setUrl(serverUrl);
              session->setSecurityConfiguration(desiredSecurityMode, desiredSecurityPolicy);

              UserIdentityToken userIdentityToken;
              userIdentityToken.setAnonymousIdentityToken(endpointDescriptions[i].getUserIdentityToken(j)->getPolicyId()); // usually obtained by GetEndpoints
              session->setUserIdentityToken(&userIdentityToken);
              session->setUserSecurityPolicy(desiredSecurityPolicy); // usually obtained by GetEndpoints

              pApp->addSession(session);

              result = session->connect(true);
              if(StatusCode::isBad(result))
              {
                  qDebug() << "ERROR: Failed to connect the session: \n"
                           << getEnumStatusCodeString(result);
                  session->disconnect();
                  pApp->removeSession(session);
              }
              if(StatusCode::isGood(result))
              {
                  qDebug() << "Successfully connected Session";
              }
          }
       }
    }
}
return result;
}

I am calling it like this ( The initalize and start function both run successfully):

OpcClient::OpcClient()
{

EnumStatusCode result;

loadToolbox(NULL);   // "NULL" only in the case that no creator is needed


ApplicationDescription appDesc;
appDesc.setApplicationType(EnumApplicationType_Client);
appDesc.setApplicationName(LocalizedText(_T("Client"), _T("en")));
appDesc.setApplicationUri(_T("urn:.../.../OpcUa/TestClient"));

appDesc.setProductUri(_T("urn:.../OpcUA/Softing_Development_Toolkit"));

serverUrl = _T("opc.tcp://myIP_andPort/Softing_dataFEED_OPC_Suite_UP");


pApp = Application::instance();
result = pApp->initialize(&appDesc);
if(StatusCode::isBad(result))
{
    qDebug() << "Failed to initialize App";
}
else if (StatusCode::isGood(result))
{
    qDebug() << "Successfully initialized App";

    result = pApp->start();
    if(StatusCode::isBad(result))
    {
        qDebug() << "Failed to start App";
    }
    else if (StatusCode::isGood(result))
    {
        qDebug() << "Successfully started App";
        result = connect();
        if(StatusCode::isBad(result))
        {
            qDebug() << "Failed to connect";
            disconnect();

The function does get all the needed Input and works via Cisco but not with Sinema RC. Any Idea why?

1 Answers

0
NewEyes On

In case anyone is interested in this in the future:

SinemaRC seems to sometimes configure your NAT settings wrong when using the default automatic method. After changing these back to the correct IP everything works again!