12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include <open62541/client.h>
- #include <open62541/client_config_default.h>
- #include <open62541/plugin/log_stdout.h>
- #include <signal.h>
- #include <stdlib.h>
- UA_Boolean running = true;
- static void stopHandler(int sign) {
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Received Ctrl-C");
- running = 0;
- }
- static void
- inactivityCallback (UA_Client *client) {
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Server Inactivity");
- }
- int main(void) {
- signal(SIGINT, stopHandler);
- UA_Client *client = UA_Client_new();
- UA_ClientConfig *cc = UA_Client_getConfig(client);
- UA_ClientConfig_setDefault(cc);
- cc->inactivityCallback = inactivityCallback;
- cc->connectivityCheckInterval = 2000;
-
- while (running) {
-
-
-
- UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
- if(retval != UA_STATUSCODE_GOOD) {
- UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
- "Not connected. Retrying to connect in 1 second");
-
-
- UA_sleep_ms(1000);
- continue;
- }
- UA_Client_run_iterate(client, 1000);
- };
-
- UA_Client_delete(client);
- return EXIT_SUCCESS;
- }
|