|
|
|
@ -81,7 +81,7 @@ namespace XGL.FormItem
|
|
|
|
this.myTb.SetBinding(TextBlock.TextProperty, textBinding);
|
|
|
|
this.myTb.SetBinding(TextBlock.TextProperty, textBinding);
|
|
|
|
|
|
|
|
|
|
|
|
InitPage();
|
|
|
|
InitPage();
|
|
|
|
GetServiceDelay(Utils.GetServerIP());
|
|
|
|
GetServiceDelay(Utils.GetServerIP());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitPage()
|
|
|
|
private void InitPage()
|
|
|
|
@ -177,6 +177,9 @@ namespace XGL.FormItem
|
|
|
|
timerDeciveState.Elapsed += TimerDeciveState_Elapsed;
|
|
|
|
timerDeciveState.Elapsed += TimerDeciveState_Elapsed;
|
|
|
|
timerDeciveState.Start();
|
|
|
|
timerDeciveState.Start();
|
|
|
|
this.lbVersion.Content = LoginUser.Version;
|
|
|
|
this.lbVersion.Content = LoginUser.Version;
|
|
|
|
|
|
|
|
FormingMachineService formingMachineService = new FormingMachineService();
|
|
|
|
|
|
|
|
DataTable dtDeviceIP = formingMachineService.GetFormingMachineState(deviceCode);
|
|
|
|
|
|
|
|
GetDevicePingResult(dtDeviceIP.Rows[0][1].ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -243,6 +246,59 @@ namespace XGL.FormItem
|
|
|
|
}, 1, 0, 2000);
|
|
|
|
}, 1, 0, 2000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void GetDevicePingResult(string serviceIp)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Time = new System.Threading.Timer((s) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PingTest(serviceIp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 1, 0, 2000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void PingTest(string ip)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string ipAddress = ip;//"192.168.1.1"; // 你要 ping 的 IP 地址
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ping pingSender = new Ping();
|
|
|
|
|
|
|
|
PingOptions options = new PingOptions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options.DontFragment = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|
|
|
|
|
|
|
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);
|
|
|
|
|
|
|
|
int timeout = 120;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);
|
|
|
|
|
|
|
|
if (reply.Status != IPStatus.Success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
|
|
|
string logMessage = $"Ping failed to {ipAddress} at {DateTime.Now}. Reason: {reply.Status}";
|
|
|
|
|
|
|
|
//WriteToLogFile(logMessage);
|
|
|
|
|
|
|
|
LogHelper.instance.log.Error(logMessage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 这里你可以添加其他处理逻辑,或者退出循环
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"Ping successful to {ipAddress}. Reply time: {reply.RoundtripTime}ms");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 可以设定一个间隔时间,然后再次 ping
|
|
|
|
|
|
|
|
//System.Threading.Thread.Sleep(5000); // 5 秒
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SerialHelper serialHelper = new SerialHelper();
|
|
|
|
SerialHelper serialHelper = new SerialHelper();
|
|
|
|
int time = 0;
|
|
|
|
int time = 0;
|
|
|
|
private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e)
|
|
|
|
private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e)
|
|
|
|
|