using BLL.DAL;
|
using Commom.DotNetDevices;
|
using Model.WcsModel;
|
using NLog;
|
using System;
|
using System.Data;
|
using System.IO;
|
using System.Threading;
|
using Common;
|
using wms.Controllers;
|
using Model.MessageModel;
|
using System.Threading.Tasks;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Serialization;
|
|
namespace wms.Task
|
{
|
//Parallel.For
|
public static class TaskAction
|
{
|
// JC09WCS
|
private static bool IsRunTast = true; // 测试方法控制
|
private static bool IsRunConveyor = true; // 托盘运输线方法控制
|
private static bool IsRunBoxConveyor = true; // 件箱运输线方法控制
|
private static bool IsRunStacker = true; // 跺机方法控制
|
private static bool IsRunStackerAddre = true; // 跺机地址方法控制
|
private static DataTable PlcInfoDt; // 获取所有设备
|
private static DataTable PlcIpDt; // 获取所有IP地址
|
|
private static string plcConveyVal = ""; // 托盘输送线连接状态
|
private static PlcIO plcConvey; // 托盘输送线IP地址
|
|
private static string plcBoxConveyVal = ""; // 件箱输送线连接状态
|
private static PlcIO plcBoxConvey; // 件箱输送线IP地址
|
|
#region 垛机地址与链接状态
|
private static string plcStackVal1 = ""; // 跺机1连接状态
|
private static PlcIO plcStack1; // 跺机1IP地址
|
|
private static string plcStackVal2 = ""; // 跺机2连接状态
|
private static PlcIO plcStack2; // 跺机2IP地址
|
|
private static string plcStackVal3 = ""; // 跺机1连接状态
|
private static PlcIO plcStack3; // 跺机1IP地址
|
|
private static string plcStackVal4 = ""; // 跺机2连接状态
|
private static PlcIO plcStack4; // 跺机2IP地址
|
|
private static string plcStackVal5 = ""; // 跺机1连接状态
|
private static PlcIO plcStack5; // 跺机1IP地址
|
|
private static string plcStackVal6 = ""; // 跺机2连接状态
|
private static PlcIO plcStack6; // 跺机2IP地址
|
|
private static string plcStackVal7 = ""; // 跺机1连接状态
|
private static PlcIO plcStack7; // 跺机1IP地址
|
|
#endregion
|
|
public static bool fuwu = false; // 服务开启关闭
|
public static bool refresh = false; // 自刷新开启关闭
|
public static bool tuoji = false; // 脱机开启关闭
|
public static bool Demo = false; //演示模式开启关闭
|
|
/// <summary>
|
/// 服务初始化
|
/// </summary>
|
[Obsolete]
|
static TaskAction()
|
{
|
// WCS标准版本代码 执行一次
|
DALWcsMessage wcsSql = new DALWcsMessage();
|
PlcIpDt = wcsSql.GetPlcIps();
|
PlcInfoDt = wcsSql.GetPlcInfos();
|
|
// 开启服务
|
fuwu = true;
|
//自刷新
|
refresh = true;
|
|
// 打开设备连接(输送线 跺机 码垛...)
|
plcConvey = new PlcIO("192.168.21.2", 1, ref plcConveyVal);
|
plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
|
plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
|
}
|
|
|
|
/// <summary>
|
/// PLC读写测试
|
/// </summary>
|
/// <param name="source"></param>
|
/// <param name="e"></param>
|
public static async void TestPlc(object source, System.Timers.ElapsedEventArgs e)
|
{
|
try
|
{
|
if (IsRunTast)
|
{
|
IsRunTast = false;
|
//WebStocket发送消息
|
WSChatController wSChat = new WSChatController();
|
|
//通知设备--任务
|
//一号巷道
|
DeviceMessage message = new DeviceMessage();
|
message.Message = "任务更新";
|
message.Status = "1";
|
message.RoadwayNo = "R01";
|
message.StartLocat = 10;
|
message.EndLocat = 15;
|
var a = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(a);
|
|
//二号巷道 没问题
|
message.Message = "任务更新";
|
message.Status = "1";
|
message.RoadwayNo = "R02";
|
message.StartLocat = 53;
|
message.EndLocat = 15;
|
var b = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(b);
|
|
//三号巷道
|
message.Message = "任务更新";
|
message.Status = "1";
|
message.RoadwayNo = "R03";
|
message.StartLocat = 14;
|
message.EndLocat = 53;
|
var c = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(c);
|
|
//四号巷道
|
message.Message = "任务更新";
|
message.Status = "1";
|
message.RoadwayNo = "R04";
|
message.StartLocat = 15;
|
message.EndLocat = 10;
|
var d = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(d);
|
|
//一号巷道
|
message.Message = "垛机实时";
|
message.RoadwayNo = "R01";
|
message.Position = 15;
|
var f = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(f);
|
|
message.Message = "垛机实时";
|
message.RoadwayNo = "R01";
|
message.Position = 33;
|
f = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(f);
|
|
message.Message = "垛机实时";
|
message.RoadwayNo = "R01";
|
message.Position = 36;
|
f = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(f);
|
|
message.Message = "垛机实时";
|
message.RoadwayNo = "R01";
|
message.Position = 45;
|
f = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(f);
|
|
message.Message = "垛机实时";
|
message.RoadwayNo = "R01";
|
message.Position = 48;
|
f = JsonConvert.SerializeObject(message);
|
wSChat.AlarmInformation(f);
|
|
//wSChat.AlarmInformation(d);
|
//var s = fuwu;
|
//WSChatController wSChat = new WSChatController();
|
//wSChat.AlarmInformation(s.ToString());
|
//DALWcsMessage wcsMySql = new DALWcsMessage();
|
//string EndLocat = string.Empty;
|
|
// LED显示屏连接测试
|
//LedDll Led = new LedDll();
|
//Led.LEDstr("192.168.21.150", "最上方", "中间多文本区域!", "最下方区域 ");
|
//Led.LEDstr("192.168.21.150", "测试LED");
|
//TaskReques taskReques = new TaskReques();
|
//taskReques.taskNo = "TK2023092000001";
|
//taskReques.TaskType = "0";
|
//taskReques.TaskStatus = "2";
|
//bool bl = wcsMySql.RequestTasks(taskReques);
|
|
|
|
//string strMsg = wcsMySql.GetLocations("T2300021", "1", ref EndLocat);
|
//WSChatController wSChat = new WSChatController();
|
// wSChat.AlarmInformation("连接设备失败:");
|
|
|
//Logger logger = LogManager.GetCurrentClassLogger();
|
//logger.Error("在运行" + "执行该方法:", "iis自动回收机制");
|
|
//string plcStatus = "";
|
//PlcIO plc = new PlcIO("192.168.21.2", 1, ref plcStatus);
|
//if (plcStatus.Length > 0)
|
//{
|
// // 连接失败
|
//}
|
//bool bl = plc.SetPlcDBValue(107, "String", "CS2024010100002", "40.0");
|
//bool bl1 = plc.SetPlcDBValue(107, "String", "T2300063", "60.0");
|
|
|
//连接测试
|
//string plcStatus = "";
|
//PlcIO plc = new PlcIO("192.168.21.2", 1, ref plcStatus);
|
//if (plcStatus.Length > 0)
|
//{
|
// // 连接失败
|
//}
|
//plc = new PlcIO("192.168.21.30", 1, ref plcStatus);
|
//if (plcStatus.Length > 0)
|
//{
|
// // 连接失败
|
//}
|
//PlcIO plc2 = new PlcIO("192.168.21.40", 1, ref plcStatus);
|
//if (plcStatus.Length > 0)
|
//{
|
// // 连接失败
|
//}
|
//string plcValue = "";
|
//plcValue = plc.GetPlcDBValue(107, "Int", "84.0");
|
//if (plcValue!= "30")
|
//{
|
// var vl = plc.SetPlcDBValue(107, "Int", "30","84.0");
|
//}
|
//plcValue = plc.GetPlcDBValue(107, "String", "0.0");
|
//plcValue = plc.GetPlcDBValue(107, "String", "20.0");
|
//plcValue = plc.GetPlcDBValue(107, "String", "40.0");
|
//plcValue = plc.GetPlcDBValue(107, "String", "60.0");
|
//plcValue = plc.GetPlcDBValue(107, "Int", "80.0");
|
//plcValue = plc.GetPlcDBValue(107, "Int", "82.0");
|
//plcValue = plc.GetPlcDBValue(107, "Int", "84.0");
|
//plcValue = plc.GetPlcDBValue(107, "Int", "86.0");
|
|
//plcStatus = "";
|
//PlcIO plc2 = new PlcIO("192.168.21.30", 1, ref plcStatus);
|
//if (plcStatus.Length > 0)
|
//{
|
// // 连接失败
|
//}
|
//plcValue = plc2.GetPlcDBValue(100, "String", "0.0");
|
//plcValue = plc2.GetPlcDBValue(100, "String", "20.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "40.0");
|
//plcValue = plc2.GetPlcDBValue(100, "String", "42.0");
|
//plcValue = plc2.GetPlcDBValue(100, "String", "62.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "82.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "84.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "86.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "88.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "90.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "92.0");
|
//plcValue = plc2.GetPlcDBValue(100, "Int", "94.0");
|
|
//led灯相应位置显示
|
// 提示LED选择执行批次
|
// LedDisplay(row["LedIP"].ToString(), "38工位", "入库前,请操作执行批次信息!", "停止入库\t");
|
//LedDisplay("192.168.8.55", "38工位 C1口", "空闲中D", "整托空桶/重桶入库分拣交互工位38"); //D口
|
//LedDisplay("192.168.8.51", "28工位 C口", "空闲中C1", "人工处理/整托袋子入库交互工位28"); //C1口
|
//LedDisplay("192.168.8.52", "24工位 B口", "空闲中C", "托袋子入库交互工位24"); //C口
|
//LedDisplay("192.168.8.54", "18工位 A口", "空闲中B", "吨袋入库B口 交互工位18"); //B口
|
//LedDisplay("192.168.8.53", "13工位 D口", "空闲中A", "桶类出入库A口 交互工位13"); //A口
|
|
//LedDisplay("192.168.8.51", "28工位 C1口", "空闲中", "人工处理/整托袋子入库交互工位28"); //C1口
|
//LedDisplay("192.168.8.52", "24工位 C口", "空闲中", "托袋子入库交互工位24"); //C口
|
//LedDisplay("192.168.8.54", "18工位 B口", "空闲中", "吨袋入库B口 交互工位18"); //B口
|
//LedDisplay("192.168.8.53", "13工位 A口", "空闲中", "桶类出入库A口 交互工位13"); //A口
|
//LedDisplay("192.168.8.55", "38工位 D口", "空闲中", "整托空桶/重桶入库分拣交互工位38"); //D口
|
//return;
|
|
//// 手动设置各工位状态
|
//plc.SetPlcDBValue(1101, "Int", "100", "420.0"); // PLC控制流程字
|
//var aa = plc.SetPlcDBValue(1101, "String", "T2300001", "400.0"); // 托盘号
|
//plc.SetPlcDBValue(1101, "Int", "70", "424.0"); // 任务类型 70满桶子母托入 80满桶母托入
|
//plc.SetPlcDBValue(1101, "Int", "60", "426.0"); // 物料类型 60:满桶字母托盘 70:满桶母托盘
|
//plc.SetPlcDBValue(1101, "Byte", "1", "428.0"); // 目标工位号
|
//plc.SetPlcDBValue(1101, "Byte", "1", "429.0"); // 字母托盘状态 0无 1有
|
//plc.SetPlcDBValue(1101, "Byte", "1", "430.0"); // 物料数量
|
//plc.SetPlcDBValue(1101, "Real", "200", "432.0"); // 物料重量
|
//plc.SetPlcDBValue(1101, "Byte", "0", "431.0"); // 拆跺数量
|
|
// 读取
|
//string plcValue = "";
|
//plcValue = plc.GetPlcDBValue(101, "String", "20.0");
|
|
|
//bool inBl = plc.SetPlcDBValue(101, "String", "T2300001", "20.0");
|
//plcValue = plc.GetPlcDBValue(101, "String", "20.0");
|
|
//plcValue = plc.GetPlcDBValue(101, "Int", "82.0");
|
|
////bool inBl = plc.SetPlcDBValue(101, "Int", "1", "82.0");
|
////plc.SetPlcDBValue(1101, "String", "T2300001", "10.0");
|
//plcValue = "";
|
//plcValue = plc.GetPlcDBValue(1101, "Int", "20.0");
|
////plc.SetPlcDBValue(1101, "Int", "99", "22.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Int", "424.0");
|
////plc.SetPlcDBValue(1101, "Int", "99", "24.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Int", "426.0");
|
////plc.SetPlcDBValue(1101, "Int", "99", "26.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Byte", "428.0");
|
////plc.SetPlcDBValue(1101, "Byte", "99", "28.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Byte", "429.0");
|
////plc.SetPlcDBValue(1101, "Byte", "99", "29.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Byte", "430.0");
|
////plc.SetPlcDBValue(1101, "Byte", "99", "30.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Byte", "431.0");
|
////plc.SetPlcDBValue(1101, "Byte", "99", "31.0");
|
//plcValue = plc.GetPlcDBValue(1101, "Real", "432.0");
|
////plc.SetPlcDBValue(1101, "Real", "99", "32.0");
|
|
|
|
|
|
// 接口测试
|
//WCSPalletBind model = new WCSPalletBind();
|
//model.PalletNo = "T2300001";
|
//model.TaskType = "001";
|
//model.SubPallet = "0";
|
//model.SkuQty = 10;
|
//model.SkuWeight = "235";
|
|
//model.SkuType = "001";
|
//model.LotNo = "2305190";
|
//model.SupplierLot = "";
|
//DALWcsMessage wcsMySql = new DALWcsMessage();
|
//string endLocat = ""; // 取货工位号
|
//string strMsg = wcsMySql.GetLocation("T2300001", model, ref endLocat);
|
|
//plc.ClosePlc();
|
IsRunTast = true;
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
finally
|
{
|
//IsRunTast = true;
|
}
|
}
|
|
/// <summary>
|
/// 堆垛机
|
/// </summary>
|
//[Obsolete]
|
public static void Stackers(object source, System.Timers.ElapsedEventArgs e)
|
{
|
try
|
{
|
if (IsRunStacker)
|
{
|
IsRunStacker = false;
|
// 判断wcs服务是否开启
|
if (!fuwu)
|
{
|
IsRunStacker = true;
|
return;
|
}
|
|
// 判断运行的服务器
|
bool sqlBool = false;
|
DALWcsMessage wcsSql = new DALWcsMessage();
|
try
|
{
|
sqlBool = wcsSql.GetIsWcsAutoDB1(); // 抛出异常,证明DB2在运行
|
}
|
catch
|
{
|
IsRunStacker = true;
|
return;
|
};
|
|
PlcInteraction plcInteraction = new PlcInteraction();
|
while (fuwu && sqlBool)
|
{
|
if (plcStackVal1.Length > 0 || plcStackVal2.Length > 0)
|
{
|
if (plcStackVal1.Length > 0)
|
{
|
// 重新连接plc
|
plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
|
}
|
|
if (plcStackVal2.Length > 0)
|
{
|
// 重新连接plc
|
plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
|
}
|
}
|
else
|
{
|
// 自动模式
|
DataRow[] ipRows = PlcIpDt.Select(" Type = '0' ");
|
foreach (DataRow ipRow in ipRows)
|
{
|
if (ipRow["IP"].ToString() == "192.168.21.30")
|
{
|
plcInteraction.StackersInteraction2(ipRow, PlcInfoDt, plcStack1, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.40")
|
{
|
plcInteraction.StackersInteraction2(ipRow, PlcInfoDt, plcStack2, plcConvey);
|
}
|
|
|
}
|
|
}
|
}
|
|
IsRunStacker = true;
|
}
|
}
|
catch (Exception ex)
|
{
|
IsRunStacker = true;
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 托盘运输线
|
/// </summary>
|
public static void Conveyors(object source, System.Timers.ElapsedEventArgs e)
|
{
|
try
|
{
|
if (IsRunConveyor)
|
{
|
IsRunConveyor = false;
|
|
// 判断wcs服务是否开启
|
if (!fuwu)
|
{
|
IsRunConveyor = true;
|
return;
|
}
|
|
// 判断运行的服务器
|
bool sqlBool = false;
|
DALWcsMessage wcsSql = new DALWcsMessage();
|
try
|
{
|
// 抛出异常,证明DB2在运行
|
sqlBool = wcsSql.GetIsWcsAutoDB1();
|
}
|
catch
|
{
|
IsRunConveyor = true;
|
return;
|
};
|
|
Logger logger = LogManager.GetCurrentClassLogger();
|
logger.Error("ASDF", "定时监控:");
|
|
PlcInteraction plcInteraction = new PlcInteraction();
|
while (fuwu && sqlBool)
|
{
|
Thread.Sleep(100);
|
|
if (plcConveyVal.Length > 0 || plcStackVal1.Length > 0 || plcStackVal2.Length > 0)
|
{
|
plcConvey.ClosePlc();
|
plcStack1.ClosePlc();
|
plcStack2.ClosePlc();
|
plcConveyVal = "";
|
plcStackVal1 = "";
|
plcStackVal2 = "";
|
// 重新连接plc
|
plcConvey = new PlcIO("192.168.21.2", 1, ref plcConveyVal);
|
plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
|
plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
|
logger.Error($"重新连接:输送线:{plcConveyVal},跺机1:{plcStackVal1},跺机2:{plcStackVal2}", "输送线错误重新连接关闭");
|
}
|
else
|
{
|
try
|
{
|
// 输送线
|
DataRow[] ipRows = PlcIpDt.Select(" Type = '1' ");
|
foreach (DataRow ipRow in ipRows)
|
{
|
plcInteraction.ConveyorsInteraction2(ipRow, PlcInfoDt, plcConvey, plcStack1, plcStack2);
|
}
|
|
// 堆垛机
|
DataRow[] ipRowsDJ = PlcIpDt.Select(" Type = '0' ");
|
foreach (DataRow ipRowDj in ipRowsDJ)
|
{
|
if (ipRowDj["IP"].ToString() == "192.168.21.30")
|
{
|
plcInteraction.StackersInteraction2(ipRowDj, PlcInfoDt, plcStack1, plcConvey);
|
}
|
else if (ipRowDj["IP"].ToString() == "192.168.21.40")
|
{
|
plcInteraction.StackersInteraction2(ipRowDj, PlcInfoDt, plcStack2, plcConvey);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
plcConvey.ClosePlc();
|
plcStack1.ClosePlc();
|
plcStack2.ClosePlc();
|
|
plcConveyVal = "OFF";
|
plcStackVal1 = "OFF";
|
plcStackVal2 = "OFF";
|
|
logger.Error("异常重连:" + ex.Message, "输送线错误重新连接关闭");
|
}
|
}
|
}
|
|
IsRunConveyor = true;
|
}
|
}
|
catch (Exception ex)
|
{
|
IsRunConveyor = true;
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 件箱运输线
|
/// </summary>
|
public static void BoxConveyors(object source, System.Timers.ElapsedEventArgs e)
|
{
|
try
|
{
|
if (IsRunBoxConveyor)
|
{
|
IsRunBoxConveyor = false;
|
|
// 判断wcs服务是否开启
|
if (!fuwu)
|
{
|
IsRunBoxConveyor = true;
|
return;
|
}
|
|
// 判断运行的服务器
|
bool sqlBool = false;
|
DALWcsMessage wcsSql = new DALWcsMessage();
|
try
|
{
|
// 抛出异常,证明DB2在运行
|
sqlBool = wcsSql.GetIsWcsAutoDB1();
|
}
|
catch
|
{
|
IsRunBoxConveyor = true;
|
return;
|
};
|
|
Logger logger = LogManager.GetCurrentClassLogger();
|
logger.Error("件箱输送线定时运行", "定时监控:");
|
|
PlcInteraction plcInteraction = new PlcInteraction();
|
while (fuwu && sqlBool)
|
{
|
Thread.Sleep(100);
|
|
if (plcBoxConveyVal.Length > 0)
|
{
|
plcBoxConvey.ClosePlc();
|
plcBoxConveyVal = "";
|
// 重新连接plc
|
plcBoxConvey = new PlcIO("192.168.21.2", 1, ref plcConveyVal);
|
logger.Error($"重新连接:件箱输送线:{plcBoxConveyVal}", "件箱输送线错误重新连接关闭");
|
}
|
else
|
{
|
try
|
{
|
// 件箱输送线
|
DataRow[] ipRows = PlcIpDt.Select(" Type = '2' ");
|
foreach (DataRow ipRow in ipRows)
|
{
|
plcInteraction.BoxConveyorsInteraction2(ipRow, PlcInfoDt, plcConvey);
|
}
|
}
|
catch (Exception ex)
|
{
|
plcBoxConvey.ClosePlc();
|
|
plcBoxConveyVal = "OFF";
|
|
logger.Error("异常重连:" + ex.Message, "件箱输送线错误重新连接关闭");
|
}
|
}
|
}
|
|
IsRunBoxConveyor = true;
|
}
|
}
|
catch (Exception ex)
|
{
|
IsRunBoxConveyor = true;
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 跺机地址监控
|
/// </summary>
|
/// <param name="source"></param>
|
/// <param name="e"></param>
|
public static void StackerAddre(object source, System.Timers.ElapsedEventArgs e)
|
{
|
try
|
{
|
if (IsRunStackerAddre)
|
{
|
IsRunStackerAddre = false;
|
// 判断wcs服务是否开启
|
if (!fuwu)
|
{
|
IsRunStacker = true;
|
return;
|
}
|
|
// 判断运行的服务器
|
bool sqlBool = false;
|
DALWcsMessage wcsSql = new DALWcsMessage();
|
try
|
{
|
sqlBool = wcsSql.GetIsWcsAutoDB1(); // 抛出异常,证明DB2在运行
|
}
|
catch
|
{
|
IsRunStackerAddre = true;
|
return;
|
};
|
|
PlcInteraction plcInteraction = new PlcInteraction();
|
while (fuwu && sqlBool)
|
{
|
if (plcStackVal1.Length > 0 || plcStackVal2.Length > 0)
|
{
|
if (plcStackVal1.Length > 0)
|
{
|
// 重新连接plc
|
plcStack1 = new PlcIO("192.168.21.30", 1, ref plcStackVal1);
|
}
|
|
if (plcStackVal2.Length > 0)
|
{
|
// 重新连接plc
|
plcStack2 = new PlcIO("192.168.21.40", 1, ref plcStackVal2);
|
}
|
|
if (plcStackVal3.Length > 0)
|
{
|
// 重新连接plc
|
plcStack3 = new PlcIO("192.168.21.50", 1, ref plcStackVal3);
|
}
|
|
if (plcStackVal4.Length > 0)
|
{
|
// 重新连接plc
|
plcStack4 = new PlcIO("192.168.21.60", 1, ref plcStackVal4);
|
}
|
|
if (plcStackVal5.Length > 0)
|
{
|
// 重新连接plc
|
plcStack5 = new PlcIO("192.168.21.70", 1, ref plcStackVal5);
|
}
|
|
if (plcStackVal6.Length > 0)
|
{
|
// 重新连接plc
|
plcStack6 = new PlcIO("192.168.21.80", 1, ref plcStackVal6);
|
}
|
|
if (plcStackVal7.Length > 0)
|
{
|
// 重新连接plc
|
plcStack7 = new PlcIO("192.168.21.90", 1, ref plcStackVal7);
|
}
|
}
|
else
|
{
|
// 自动模式
|
DataRow[] ipRows = PlcIpDt.Select(" Type = '0' ");
|
foreach (DataRow ipRow in ipRows)
|
{
|
if (ipRow["IP"].ToString() == "192.168.21.30")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack1, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.40")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack2, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.50")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack3, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.60")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack4, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.70")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack5, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.80")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack6, plcConvey);
|
}
|
else if (ipRow["IP"].ToString() == "192.168.21.90")
|
{
|
plcInteraction.StackersAddreInteraction(ipRow, PlcInfoDt, plcStack7, plcConvey);
|
}
|
|
|
|
}
|
|
}
|
}
|
|
IsRunStackerAddre = true;
|
}
|
}
|
catch (Exception ex)
|
{
|
IsRunStackerAddre = true;
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 清除log日志
|
/// </summary>
|
public static void DeleteNlogFile(object source, System.Timers.ElapsedEventArgs e)
|
{
|
try
|
{
|
// 时 分 秒
|
// 得到 hour minute second 如果等于某个值就开始执行某个程序。
|
int intHour = e.SignalTime.Hour;
|
int intMinute = e.SignalTime.Minute;
|
//int intSecond = e.SignalTime.Second;
|
// 定制时间; 比如 在10:30 :00 的时候执行某个函数
|
int iHour = 00;
|
int iMinute = 05;
|
//int iSecond = 00;
|
// 设置 在每天晚上的23点50执行
|
//if (intHour == iHour && intMinute == iMinute && intSecond == iSecond)
|
if (intHour == iHour && intMinute == iMinute)
|
{
|
|
int count = 0;
|
string[] files = Directory.GetFiles("E:\\server\\WcsServer\\LogFile");//路径需要更改
|
//string[] files = Directory.GetFiles("D:\\WMS\\JC08Wcs\\WCS-V1.0\\wms\\LogFile");
|
foreach (string file in files)
|
{
|
FileInfo fi = new FileInfo(file);
|
var a = fi.Name.Split('.');
|
a[0].ToDate();
|
if (a[0].ToDate() < DateTime.Now.AddMonths(-1))
|
{
|
count += 1;
|
fi.Delete();
|
}
|
}
|
Logger logger = LogManager.GetCurrentClassLogger();
|
if (count > 0)
|
{
|
logger.Error("清除WCS日志消息:清除成功");
|
//调用WMS清除日志接口
|
var response = Utility.Extra.HttpHelper.DoPost("http://192.168.220.137:8081/api/DownAPi/DeleteNlogFile", null);//路径需要更改
|
if (response != "清除成功")
|
{
|
logger.Error("清除WMS日志消息:清除成功");
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Logger logger = LogManager.GetCurrentClassLogger();
|
logger.Error("清除日志异常消息:" + ex.Message, "清除日志定时器错误");
|
}
|
|
}
|
|
/// <summary>
|
/// 获取当前工位交互流程字为多少
|
/// </summary>
|
public static string GetPlcOrWcsPos(string Ip, string Stat, string Plcpos)
|
{
|
#region 与PLC交互逻辑
|
//DataRow[] iProws = null;
|
|
//string type = "0";
|
|
////判断是输送线连接还是垛机连接
|
//if (Ip == "192.168.8.40")
|
//{
|
// type = "1";
|
// // 获取运输线交互IP集合
|
// iProws = PlcInfoDt.Select("Level = '0' and Type = '1' ");
|
//}
|
//else
|
//{
|
// // 获取跺机交互IP集合
|
// iProws = PlcInfoDt.Select("Level = '0' and Type = '0' ");
|
//}
|
|
|
//// 连接运输线PlC
|
////string plcIp = ipRow["PlcIP"].ToString();
|
//string plcStatus = ""; // PLC连接状态
|
//PlcIO plc = new PlcIO(Ip, 1, ref plcStatus);
|
//// 循环连接运输线设备
|
//foreach (DataRow ipRow in iProws)
|
//{
|
// // 循环各跺机与PLC进行交互
|
// DataRow[] rows = PlcInfoDt.Select($"Level = '2' and Type = '{type}' and PlcIP='{Ip}' ");
|
// //rows.Select(a=>a.)
|
// rows = PlcInfoDt.Select($"StationNum = '{Stat}' and PlcPos = '{Plcpos}'");
|
// foreach (DataRow row in rows)
|
// {
|
// // 读取工位流程字
|
// string dbNumber = row["DbNumber"].ToString();
|
// string posType = row["PosType"].ToString();
|
// string plcPos = row["PlcPos"].ToString();
|
// string wcsPos = row["WcsPos"].ToString();
|
// string stationNum = row["StationNum"].ToString();
|
// string plcValue = plc.GetPlcDBValue(int.Parse(dbNumber), posType, plcPos);
|
|
// //判断工位号
|
// if (stationNum == Stat)
|
// {
|
// if (plcValue == "0" || plcValue == "10" || plcValue == "20" || plcValue == "21" || plcValue == "22" || plcValue == "100" || plcValue == "110" || plcValue == "120" || plcValue == "130" || plcValue == "140" || plcValue == "200" || plcValue == "210" || plcValue == "300" || plcValue == "310" || plcValue == "320" || plcValue == "330")
|
// {
|
// // 关闭设备连接
|
// plc.ClosePlc();
|
// return plcValue;
|
// }
|
// else
|
// {
|
// continue;
|
// }
|
// }
|
// else
|
// {
|
// continue;
|
// }
|
// }
|
//}
|
|
|
//// 关闭设备连接
|
//plc.ClosePlc();
|
|
return null;
|
#endregion
|
|
}
|
|
/// <summary>
|
///// 获取当前工位偏移量值为多少
|
/// </summary>
|
public static PosNameVal GetPlcOrWcsPosVal(string plcInfoId)
|
{
|
#region 与PLC交互逻辑
|
PosNameVal list = new PosNameVal();
|
DALWcsMessage wcsMySql = new DALWcsMessage();
|
DataTable posDt = wcsMySql.GetPlcPos(plcInfoId); //偏移量
|
|
var plcInfo = PlcInfoDt.Select($"Id={plcInfoId} ")[0];
|
var ipInfo = PlcIpDt.Select($"Id = {plcInfo["PlcIP"].ToString()} ")[0];
|
|
var dbNumber = plcInfo["DbNumber"].ToString();//db块
|
var infoPlcPos = plcInfo["PlcPos"].ToString();//plc流程字值
|
var infoPosType = plcInfo["PosType"].ToString();//流程字类型
|
var infoWcsPos = plcInfo["WcsPos"].ToString();//wcs流程字值
|
|
string plcStatus = ""; // PLC连接状态
|
PlcIO plc = new PlcIO(ipInfo["IP"].ToString(), 1, ref plcStatus);
|
if (plcStatus.Length <= 0)
|
{
|
try
|
{
|
string plcValue1 = plc.GetPlcDBValue(int.Parse(dbNumber), infoPosType, infoPlcPos);
|
list.PlcPos = plcValue1;
|
string plcValue2 = plc.GetPlcDBValue(int.Parse(dbNumber), infoPosType, infoWcsPos);
|
list.WcsPos = plcValue2;
|
|
foreach (var row in posDt.Select())
|
{
|
// 读取工位流程字
|
string posType = row["PosType"].ToString();
|
string plcPos = row["PlcPos"].ToString();
|
string name = row["Name"].ToString();
|
string plcValue = plc.GetPlcDBValue(int.Parse(dbNumber), posType, plcPos);
|
|
#region 赋值
|
if (PosName.PlcTaskNo.ToString() == name)
|
{
|
list.PlcTaskNo = plcValue;
|
}
|
else if (PosName.PlcPalletNo.ToString() == name)
|
{
|
list.PlcPalletNo = plcValue;
|
}
|
else if (PosName.TaskNo.ToString() == name)
|
{
|
list.TaskNo = plcValue;
|
}
|
else if (PosName.PalletNo.ToString() == name)
|
{
|
list.PalletNo = plcValue;
|
}
|
else if (PosName.StartLocatNo.ToString() == name)
|
{
|
list.StartLocatNo = plcValue;
|
}
|
else if (PosName.EndLocatNo.ToString() == name)
|
{
|
list.EndLocatNo = plcValue;
|
}
|
else if (PosName.StartRow.ToString() == name)
|
{
|
list.StartRow = plcValue;
|
}
|
else if (PosName.StartColumn.ToString() == name)
|
{
|
list.StartColumn = plcValue;
|
}
|
else if (PosName.StartLayer.ToString() == name)
|
{
|
list.StartLayer = plcValue;
|
}
|
else if (PosName.EndRow.ToString() == name)
|
{
|
list.EndRow = plcValue;
|
}
|
else if (PosName.EndColumn.ToString() == name)
|
{
|
list.EndColumn = plcValue;
|
}
|
else if (PosName.EndLayer.ToString() == name)
|
{
|
list.EndLayer = plcValue;
|
}
|
|
#endregion
|
}
|
}
|
catch (Exception ex)
|
{
|
plc.ClosePlc();
|
throw ex;
|
}
|
}
|
|
// 关闭设备连接
|
plc.ClosePlc();
|
|
return list;
|
#endregion
|
}
|
|
/// <summary>
|
/// 应用池回收的时候调用的方法
|
/// </summary>
|
public static void SetContent(string type)
|
{
|
Logger logger = LogManager.GetCurrentClassLogger();
|
logger.Error(type + "执行该方法:", "iis自动回收机制");
|
|
}
|
|
}
|
}
|