交接班、设备ping测试

master
zhaoaomin 2 years ago
parent e0cb00aec5
commit fcb9959490

Binary file not shown.

@ -142,7 +142,7 @@ namespace XGL.Data.DBService
public DataTable GetFormingMachineState(string devicecode)
{
string sql = $@"select status from base_equipment where equipment_code = '{devicecode}'; ";
string sql = $@"select status,plc_ip from base_equipment where equipment_code = '{devicecode}'; ";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
@ -537,11 +537,13 @@ VALUES
return sqlList;//> 0 ? true : false;
}
public void ChangeShiftsInfo()
public bool ChangeShiftsInfo()
{
//
string sql = $@"INSERT INTO [dbo].[mes_changeshift_info] ([id], [shift_code], [change_time], [create_time], [create_by], [last_update], [update_by], [work_date])
VALUES ('1', NULL, NULL, NULL, NULL, NULL, NULL, NULL);";
VALUES ('{Common.GetUUID()}', '{LoginUser.ShiftCode}', GetDate(), GetDate(), '{LoginUser.UserName}', GetDate(), '{LoginUser.UserName}', '{LoginUser.WorkDate}');";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}

@ -12,7 +12,7 @@
<!--设备编码-->
<add key="DeviceCode" value="C3" />
<!--上位机类型 0:工单准备1成型机\shoupei2烘房,3:人员登录-->
<add key="ClientMode" value="0" />
<add key="ClientMode" value="1" />
<add key="SerialPort" value="COM5" />
<add key="DryingHouseList" value="H16,H17,H18"/>
<!--线体编码-->

@ -81,7 +81,7 @@ namespace XGL.FormItem
this.myTb.SetBinding(TextBlock.TextProperty, textBinding);
InitPage();
GetServiceDelay(Utils.GetServerIP());
GetServiceDelay(Utils.GetServerIP());
}
private void InitPage()
@ -177,6 +177,9 @@ namespace XGL.FormItem
timerDeciveState.Elapsed += TimerDeciveState_Elapsed;
timerDeciveState.Start();
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);
}
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();
int time = 0;
private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e)

Loading…
Cancel
Save