Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with session disconnect sending and receiving requests from client #6409

Open
5 of 7 tasks
VedanthaKasturi opened this issue Apr 12, 2024 · 1 comment
Open
5 of 7 tasks

Comments

@VedanthaKasturi
Copy link

VedanthaKasturi commented Apr 12, 2024

I am new to OPC so please bear with me. Also Thanks to this amazing project for being open-source and the lively community!

Background Information

I am working on a client-side code in C++ whose job is to get sensor information from a magnet system controlled by a PLC. I will also occasionally send some commands to turn on and turn off things. I have followed the client examples in the documentation to develop the code. The OPC send and receive commands are handled by a class called OPCmanager and the user end functions are done by another class called magnetControl. The connect part in the OPCmanager looks like this:

bool OpcManager::connectToServer() {
    MagnetControlClient = UA_Client_new();
    UA_ClientConfig *magnetClientConfig = UA_Client_getConfig(MagnetControlClient);

    UA_ClientConfig_setDefault(magnetClientConfig);

    std::string serverAddress = "opc.tcp://" + ServerIpAddress + ":" + std::to_string(PortNumber);

    UA_StatusCode retval = UA_Client_connect(MagnetControlClient, serverAddress.c_str());

    if(retval != UA_STATUSCODE_GOOD) {
        if(loggingEnabled)
            UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SESSION, "Could not connect to server at %s", serverAddress.c_str());

        UA_Client_delete(MagnetControlClient);
        return false;
    } else {
        if(loggingEnabled)
            UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SESSION, "Connected to server at %s", serverAddress.c_str());
    }

    return true;
}

Description of Issue

I have a while loop which reads nodes and writes to nodes inside a while loop whenever the user requests it. I was able to access the nodes but sometimes I have an error and I can't send any additional requests until I disconnect and reconnect to the server:

[2024-04-12 17:13:43.755 (UTC+0200)] info/userland Turning Off Power Converter
[2024-04-12 17:13:43.758 (UTC+0200)] info/client Received a ServiceFault response
[2024-04-12 17:13:43.758 (UTC+0200)] warn/client Session no longer valid. A new Session is created for the next Service request but we do not re-send the current request.
[2024-04-12 17:13:43.758 (UTC+0200)] info/client Client Status: ChannelState: Open, SessionState: Closed, ConnectStatus: Good
[2024-04-12 17:13:43.758 (UTC+0200)] error/userland Could not write the value. StatusCode 80250000

From the documentation I understand I might need to use perhaps "UA_Client_run_iterate" but I am not sure how and if thats enough since I have no idea when my next request might be. should I call it once every loop with no timeout? is there another way to keep the session open? or is this error not related to this? I could really use your guidance.

Checklist

Please provide the following information:

  • open62541 Version (release number or git tag): main (1.3.10 and 1.4.0)
  • Other OPC UA SDKs used (client or server): none
  • Operating system: Linux and Mac OS Sonoma
  • Logs (with UA_LOGLEVEL set as low as necessary) attached
  • Wireshark network dump attached
  • Self-contained code example attached
  • Critical issue
@jpfr
Copy link
Member

jpfr commented Apr 23, 2024

You can call _run with a fixed interval.
Or you get from the clients eventloop the timestamp of the next scheduled action.
Then you can keep track of time yourself.

Or you just open a separate thread to do the cyclic _run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants