From 748903264012ada19e0be45a1333890198ac0426 Mon Sep 17 00:00:00 2001 From: TomKovac <61820360+TomKovac@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:15:02 +0100 Subject: [PATCH] Create draft PR for #498 (#499) --- .../PlcSim/PlcSimInstance.cs | 40 ++++++++++++++++++- .../Properties/launchSettings.json | 2 +- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/PlcSim/PlcSimInstance.cs b/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/PlcSim/PlcSimInstance.cs index 8e99e687c..0b8c3c7ae 100644 --- a/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/PlcSim/PlcSimInstance.cs +++ b/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/PlcSim/PlcSimInstance.cs @@ -3,7 +3,9 @@ using Microsoft.CodeAnalysis; using System.Xml.Linq; using System.Diagnostics; - +using System.Net.NetworkInformation; +using System.Net; +using System.Threading; namespace PlcSimAdvancedStarterTool.PlcSim { @@ -198,6 +200,42 @@ public Task StartPlcSim([Option('x', Description = "PlcSim instance name")] stri } } + const int timeoutSeconds = 60; + const int pingIntervalMilliseconds = 1000; + + bool isAccessible = false; + DateTime startTime = DateTime.Now; + + Console.WriteLine($"Checking accessibility of the PLCsim instance: {PlcSimInstanceName} at IP address: {PlcIpAddress}."); + + using (Ping ping = new Ping()) + { + while ((DateTime.Now - startTime).TotalSeconds < timeoutSeconds) + { + try + { + PingReply reply = ping.Send(PlcIpAddress); + + if (reply.Status == IPStatus.Success) + { + Console.WriteLine($"PLCsim instance: {PlcSimInstanceName} at IP address: {PlcIpAddress} is accessible!"); + isAccessible = true; + break; + } + } + catch (Exception ex) + { + Console.WriteLine($"Ping attempt failed: {ex.Message}"); + } + + Thread.Sleep(pingIntervalMilliseconds); + } + } + + if (!isAccessible) + { + Console.WriteLine($"Error: Device did not respond within {timeoutSeconds} seconds."); + } } return Task.CompletedTask; } diff --git a/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/Properties/launchSettings.json b/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/Properties/launchSettings.json index 10bbc613a..36c51c77b 100644 --- a/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/Properties/launchSettings.json +++ b/src/tools/src/PlcSimAdvancedStarter/PlcSimAdvancedStarterTool/Properties/launchSettings.json @@ -3,7 +3,7 @@ "startplcsim": { "commandName": "Project", "workingDirectory": "", - "commandLineArgs": "startplcsim -x abc16 -n test_plc -t 10.10.10.120" + "commandLineArgs": "startplcsim -x app_axopen.components.abb.robotics -n test_plc -t 10.10.10.120" } } }