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
|
{
|
/// <summary>
|
/// 事件
|
/// </summary>
|
public partial class ViewModel : System.ComponentModel.INotifyPropertyChanged
|
{
|
bool IsExitApp = false;
|
ConcurrentStack<int> ExitJudgeStack = new ConcurrentStack<int>();
|
System.Net.HttpListener HttpSvcHost = null;
|
|
#region View1事件
|
/// <summary>
|
/// View1打开事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
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.116:8808/");
|
HttpSvcHost.Start();
|
HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
View1_Init(sender, e);
|
|
/// <summary>
|
/// 程序片段:初始化配置
|
/// 描述:
|
/// </summary>
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
{
|
System.Threading.Thread.CurrentThread.IsBackground = true;
|
ExitJudgeStack.Push(0);
|
//一直执行,直到满足结束条件
|
while(true)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250323111613779][业务逻辑.初始化配置]
|
if (Tag.Global.SettingsOver == 0)
|
{
|
SettingInit();
|
Tag.Global.SettingsOver = 1;
|
}
|
else if(Settings.deviceInfos.Count == 0)
|
{
|
Tag.Global.SettingsOver = 0;
|
}
|
|
#endregion [脚本][20250323111613779][业务逻辑.初始化配置]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(10000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
//执行多次
|
for(int iii=0;iii<1;iii++)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250323151832119][业务逻辑.Program4]
|
//Conn.默认Redis.SetValue("西门子2.Param3","300","西门子2Queue");
|
//return;
|
if(false){
|
List<string> locs = new List<string>() { "vxr1l", "vx1r", "vxr1c1", "vxr1c2", "vxr2l", "vxr2r", "vxr2c1", "vxr2c2" };
|
List<string> sites = new List<string>() { "196365BB283162", "193841BB283149", "198756BB287300", "198767BB286133", "206987BB282931", "204460BB282975", "209405BB287057", "209377BB285899" };
|
|
LocRepository locservice = new LocRepository();
|
for (int i = 0; i < locs.Count; i++)
|
{
|
string loccode = locs[i];
|
string sitesss = sites[i];
|
var loc = locservice.FindEntity(x => x.S_LOC_CODE == loccode);
|
if (loc == null)
|
{
|
locservice.Insert(new LocEntity
|
{
|
S_ID = Guid.NewGuid().ToString(),
|
S_STATE = "编辑",
|
T_CREATE = DateTime.Now,
|
T_MODIFY = DateTime.Now,
|
S_DEEP = "vxr",
|
|
S_LOC_CODE = loccode,
|
S_AGV_SITE = sitesss,
|
|
S_LOCK_STATE = "无",
|
N_ROW = 1,
|
N_COL = 1,
|
N_AGV_CODE = 0,
|
N_AGV_SITE_LAYER = 0,
|
N_CAPACITY = 1,
|
N_CURRENT_NUM = 0,
|
S_TYPE = "",
|
|
});
|
}
|
}
|
// TaskProcess.CreateTask("", locs[6], locs[7], "test", 9, new List<string> { "test" }, 1, 1, 1);
|
}
|
|
#endregion [脚本][20250323151832119][业务逻辑.Program4]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
/// <summary>
|
/// 程序片段:捷瞬抓臂1
|
/// 描述:
|
/// </summary>
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
{
|
System.Threading.Thread.CurrentThread.IsBackground = true;
|
ExitJudgeStack.Push(0);
|
//一直执行,直到满足结束条件
|
while(true)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
|
var VERX = Settings.deviceInfos?.Find(x =>x.deviceType==2&& x.deviceName == "Js捷顺1");
|
|
if (VERX != null)
|
{
|
if (tag.Js1.D1212_LAST == 0 && TcpServer.GetBitdata(tag.Js1.D1212, 2) == 1)
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 4,
|
endBit = VERX.location[0]
|
}));
|
LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.Js1.D1212_LAST = 1;
|
}
|
}
|
if(tag.Js1.D1212_LAST == 1 &&TcpServer.GetBitdata(tag.Js1.D1212, 2) == 0){
|
tag.Js1.D1212_LAST = 0;
|
}
|
if (tag.Js1.D1213_LAST == 0 && TcpServer.GetBitdata(tag.Js1.D1212, 3) == 1)
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 4,
|
endBit = VERX.location[1]
|
}));
|
LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.Js1.D1213_LAST = 1;
|
}
|
}if(tag.Js1.D1213_LAST == 1 &&TcpServer.GetBitdata(tag.Js1.D1212, 3) == 0){
|
tag.Js1.D1213_LAST = 0;
|
}
|
}
|
#endregion [脚本][20250325083325390][业务逻辑.第三标段.捷瞬抓臂1]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:捷瞬抓臂2
|
/// 描述:
|
/// </summary>
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
{
|
System.Threading.Thread.CurrentThread.IsBackground = true;
|
ExitJudgeStack.Push(0);
|
//一直执行,直到满足结束条件
|
while(true)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
|
//jsz2捷瞬抓臂2
|
|
var VERX = Settings.deviceInfos?.Find(x =>x.deviceType==2&& x.deviceName == "Js捷顺2");
|
|
if (VERX != null)
|
{
|
if (tag.Js2.D1212_LAST == 0 && TcpServer.GetBitdata(tag.Js2.D1212, 2) == 1)
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 4,
|
endBit = VERX.location[0]
|
}));
|
LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.Js2.D1212_LAST = 1;
|
}
|
} if(tag.Js2.D1212_LAST == 1 &&TcpServer.GetBitdata(tag.Js2.D1212, 2) == 0){
|
tag.Js2.D1212_LAST = 0;
|
}
|
if (tag.Js2.D1213_LAST == 0 && TcpServer.GetBitdata(tag.Js2.D1212, 3) == 1)
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 4,
|
endBit = VERX.location[1]
|
}));
|
LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.Js2.D1213_LAST = 1;
|
}
|
}if(tag.Js2.D1213_LAST == 1 &&TcpServer.GetBitdata(tag.Js2.D1213, 2) == 0){
|
tag.Js2.D1213_LAST = 0;
|
}
|
}
|
#endregion [脚本][20250325083326611][业务逻辑.第三标段.捷瞬抓臂2]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:自流转流程
|
/// 描述:
|
/// </summary>
|
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 任务。
|
#endregion [脚本][20250325085810885][业务逻辑.第三标段.自流转流程]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:维希尔抓臂1L
|
/// 描述:
|
/// </summary>
|
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]
|
|
var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("1"));
|
|
if (VERX != null)
|
{
|
if (tag.wxr1.R44 && !tag.wxr1.R44_LAST && tag.wxr1.R10)
|
{
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode))
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 1,
|
cntrCode = traycode,
|
startBit = VERX.location[0],
|
endBit = ""
|
}));
|
LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.wxr1.R44_LAST = true;
|
}
|
}
|
else
|
{
|
TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E"));
|
}
|
}
|
else
|
{
|
//TaskRepository ts = new TaskRepository();
|
if (tag.wxr1.R10_LAST) //托盘放置信号。。
|
{
|
if (tag.wxr1.R10)
|
{
|
tag.wxr1.R10_LAST=false;
|
} else
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0],out string traycode))
|
{
|
//上报校验。
|
///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
|
{
|
sceneType = 1,
|
cntrCode = traycode,
|
}));
|
if (str.Contains("true"))
|
{
|
//Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
|
tag.wxr1.R10 = true;
|
tag.wxr1.R44_LAST = false;
|
}
|
else
|
{
|
//报警。
|
}
|
}
|
else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
|
}
|
}
|
}
|
#endregion [脚本][20250325083149366][业务逻辑.第三标段.维系尔1号.维希尔抓臂1L]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:维希尔抓臂1R
|
/// 描述:
|
/// </summary>
|
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]
|
var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("1"));
|
|
if (VERX != null)
|
{
|
if (tag.wxr1.R46 && !tag.wxr1.R46_LAST && tag.wxr1.R11)
|
{
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode))
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 1,
|
cntrCode = traycode,
|
startBit = VERX.location[1],
|
endBit = ""
|
}));
|
LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.wxr1.R46_LAST = true;
|
}
|
}
|
else
|
{
|
TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E"));
|
}
|
}
|
else
|
{
|
if (tag.wxr1.R11_LAST) //托盘放置信号。。
|
{
|
if (tag.wxr1.R11)
|
{
|
tag.wxr1.R11_LAST=false;
|
} else
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1],out string traycode))
|
{
|
//上报校验。
|
///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
|
{
|
sceneType = 1,
|
cntrCode = traycode,
|
}));
|
if (str.Contains("true"))
|
{
|
//Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
|
tag.wxr1.R11 = true;
|
tag.wxr1.R46_LAST = false;
|
}
|
else
|
{
|
//报警。
|
}
|
}
|
else { TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
|
}
|
}
|
}
|
#endregion [脚本][20250610002047005][业务逻辑.第三标段.维系尔1号.维希尔抓臂1R]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:维希尔抓臂2L
|
/// 描述:
|
/// </summary>
|
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]
|
|
var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("2"));
|
|
if (VERX != null)
|
{
|
if (tag.wxr2.R44 && !tag.wxr2.R44_LAST && tag.wxr2.R10)
|
{
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode))
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 1,
|
cntrCode = traycode,
|
startBit = VERX.location[0],
|
endBit = ""
|
}));
|
LogHelper.Info($"{VERX.location[0]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.wxr2.R44_LAST = true;
|
}
|
}
|
else
|
{
|
TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E"));
|
}
|
}
|
else
|
{
|
if (tag.wxr2.R10_LAST) //托盘放置信号。。
|
{
|
if (tag.wxr2.R10)
|
{
|
tag.wxr2.R10_LAST=false;
|
} else
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0],out string traycode))
|
{
|
//上报校验。
|
///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
|
{
|
sceneType = 1,
|
cntrCode = traycode,
|
}));
|
if (str.Contains("true"))
|
{
|
//Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
|
tag.wxr2.R10 = true;
|
tag.wxr2.R44_LAST = false;
|
}
|
else
|
{
|
//报警。
|
}
|
}
|
else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
|
}
|
}
|
}
|
#endregion [脚本][20250325083315503][业务逻辑.第三标段.维系尔2号.维希尔抓臂2L]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:维希尔抓臂2R
|
/// 描述:
|
/// </summary>
|
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]
|
var VERX = Settings.deviceInfos?.Find(x => x.deviceType == 1 && x.deviceName.Contains("2"));
|
|
if (VERX != null)
|
{
|
if (tag.wxr2.R46 && !tag.wxr2.R46_LAST && tag.wxr2.R11)
|
{
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode))
|
{
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", JsonConvert.SerializeObject(new
|
{
|
requestType = 1,
|
cntrCode = traycode,
|
startBit = VERX.location[1],
|
endBit = ""
|
}));
|
LogHelper.Info($"{VERX.location[1]}申请mes任务结果{str}");
|
if (str.Contains("true"))
|
{
|
tag.wxr2.R46_LAST = true;
|
}
|
}
|
else
|
{
|
TcpServer.TcpServerSend(VERX.deviceNo[2], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E"));
|
}
|
}
|
else
|
{
|
if (tag.wxr2.R11_LAST) //托盘放置信号。。
|
{
|
if (tag.wxr2.R11)
|
{
|
tag.wxr2.R11_LAST=false;
|
} else
|
if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1],out string traycode))
|
{
|
//上报校验。
|
///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
|
var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
|
{
|
sceneType = 1,
|
cntrCode = traycode,
|
}));
|
if (str.Contains("true"))
|
{
|
//Conn.默认Redis.SetValue("维希尔抓臂1.R10", "true", "维希尔抓臂1Queue");
|
tag.wxr2.R11 = true;
|
tag.wxr2.R46_LAST = false;
|
}
|
else
|
{
|
//报警。
|
}
|
}
|
else { TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
|
}
|
}
|
}
|
#endregion [脚本][20250610002647095][业务逻辑.第三标段.维系尔2号.维希尔抓臂2R]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:任务下发
|
/// 描述:
|
/// </summary>
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
{
|
System.Threading.Thread.CurrentThread.IsBackground = true;
|
ExitJudgeStack.Push(0);
|
//一直执行,直到满足结束条件
|
while(true)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250325085542733][业务逻辑.任务下发]
|
|
#endregion [脚本][20250325085542733][业务逻辑.任务下发]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:ResolveMesTask
|
/// 描述:
|
/// </summary>
|
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();
|
#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]
|
var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
|
foreach (var ip in host.AddressList)
|
{
|
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
{
|
Console.WriteLine($"ip= {ip.ToString()}");
|
new TcpServer(ip.ToString());
|
}
|
}
|
#endregion [脚本][20250605212104026][业务逻辑.SocketServer]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
}
|
/// <summary>
|
/// 程序片段:光栅处理
|
/// 描述:
|
/// </summary>
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
{
|
System.Threading.Thread.CurrentThread.IsBackground = true;
|
ExitJudgeStack.Push(0);
|
//一直执行,直到满足结束条件
|
while(true)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250611223832523][业务逻辑.光栅处理]
|
// - 光栅交互处理。。
|
var taskCOdes = new List<string> { "Sarrive", "Srelease", "Earrive", "Erelease" };
|
TaskActRepository taskActRepository = new TaskActRepository();
|
TaskRepository taskRepository = new TaskRepository();
|
var requires = taskActRepository.FindList(x => taskCOdes.Contains(x.S_ACTION_CODE) && x.N_CREATEMETHOD == 0);
|
foreach (var item in requires)
|
{
|
var tin = taskCOdes.IndexOf(item.S_ACTION_CODE);
|
if (tin == -1)
|
{
|
item.N_CREATEMETHOD = -1;
|
taskActRepository.Update(item);
|
continue;
|
}
|
//var task = taskRepository.FindEntity(x => x.S_TASK_NO == item.S_TASK_NO);
|
string loc = "";
|
if (tin < 2)
|
{
|
loc = item.S_START_LOC;
|
}
|
else
|
{
|
loc = item.S_END_LOC;
|
}
|
if (loc == null) continue; else loc = loc.Trim();
|
bool goin = tin % 2 == 0;
|
bool continuuuuu =false;
|
var dev = Settings.deviceInfos.Find(x => x.location.Contains(loc));
|
if (dev != null)
|
{
|
var V = dev.location.ToList().FindIndex(x => x == loc) == 0;
|
//车走了 开光栅
|
if (!goin)
|
{
|
if (dev.deviceType == 1)
|
{
|
LogHelper.Info($"{dev.deviceName}{(V ? "左" : "右")} 光栅{(goin?"关闭":"开启")} 申请。"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "R02" : "R04"), "true", dev.deviceName + "Queue"));
|
Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "R02" : "R04"), "true", dev.deviceName + "Queue");
|
|
}
|
else if (dev.deviceType == 2)
|
{
|
LogHelper.Info($"{dev.deviceName}{(V ? "左" : "右")} 光栅{(goin?"关闭":"开启")} 申请。"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue"));
|
Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1222" : "D1223"), "1", dev.deviceName + "Queue");
|
}
|
|
item.N_CREATEMETHOD = 1;
|
taskActRepository.Update(item);
|
}
|
//车要进入交互。
|
else
|
{
|
if (dev.deviceType == 1)
|
{
|
var tf = Conn.默认Redis.GetValue(dev.deviceName + "." + (V ? "R50" : "R52"));//读关闭状态
|
if (tf?.ToLower() == "true")
|
{
|
LogHelper.Info($"{dev.deviceName}{(V ? "左" : "右")} 光栅{(goin?"关闭":"开启")} 申请。 已经关闭!");
|
continuuuuu = true;
|
}
|
else
|
{
|
LogHelper.Info($"{dev.deviceName}{(V ? "左" : "右")} 光栅{(goin?"关闭":"开启")} 申请。"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "R01" : "R03"), "true", dev.deviceName + "Queue"));
|
Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "R01" : "R03"), "true", dev.deviceName + "Queue");
|
}
|
|
}
|
else if (dev.deviceType == 2)
|
{
|
var tf = Conn.默认Redis.GetValue(dev.deviceName + ".D1202");
|
int numm = int.Parse(string.IsNullOrEmpty(tf) ? "0" : tf);
|
if (TcpServer.GetBitdata(numm,(V?0:1))==1)
|
{
|
LogHelper.Info($"{dev.deviceName}{(V ? "左" : "右")} 光栅{(goin?"关闭":"开启")} 申请。 已经关闭!");
|
continuuuuu = true;
|
}
|
else
|
{
|
LogHelper.Info($"{dev.deviceName}{(V ? "左" : "右")} 光栅{(goin?"关闭":"开启")} 申请。"+string.Format("{0}{1}{2}", dev.deviceName + "." + (V ? "D1220" : "D1221"), dev.deviceName + "Queue"));
|
Conn.默认Redis.SetValue(dev.deviceName + "." + (V ? "D1220" : "D1221"), "1", dev.deviceName + "Queue");
|
}
|
}
|
|
}
|
|
}
|
if (continuuuuu)
|
{
|
LogHelper.Info($"{item.S_TASK_NO}{item.S_ACTION_CODE} 车辆发送继续任务!");
|
continueTask(new HaiKangOrderInfo
|
{
|
reqCode = item.S_ID.Replace("-", ""),
|
taskCode = item.S_TASK_NO
|
});
|
item.N_CREATEMETHOD = 1;
|
taskActRepository.Update(item);
|
}
|
}
|
System.Threading.Thread.Sleep(3000);
|
//重置信号
|
foreach (var dev in Settings.deviceInfos.FindAll(x => x.deviceType == 2))
|
{
|
var tf = Conn.默认Redis.GetValue(dev.deviceName + ".D1202");
|
int numm = int.Parse(string.IsNullOrEmpty(tf) ? "0" : tf);
|
if (TcpServer.GetBitdata(numm, 0) == 0)
|
{
|
Conn.默认Redis.SetValue(dev.deviceName + ".D1220", "0", dev.deviceName + "Queue");
|
Conn.默认Redis.SetValue(dev.deviceName + ".D1222", "0", dev.deviceName + "Queue");
|
}
|
else if (TcpServer.GetBitdata(numm, 1) == 0)
|
{
|
Conn.默认Redis.SetValue(dev.deviceName + ".D1221", "0", dev.deviceName + "Queue");
|
Conn.默认Redis.SetValue(dev.deviceName + ".D1223", "0", dev.deviceName + "Queue");
|
}
|
}
|
|
// 发那科下料光栅。
|
#endregion [脚本][20250611223832523][业务逻辑.光栅处理]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:1020空框下线
|
/// 描述:
|
/// </summary>
|
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空框下线]
|
foreach (var Bssx in new string[] { "1020", "1023" })
|
{
|
var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
|
var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
|
var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
|
Console.WriteLine($"{Bssx} 空下检测:任务申请:{RtaskState}- 是否已处理:{RtaskState_LAST}- 托盘码:{R托盘码}");
|
if (RtaskState == 3 && RtaskState_LAST == 0)
|
{
|
try
|
{
|
foreach (var item in new string[] { "1004", "1006", "1012", "1014" })
|
{
|
var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
|
var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
|
if (R5 == 5 && R5空闲_LAST == 0)
|
{
|
var b = TaskProcess.CreateTask("", Bssx, item, "空上RGV", 5, new List<string> { R托盘码 }, "RGV");
|
if (b)
|
{
|
LogHelper.Debug($"输送线RGV空托任务 from:{Bssx}>to {item}开始创建成功");
|
Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
|
//Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
|
Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg1);
|
//Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
|
break;
|
}
|
}
|
else if (R5 != 5 && R5空闲_LAST == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg);
|
//Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "0", $"S{item}ReadQueue");
|
}
|
}
|
System.Threading.Thread.Sleep(1000);
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Error(ex.Message, ex);
|
Console.WriteLine(ex.Message + ex.StackTrace);
|
}
|
}
|
else if (RtaskState != 3 && RtaskState_LAST == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
|
//Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "0", $"S{Bssx}ReadQueue");
|
}
|
System.Threading.Thread.Sleep(2000);
|
}
|
#endregion [脚本][20250616094224396][业务逻辑.流程2热处理炉进出.1020空框下线]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:1023空框下线
|
/// 描述:
|
/// </summary>
|
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);
|
});
|
/// <summary>
|
/// 程序片段:定子满下线
|
/// 描述:
|
/// </summary>
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
{
|
System.Threading.Thread.CurrentThread.IsBackground = true;
|
ExitJudgeStack.Push(0);
|
//一直执行,直到满足结束条件
|
while(true)
|
{
|
if (IsExitApp) { break; }
|
try
|
{
|
#region [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
|
foreach (var Bssx in new string[] { "1008", "1016" })
|
{
|
var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
|
var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
|
var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
|
Console.WriteLine($"{Bssx} 满下检测:任务申请:{RtaskState}- 是否已处理:{RtaskState_LAST}- 托盘码:{R托盘码}");
|
if (RtaskState == 3 && RtaskState_LAST == 0)
|
{
|
var item = "1026";
|
var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
|
var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
|
if (R5 == 5 && R5空闲_LAST == 0)
|
{
|
var b = TaskProcess.CreateTask("", Bssx, item, "满转1026", 5, new List<string> { R托盘码 }, "RGV");
|
if (b)
|
{
|
Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
|
Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg2);
|
//Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
|
//Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
|
break;
|
}
|
}
|
else if (R5 != 5 && R5空闲_LAST == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg2);
|
}
|
}
|
else if (RtaskState != 3 && RtaskState_LAST == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
|
//Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "0", $"S{Bssx}ReadQueue");
|
}
|
System.Threading.Thread.Sleep(2000);
|
}
|
#endregion [脚本][20250616094632985][业务逻辑.流程2热处理炉进出.定子满下线]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:转子满下线
|
/// 描述:
|
/// </summary>
|
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工位任务。
|
foreach (var Bssx in new string[] { "1002", "1010" })
|
{
|
var RtaskState = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState"), typeof(System.UInt16));
|
var RtaskState_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.RtaskState_LAST"), typeof(System.UInt16));
|
var R托盘码 = (System.String)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{Bssx}Read.R托盘码"), typeof(System.String));
|
Console.WriteLine($"{Bssx} 满下检测:任务申请:{RtaskState}- 是否已处理:{RtaskState_LAST}- 托盘码:{R托盘码}");
|
if (RtaskState == 3 && RtaskState_LAST == 0)
|
{
|
var item = "1017";
|
var R5 = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲"), typeof(System.UInt16));
|
var R5空闲_LAST = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"S{item}Read.R5空闲_LAST"), typeof(System.UInt16));
|
if (R5 == 5 && R5空闲_LAST == 0)
|
{
|
var b = TaskProcess.CreateTask("", Bssx, item, "满转1017", 5, new List<string> { R托盘码 }, "RGV");
|
if (b)
|
{
|
Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "1", out string msg);
|
Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "1", out string msg1);
|
//Conn.默认Redis.SetValue($"S{Bssx}Read.RtaskState_LAST", "1", $"S{Bssx}ReadQueue");
|
//Conn.默认Redis.SetValue($"S{item}Read.R5空闲_LAST", "1", $"S{item}ReadQueue");
|
break;
|
}
|
}
|
else if (R5 != 5 && R5空闲_LAST == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"S{item}Read.R5空闲_LAST", "0", out string msg1);
|
}
|
}
|
else if (RtaskState != 3 && RtaskState_LAST == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"S{Bssx}Read.RtaskState_LAST", "0", out string msg);
|
}
|
System.Threading.Thread.Sleep(2000);
|
}
|
#endregion [脚本][20250616094511322][业务逻辑.流程2热处理炉进出.转子满下线]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:下料位检测
|
/// 描述:
|
/// </summary>
|
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 到位时 写 标识信号 并 给机械手信号。
|
foreach (var ssx in new string[] { "1003", "1005", "1011", "1013" })
|
{
|
var RArrive = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"FNK1003051113.RArrive{ssx}"), typeof(System.UInt16));
|
var RArriveLast = (System.UInt16)System.Convert.ChangeType(Conn.默认Redis.GetValue($"FNK1003051113.RArrive{ssx}_LAST"), typeof(System.UInt16));
|
if (RArrive == 1 && RArriveLast == 0)
|
{
|
if (ssx == "1005")
|
{
|
tag.FNK1.D2210 = 1;
|
tag.SF下料位.RArrive1005_LAST = 1;
|
|
tag.SF下料位.WRelease1005 = 0;
|
tag.SF下料位.WSafe0305 = 0;
|
}
|
else if (ssx == "1003")
|
{
|
tag.FNK2.D2215 = 1;
|
tag.SF下料位.RArrive1003_LAST = 1;
|
|
tag.SF下料位.WRelease1003 = 0;
|
tag.SF下料位.WSafe0305 = 0;
|
}
|
else if (ssx == "1013")
|
{
|
tag.FNK2.D2210 = 1;
|
tag.SF下料位.RArrive1013_LAST = 1;
|
|
tag.SF下料位.WRelease1013 = 0;
|
tag.SF下料位.WSafe1113 = 0;
|
}
|
else if (ssx == "1011")
|
{
|
tag.FNK2.D2215 = 1;
|
tag.SF下料位.RArrive1011_LAST = 1;
|
|
tag.SF下料位.WRelease1011 = 0;
|
tag.SF下料位.WSafe1113 = 0;
|
}
|
}
|
else if (RArrive == 0 && RArriveLast == 1)
|
{
|
Modular.Redis.RedisHelper.Add($"FNK1003051113.RArrive{ssx}_LAST", "0", out string msg);
|
}
|
}
|
#endregion [脚本][20250616095605911][业务逻辑.流程2热处理炉进出.下料位检测]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:1号FNK机械手完成
|
/// 描述:
|
/// </summary>
|
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机械手完成]
|
if (tag.FNK1.D2212 == 1 && tag.FNK1.D2212_LAST == 0)
|
{
|
tag.FNK1.D2210 = 0;
|
tag.FNK1.D2212_LAST = 1;
|
|
tag.SF下料位.WRelease1005 = 1;
|
tag.SF下料位.WSafe0305 = 1;
|
}
|
else if (tag.FNK1.D2212 == 0 && tag.FNK1.D2212_LAST == 1)
|
{
|
tag.FNK1.D2212_LAST = 0;
|
}
|
if (tag.FNK1.D2217 == 1 && tag.FNK1.D2217_LAST == 0)
|
{
|
tag.FNK1.D2215 = 0;
|
tag.FNK1.D2217_LAST = 1;
|
|
tag.SF下料位.WRelease1003 = 1;
|
tag.SF下料位.WSafe0305 = 1;
|
}
|
else if (tag.FNK1.D2217 == 0 && tag.FNK1.D2217_LAST == 1)
|
tag.FNK1.D2217_LAST = 0;
|
|
#endregion [脚本][20250616095709155][业务逻辑.流程2热处理炉进出.1号FNK机械手完成]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:2号FNK机械手完成
|
/// 描述:
|
/// </summary>
|
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机械手完成]
|
if (tag.FNK2.D2212 == 1 && tag.FNK2.D2212_LAST == 0)
|
{
|
tag.FNK2.D2210 = 0;
|
tag.FNK2.D2212_LAST = 1;
|
|
tag.SF下料位.WRelease1013 = 1;
|
tag.SF下料位.WSafe1113 = 1;
|
}
|
else if (tag.FNK2.D2212 == 0 && tag.FNK2.D2212_LAST == 1)
|
{
|
tag.FNK2.D2212_LAST = 0;
|
}
|
if (tag.FNK2.D2217 == 1 && tag.FNK2.D2217_LAST == 0)
|
{
|
tag.FNK2.D2215 = 0;
|
tag.FNK2.D2217_LAST = 1;
|
|
tag.SF下料位.WRelease1011 = 1;
|
tag.SF下料位.WSafe1113 = 1;
|
}
|
else if (tag.FNK2.D2217 == 0 && tag.FNK2.D2217_LAST == 1)
|
tag.FNK2.D2217_LAST = 0;
|
#endregion [脚本][20250616095733680][业务逻辑.流程2热处理炉进出.2号FNK机械手完成]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:Program1
|
/// 描述:
|
/// </summary>
|
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]
|
|
Console.WriteLine($"1019任务状态:{tag.SA1019.RtaskState}- barcode:{tag.SA1019.R托盘码}- 空闲{tag.SA1019.R5空闲}");
|
#endregion [脚本][20250617085708084][业务逻辑.流程2热处理炉进出.1019转满出输送线.Program1]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:Program1
|
/// 描述:
|
/// </summary>
|
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]
|
|
Console.WriteLine($"SA1025 任务状态:{tag.SA1025.RtaskState}- 空闲{tag.SA1025.R5空闲}");
|
#endregion [脚本][20250617085712101][业务逻辑.流程2热处理炉进出.1025agv上空.Program1]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:Program1
|
/// 描述:
|
/// </summary>
|
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]
|
|
Console.WriteLine($"SA1022 任务状态:{tag.SA1022.RtaskState}- 空闲{tag.SA1022.R5空闲}");
|
#endregion [脚本][20250617085750712][业务逻辑.流程2热处理炉进出.1022agv上空.Program1]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:Program1
|
/// 描述:
|
/// </summary>
|
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]
|
|
Console.WriteLine($"SA1030 任务状态:{tag.SA1030.RtaskState}- 空闲{tag.SA1030.R5空闲}-->对应终点2001>空闲5:{tag.SA2001.R5空闲}");
|
#endregion [脚本][20250617085800942][业务逻辑.流程2热处理炉进出.1030下母托.Program1]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
/// <summary>
|
/// 程序片段:Program1
|
/// 描述:
|
/// </summary>
|
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]
|
|
Console.WriteLine($"SA2030 任务状态:{tag.SA2030.RtaskState}- 空闲{tag.SA2030.R5空闲} - barcode:{tag.SA2030.R托盘码}");
|
#endregion [脚本][20250617085809982][业务逻辑.流程2热处理炉进出.2030输送线下定子.Program1]
|
}
|
catch(Exception ex)
|
{
|
Conn.默认日志.Error(ex.ToString());
|
}
|
finally
|
{
|
System.Threading.Thread.Sleep(3000);
|
}
|
}
|
ExitJudgeStack.TryPop(out int exitJudgeVal);
|
});
|
|
}
|
/// <summary>
|
/// View1关闭事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
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();
|
}
|
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)
|
)
|
{
|
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();
|
}
|
/// <summary>
|
/// View1初始化
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
public void View1_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.116: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<HaiKangOrderInfo>(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<ToWMSMES.CreateTask>(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<ToWMSMES.CreateTask>(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 = System.IO.Path.Combine("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
|
}
|
}
|