Skip to content

Commit

Permalink
Create draft PR for #498 (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomKovac authored Dec 16, 2024
1 parent 9a27098 commit 7489032
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit 7489032

Please sign in to comment.