using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.Serialization;
using System.Collections.Concurrent;
using System.ServiceModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using NLog;
using NLog.Config;
using NLog.Targets;
using GZ.DB.Map.OIDATABASE;
using GZ.DB.App.OIDATABASE;
using GZ.DB.Repository.OIDATABASE;
using GZ.DB.IRepository.OIDATABASE;
using GZ.DB.Entity.OIDATABASE;
namespace GZ.Projects.AuxAllWCS
{
///
/// 事件
///
public partial class ViewModel : System.ComponentModel.INotifyPropertyChanged
{
bool IsExitApp = false;
ConcurrentStack ExitJudgeStack = new ConcurrentStack();
System.Net.HttpListener HttpSvcHost = null;
#region View1事件
///
/// View1打开事件
///
///
///
public void View1_LoadEvent(object sender, RoutedEventArgs e)
{
try
{
//HttpSvcHost = new System.Net.HttpListener();
//HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
//HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/");
//HttpSvcHost.Start();
//HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
View1_Init(sender, e);
///
/// 程序片段:初始化配置
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250323111613779][业务逻辑.初始化配置]
Action myDelegate = () => SettingInit();
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadSettingInit", new object[] { tag, myDelegate });
#endregion [脚本][20250323111613779][业务逻辑.初始化配置]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(10000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:捷瞬抓臂1
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadJS1", new object[] { tag });
#endregion [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:捷瞬抓臂2
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadJS2", new object[] { tag });
#endregion [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:自流转流程
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
//foreach(var di in Settings.deviceInfos)
// if (di.deviceType == 2 || di.deviceType == 1)
// RunafterMac(di,true);
/// TODO mes 下发。 改成机械臂监控 - 监控空的还是满的 - 联动mes 任务。
//LogHelper.Info($"设备状态:维希尔1:维希尔抓臂1.State:{Device.维希尔抓臂1.State} ");
//Device.维希尔抓臂1.ReadPLC("维希尔抓臂1.R50", out object value);
//LogHelper.Info($"设备状态:维希尔1:维希尔抓臂1.R50:{value?.ToString()} ");
//LogHelper.Info($"设备状态:维希尔2:维希尔抓臂2.State:{Device.维希尔抓臂2.State} ");
//Device.维希尔抓臂2.ReadPLC("维希尔抓臂2.R50", out value);
//LogHelper.Info($"设备状态:维希尔2:维希尔抓臂2.R50:{value?.ToString()} ");
//LogHelper.Info($"设备状态:捷瞬1:Js捷顺1.State:{Device.Js捷顺1.State} ");
//Device.Js捷顺1.ReadPLC("Js捷顺1.D1202", out value);
//LogHelper.Info($"设备状态:捷瞬1 Js捷顺1.D1202:{value?.ToString()} ");
//LogHelper.Info($"设备状态:捷瞬2:Js捷顺2.State:{Device.Js捷顺2.State} ");
//Device.Js捷顺2.ReadPLC("Js捷顺2.D1202", out value);
//LogHelper.Info($"设备状态:捷瞬2 Js捷顺2.D1202:{value?.ToString()} ");
#endregion [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:维希尔抓臂1L
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
AutoThread.InvokeMethod(AutoThread.Instance, "Threadwxr1L", new object[] { tag });
#endregion [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:维希尔抓臂1R
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
AutoThread.InvokeMethod(AutoThread.Instance, "Threadwxr1R", new object[] { tag });
#endregion [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:维希尔抓臂2L
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
AutoThread.InvokeMethod(AutoThread.Instance, "Threadwxr2L", new object[] { tag });
#endregion [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:维希尔抓臂2R
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
AutoThread.InvokeMethod(AutoThread.Instance, "Threadwxr2R", new object[] { tag });
#endregion [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:任务下发
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250325085542733][业务逻辑.任务下发]
Func myDelegate = (t) => RunTask(t);
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadTaskRun", new object[] { tag, myDelegate });
#endregion [脚本][20250325085542733][业务逻辑.任务下发]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:ResolveMesTask
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250531163716255][业务逻辑.处理MES任务线程.ResolveMesTask]
//mes 任务拆分。一段任务和 多段任务。
ToWMSMES.ResMesTask(tag);
#endregion [脚本][20250531163716255][业务逻辑.处理MES任务线程.ResolveMesTask]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
try
{
#region [脚本][20250605212104026][业务逻辑.SocketServer]
AutoThread.InvokeMethod(AutoThread.Instance, "TaskEverythingRun");
#endregion [脚本][20250605212104026][业务逻辑.SocketServer]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
}
///
/// 程序片段:光栅处理
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250611223832523][业务逻辑.光栅处理]
// - 光栅交互处理。。
Action myDelegate = (t) => continueTask(t);
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadGrats", new object[] { tag, myDelegate });
// 发那科下料光栅。
#endregion [脚本][20250611223832523][业务逻辑.光栅处理]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:1020空框下线
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
//1020 1023 空框下线
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadEdown", new object[] { tag });
#endregion [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:1023空框下线
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616094226654][业务逻辑.流程2热处理炉进出.1023空框下线]
//1023 空框下线
#endregion [脚本][20250616094226654][业务逻辑.流程2热处理炉进出.1023空框下线]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:定子满下线
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
//定子满下线 1008 1016 -> 1026
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadDdown", new object[] { tag });
#endregion [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:转子满下线
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
//转子满下线 1002 1010 - RGV2工位不可到 1017 不可下发2工位任务。
AutoThread.InvokeMethod(AutoThread.Instance, "Thread0210Down", new object[] { tag });
#endregion [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:下料位检测
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
//下料位检测。 1003 到位时 写 标识信号 并 给机械手信号。
AutoThread.InvokeMethod(AutoThread.Instance, "Thread下料位检测", new object[] { tag });
#endregion [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:1号FNK机械手完成
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadFNK1Over", new object[] { tag });
#endregion [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:2号FNK机械手完成
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
AutoThread.InvokeMethod(AutoThread.Instance, "ThreadFNK2Over", new object[] { tag });
#endregion [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:Program1
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
AutoThread.InvokeMethod(AutoThread.Instance, "Thread1019Down", new object[] { tag });
#endregion [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:Program1
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
AutoThread.InvokeMethod(AutoThread.Instance, "Thread1025Up", new object[] { tag });
#endregion [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:Program1
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
AutoThread.InvokeMethod(AutoThread.Instance, "Thread1022Up", new object[] { tag });
#endregion [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:Program1
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
AutoThread.InvokeMethod(AutoThread.Instance, "Thread1030Down", new object[] { tag });
#endregion [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
///
/// 程序片段:Program1
/// 描述:
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
AutoThread.InvokeMethod(AutoThread.Instance, "Thread2030Down", new object[] { tag });
#endregion [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
//执行多次
for (int iii = 0; iii < 1; iii++)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250323151832119][业务逻辑.Program4]
//LogHelper.Info($"<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>");
//LogHelper.Info($"<<<<<<<<<<<<<<<<<程序·启动>>>>>>>>>>>>>>");
//// 使用拦截器
//var interceptor = new ConsoleInterceptor();
//Console.SetOut(interceptor);
//LogHelper.Info($"<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>");
//AnsiConsole.Markup("[underline red]Hello[/] World!");
// AnsiConsole.Markup("[underline red]Hello[/] World!");
#endregion [脚本][20250323151832119][业务逻辑.Program4]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
///
/// 程序片段:新线程总线
/// 描述:1
///
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Thread.CurrentThread.IsBackground = true;
ExitJudgeStack.Push(0);
//一直执行,直到满足结束条件
while (true)
{
if (IsExitApp) { break; }
try
{
#region [脚本][20250708095248653][业务逻辑.新线程总线]
AutoThread.InvokeMethod(AutoThread.Instance, "ThreaTotal", new object[] { tag });
#endregion [脚本][20250708095248653][业务逻辑.新线程总线]
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
System.Threading.Thread.Sleep(3000);
}
}
ExitJudgeStack.TryPop(out int exitJudgeVal);
});
}
///
/// View1关闭事件
///
///
///
public void View1_CloseEvent(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
System.Threading.Tasks.Task.Factory.StartNew(() => { MessageBox.Show("程序正在关闭,请等待..."); });
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
try
{
Conn.默认日志.Debug("[关闭处理][Start]关闭Http服务");
if (HttpSvcHost != null)
{
HttpSvcHost.Stop();
}
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
Conn.默认日志.Debug("[关闭处理][End]关闭Http服务");
}
try
{
Conn.默认日志.Debug("[关闭处理][Start]判断业务处理状态");
IsExitApp = true;
//int exitCnt = 0;
while
(
ExitJudgeStack.Count > 0
)
{
System.Threading.Thread.Sleep(100);
//++exitCnt;
//10秒未结束则强制关闭
//if (exitCnt >= 100)
//{
// break;
//}
}
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
Conn.默认日志.Debug("[关闭处理][End]判断业务处理状态");
}
e.Cancel = true;
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
try
{
Conn.默认日志.Debug("[关闭处理][Start]关闭PLC");
Device.维希尔抓臂1?.Stop();
Device.维希尔抓臂2?.Stop();
Device.Js捷顺1?.Stop();
Device.Js捷顺2?.Stop();
Device.p发那科1下线?.Stop();
Device.A1025放货交互?.Stop();
Device.A1022放货交互?.Stop();
Device.A1019取货交互?.Stop();
Device.A1030取货交互?.Stop();
Device.SSXReadTemp?.Stop();
Device.S1019Read?.Stop();
Device.S1022Read?.Stop();
Device.S1025Read?.Stop();
Device.S1017Read?.Stop();
Device.S1023Read?.Stop();
Device.S1020Read?.Stop();
Device.S1002Read?.Stop();
Device.S1004Read?.Stop();
Device.S1006Read?.Stop();
Device.S1008Read?.Stop();
Device.S1010Read?.Stop();
Device.S1012Read?.Stop();
Device.S1014Read?.Stop();
Device.S1016Read?.Stop();
Device.FNK1003051113?.Stop();
Device.SSX1003051113?.Stop();
Device.S1026Read?.Stop();
Device.S1030Read?.Stop();
Device.S2001Read?.Stop();
Device.S2030Read?.Stop();
Device.A2001放货交互?.Stop();
Device.A2030取货交互?.Stop();
Device.RGV?.Stop();
Device.p发那科2下线?.Stop();
Device.p发那科3上线?.Stop();
Device.p发那科4上线?.Stop();
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
Conn.默认日志.Debug("[关闭处理][End]关闭PLC");
}
try
{
Conn.默认日志.Debug("[关闭处理][Start]判断PLC状态");
//int exitCnt = 0;
while
(
false
|| (Device.维希尔抓臂1 == null ? false : Device.维希尔抓臂1.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.维希尔抓臂2 == null ? false : Device.维希尔抓臂2.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.Js捷顺1 == null ? false : Device.Js捷顺1.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.Js捷顺2 == null ? false : Device.Js捷顺2.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.p发那科1下线 == null ? false : Device.p发那科1下线.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.A1025放货交互 == null ? false : Device.A1025放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.A1022放货交互 == null ? false : Device.A1022放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.A1019取货交互 == null ? false : Device.A1019取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.A1030取货交互 == null ? false : Device.A1030取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.SSXReadTemp == null ? false : Device.SSXReadTemp.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1019Read == null ? false : Device.S1019Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1022Read == null ? false : Device.S1022Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1025Read == null ? false : Device.S1025Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1017Read == null ? false : Device.S1017Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1023Read == null ? false : Device.S1023Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1020Read == null ? false : Device.S1020Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1002Read == null ? false : Device.S1002Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1004Read == null ? false : Device.S1004Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1006Read == null ? false : Device.S1006Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1008Read == null ? false : Device.S1008Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1010Read == null ? false : Device.S1010Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1012Read == null ? false : Device.S1012Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1014Read == null ? false : Device.S1014Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1016Read == null ? false : Device.S1016Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.FNK1003051113 == null ? false : Device.FNK1003051113.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.SSX1003051113 == null ? false : Device.SSX1003051113.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1026Read == null ? false : Device.S1026Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S1030Read == null ? false : Device.S1030Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S2001Read == null ? false : Device.S2001Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.S2030Read == null ? false : Device.S2030Read.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.A2001放货交互 == null ? false : Device.A2001放货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.A2030取货交互 == null ? false : Device.A2030取货交互.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.RGV == null ? false : Device.RGV.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.p发那科2下线 == null ? false : Device.p发那科2下线.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.p发那科3上线 == null ? false : Device.p发那科3上线.State != GZ.Device.PLC.PlcRunState.Stoped)
|| (Device.p发那科4上线 == null ? false : Device.p发那科4上线.State != GZ.Device.PLC.PlcRunState.Stoped)
)
{
System.Threading.Thread.Sleep(1000);
//++exitCnt;
//10秒未结束则强制关闭
//if (exitCnt >= 100)
//{
// break;
//}
}
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
finally
{
Conn.默认日志.Debug("[关闭处理][End]判断PLC状态");
}
Application.Current.Dispatcher.Invoke(() => { Environment.Exit(0); });
});
//System.Windows.Application.Current.Shutdown();
}
///
/// View1初始化
///
///
///
public void View1_Init(object sender, RoutedEventArgs e)
{
}
#endregion
#region View2事件
///
/// View2打开事件
///
///
///
public void View2_LoadEvent(object sender, RoutedEventArgs e)
{
}
///
/// View2关闭事件
///
///
///
public void View2_CloseEvent(object sender, System.ComponentModel.CancelEventArgs e)
{
}
///
/// View2初始化
///
///
///
public void View2_Init(object sender, RoutedEventArgs e)
{
}
#endregion
#region 切换tab页
public void tab_SelectionChanged(object sender, EventArgs e)
{
//TabItem ti = (sender as TabControl).SelectedItem as TabItem;
//MessageBox.Show(ti.Name);
}
#endregion
#region Http服务监听
private void HttpSvcListenerCallback(IAsyncResult ar)
{
try
{
HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar);
System.Net.HttpListenerRequest request = context.Request;
System.Net.HttpListenerResponse response = context.Response;
switch (request.LocalEndPoint.ToString())
{
case "10.221.55.117:8808":
{
using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8))
{
string requestJson = reader.ReadToEnd();
string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out System.Net.HttpStatusCode statusCode);
string logContent = "";
logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}";
logContent += $"\r\n[request]{requestJson}";
logContent += $"\r\n[response]{respstr}";
Conn.默认日志?.Info(logContent);
byte[] bytstr = Encoding.UTF8.GetBytes(respstr);
response.StatusCode = (int)statusCode;
response.SendChunked = false;
response.ContentLength64 = bytstr.Length;
response.OutputStream.Write(bytstr, 0, bytstr.Length);
response.Close();
}
break;
}
}
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
}
}
private System.String HttpSvcListenerCallback_he(System.String method, System.String path, System.String requestJson, out System.Net.HttpStatusCode statusCode)
{
try
{
switch (method)
{
case "POST":
{
switch (path)
{
case "/agv/agvCallbackService/agvCallback":
{
statusCode = System.Net.HttpStatusCode.OK;
LogHelper.Info("ExecuteState Request-haikang:" + requestJson);
var model = JsonConvert.DeserializeObject(requestJson);
OperateHKTaskStatus(model);
return JsonConvert.SerializeObject(new HkReturnResult { reqCode = model.reqCode });
}
case "/api/Wcs/CreateTask":
{
statusCode = System.Net.HttpStatusCode.OK;
LogHelper.Info("/api/Wcs/CreateTask:" + requestJson);
var model = JsonConvert.DeserializeObject(requestJson);
var res = ToWMSMES.CreateTask.CreatemesTask(model);
return JsonConvert.SerializeObject(res);
}
case "/api/Wcs/TestRequestTask":
{
statusCode = System.Net.HttpStatusCode.OK;
LogHelper.Info("/api/Wcs/TestRequestTask:" + requestJson);
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", requestJson);
return str;
}
case "/api/Wcs/updateStatus":
{
statusCode = System.Net.HttpStatusCode.OK;
LogHelper.Info("/api/Wcs/updateStatus:" + requestJson);
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/201", requestJson);
return str;
}
case "/api/Wcs/toMes":
{
statusCode = System.Net.HttpStatusCode.OK;
LogHelper.Info("/api/Wcs/toMes:" + requestJson);
var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
return str;
}
case "/api/Wcs/CreatePointTask":
{
statusCode = System.Net.HttpStatusCode.OK;
LogHelper.Info("/api/Wcs/CreatepointTask:" + requestJson);
var model = JsonConvert.DeserializeObject(requestJson);
var res = ToWMSMES.CreateTask.CreatePointTask(model);
return JsonConvert.SerializeObject(res);
}
}
break;
}
case "GET":
{
switch (path)
{
case "/inddddddddddddddddd":
{
statusCode = System.Net.HttpStatusCode.OK;
// 复制到case 上
//var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
var filePath = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\Static", path.Substring(1));
return File.ReadAllText(filePath);
}
}
break;
}
}
statusCode = System.Net.HttpStatusCode.NotFound;
return "";
}
catch (Exception ex)
{
Conn.默认日志.Error(ex.ToString());
statusCode = System.Net.HttpStatusCode.InternalServerError;
return "";
}
}
#endregion
}
}