using HslCommunication.ModBus;
|
using Microsoft.CodeAnalysis;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Numeric;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.Net.Sockets;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Common.DBHelper;
|
using WIDESEA_Common.Tools;
|
using WIDESEA_Entity.DomainModels.Equipment;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_WCS.Jobs;
|
using WIDESEA_WCS.SchedulerExecute.AGV;
|
using WIDESEA_WCS.WCSClient;
|
using System.IO;
|
using System.Linq;
|
using HslCommunication;
|
using SqlSugar;
|
using WIDESEA_Core.Extensions;
|
|
namespace WIDESEA_WCS
|
{
|
[DisallowConcurrentExecution]
|
/// <summary>
|
/// 缓存架信号Job
|
/// </summary>
|
public class AluminumCaseJob : JobBase, IJob
|
{
|
FreeDB freeDB = new FreeDB();
|
static List<HCJCenterEqDB> centerEqDBList;
|
private static object createTaskObj = new object();
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
ExecuteJob(context, DoAction);
|
}
|
catch (Exception)
|
{
|
|
}
|
return Task.FromResult(string.Empty);
|
}
|
private void DoAction(IJobExecutionContext context)
|
{
|
var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
|
// //Console.WriteLine($"{client}");
|
if (!client.IsConnected)
|
{
|
client.Connect();
|
return;
|
}
|
//铝壳缓存架业务作业
|
LKHCJdispatch();
|
}
|
private void LKHCJdispatch()
|
{
|
|
//铝壳缓存架搬运
|
PLCClient pLCClient1F = WCSService.Clients.Find(V => V.PLCName.Equals(PLCConst.PLCName1FLKHCJ));
|
PLCClient pLCClient2F = WCSService.Clients.Find(V => V.PLCName.Equals(PLCConst.PLCName2FLKHCJ));
|
if (pLCClient1F != null && pLCClient2F != null)
|
{
|
string tsjJson = File.ReadAllText(AppContext.BaseDirectory + "/Config/铝壳缓存架.json", Encoding.UTF8);
|
centerEqDBList = JsonConvert.DeserializeObject<List<HCJCenterEqDB>>(tsjJson);
|
if (centerEqDBList == null)
|
{
|
return;
|
}
|
PLCClient agvzzplc = WCSService.Clients.Find(v => v.PLCName == "组装AGV调度");
|
AGVTransfershelfstatus(agvzzplc);
|
UpdateHCJInfoByRealTime(pLCClient2F);
|
UpdateHCJInfoByRealTime(pLCClient1F);
|
|
#region 二楼铝壳缓存架满托搬运一楼铝壳空位缓存架
|
List<dt_stationinfo> stationListGYKTSL = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => t.LampGreen)
|
.Where(t => t.tpgd)
|
.Where(t => t.wlgd)
|
.Where(t => t.stationType == "2楼铝壳缓存架")
|
.ToList();
|
|
if (stationListGYKTSL != null)
|
{
|
|
foreach (var fcStation in stationListGYKTSL)
|
{
|
|
lock (createTaskObj)
|
{
|
|
dt_agvtask dt_Agvtask = freeDB.Select<dt_agvtask>().Where(t => t.agv_fromaddress == fcStation.stationCode).First();
|
if (dt_Agvtask != null)
|
{
|
|
continue;
|
}
|
//铝壳库还有空闲的满料代表库房送料到产线,二楼送料到库房(除非库房没空位就往产线送)
|
List<dt_stationinfo> stationListGMKHCJlistbeg = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => t.tpgd)
|
.Where(t => t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => t.remark.Contains("一楼隔膜库3缓存架"))
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_fromaddress = a.stationCode)")
|
.ToList();
|
|
List<dt_stationinfo> stationListGMKHCJlistend = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => !t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => t.remark.Contains("一楼隔膜库3缓存架"))
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)")
|
.ToList();
|
|
if (stationListGMKHCJlistbeg.Count > 0 && stationListGMKHCJlistend.Count > 0)
|
{
|
//Console.WriteLine(stationListGMKHCJlistbeg.Count);
|
//Console.WriteLine(stationListGMKHCJlistend.Count);
|
//Console.WriteLine(9);
|
//Console.WriteLine("cccccccccccccc");
|
|
dt_stationinfo stationListGMHCJ = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => !t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => t.remark.Contains("一楼隔膜库3缓存架"))
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)")
|
//查找的目的地址不应该在任务中,也不能是任务的终点
|
//.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)")
|
.First();
|
|
|
if (stationListGMHCJ != null)
|
{
|
Console.WriteLine(11);
|
string agv_remark = "二楼铝壳缓存架任务下料";
|
string begin = fcStation.stationCode;
|
string end = stationListGMHCJ.stationCode;
|
agvtaskAdd(agv_remark, begin, end, true);
|
}
|
else
|
{
|
Console.WriteLine("null");
|
}
|
|
}
|
//库房中没有可搬运的满料
|
else if (stationListGMKHCJlistbeg.Count == 0)
|
{
|
|
dt_stationinfo stationListGMHCJ = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => t.LampGreen)
|
.Where(t => !t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => !t.remark.Contains("一楼隔膜库3缓存架"))
|
//查找的目的地址不应该在任务中,也不能是任务的终点
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress =a.stationCode)")
|
.First();
|
//产线无呼叫,一楼库中有空位就直接二楼送料到库房
|
if (stationListGMHCJ == null)
|
{
|
if (stationListGMKHCJlistend != null)
|
{
|
dt_stationinfo stationListGMHCJku = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => !t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => t.remark.Contains("一楼隔膜库3缓存架"))
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)").First();
|
if (stationListGMHCJku != null)
|
{
|
string agv_remark = "二楼铝壳缓存架任务下料";
|
string begin = fcStation.stationCode;
|
string end = stationListGMHCJku.stationCode;
|
agvtaskAdd(agv_remark, begin, end, true);
|
}
|
}
|
}
|
//产线呼叫,二楼直接送料到产线
|
else
|
{
|
string agv_remark = "二楼铝壳缓存架任务下料";
|
string begin = fcStation.stationCode;
|
string end = stationListGMHCJ.stationCode;
|
agvtaskAdd(agv_remark, begin, end, true);
|
|
}
|
|
}
|
|
|
|
}
|
}
|
}
|
|
#endregion
|
#region 一楼线边空位铝壳缓存架呼叫隔膜库3满托铝壳缓存架
|
//二楼铝壳没有呼叫,进入产线直接呼叫库房满料进行搬运
|
//var dt_Stationinfo= freeDB.Select<dt_stationinfo>()
|
// .Where(t => t.enable == true)
|
// .Where(t => !t.connect)
|
// .Where(t => t.LampGreen)
|
// .Where(t => t.tpgd)
|
// .Where(t => t.wlgd)
|
// .Where(t => t.stationType == "2楼铝壳缓存架")
|
// .Where(@"not EXISTS (select * from dt_agvtask where agv_fromaddress = a.stationCode)")
|
// .Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)").First();
|
//if (stationListGYKTSL==null)
|
//{
|
List<dt_stationinfo> stationList1XBLKSL = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => t.LampGreen)
|
.Where(t => !t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => !t.remark.Contains("一楼隔膜库3缓存架"))
|
.ToList();
|
if (stationList1XBLKSL != null)
|
{
|
foreach (var fcStation in stationList1XBLKSL)
|
{
|
lock (createTaskObj)
|
{
|
dt_agvtask dt_Agvtask = freeDB.Select<dt_agvtask>().Where(t => t.agv_toaddress == fcStation.stationCode).First();
|
if (dt_Agvtask != null)
|
{
|
continue;
|
}
|
dt_stationinfo stationListGMHCJ = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => t.tpgd)
|
.Where(t => t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => t.remark.Contains("一楼隔膜库3缓存架"))
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_fromaddress = a.stationCode)")
|
//查找的目的地址不应该在任务中,也不能是任务的终点
|
//.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)")
|
.First();
|
if (stationListGMHCJ != null)
|
{
|
string agv_remark = "一楼线边铝壳缓存架任务叫料";
|
string begin = stationListGMHCJ.stationCode;
|
string end = fcStation.stationCode;
|
agvtaskAdd(agv_remark, begin, end, false);
|
}
|
|
|
|
}
|
}
|
}
|
|
|
#endregion
|
#region 二楼空位铝壳缓存架呼叫一楼线边空托缓存架回流
|
List<dt_stationinfo> stationList2FLKSL = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => !t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "2楼铝壳缓存架")
|
.ToList();
|
|
|
foreach (var fcStation in stationList2FLKSL)
|
{
|
//Console.WriteLine("线边空托缓存架回流0");
|
lock (createTaskObj)
|
{
|
dt_agvtask dt_Agvtask = freeDB.Select<dt_agvtask>().Where(t => t.agv_toaddress == fcStation.stationCode).First();
|
if (dt_Agvtask != null)
|
{
|
continue;
|
}
|
|
dt_stationinfo stationListGMHCJ = freeDB.Select<dt_stationinfo>()
|
.Where(t => t.enable == true)
|
.Where(t => !t.connect)
|
.Where(t => t.LampGreen)
|
.Where(t => t.tpgd)
|
.Where(t => !t.wlgd)
|
.Where(t => t.stationType == "1楼铝壳缓存架")
|
.Where(t => !t.remark.Contains("一楼隔膜库3缓存架"))
|
.Where(@"not EXISTS (select * from dt_agvtask where agv_fromaddress = a.stationCode)")
|
//查找的目的地址不应该在任务中,也不能是任务的终点
|
//.Where(@"not EXISTS (select * from dt_agvtask where agv_toaddress = a.stationCode)")
|
.First();
|
|
if (stationListGMHCJ != null)
|
{
|
string agv_remark = "铝壳缓存架任务空托回流";
|
string begin = stationListGMHCJ.stationCode;
|
string end = fcStation.stationCode;
|
|
|
|
//UpdateLightInfo(task, true);
|
|
agvtaskAdd(agv_remark, begin, end, true);
|
}
|
}
|
}
|
#endregion
|
}
|
}
|
|
/// <summary>
|
/// 铝壳缓存架状态传递agv
|
/// </summary>
|
/// <param name="agvzzplc"></param>
|
private void AGVTransfershelfstatus(PLCClient agvzzplc)
|
{
|
|
double comErr_2f = 8700.0;//是否掉线
|
double doorCode_2f = 8702.0;//缓存架ID
|
double doorState_2f = 8724.0;//缓存架物料状态(1:空位,2:空托盘,3:满托盘)
|
double gdState_2f = 8726.0;//预留
|
var dt_stationinfo_2f = freeDB.Select<dt_stationinfo>().Where(d => d.area == "2F" && d.remark.Contains("二楼铝壳缓存架"))
|
.OrderBy(t => t.sort)
|
.ToList();
|
foreach (var item in dt_stationinfo_2f)
|
{
|
if (item.connect == true)
|
{
|
//掉线
|
}
|
else
|
{
|
if (item.tpgd == true && item.wlgd == true)
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_2f, Convert.ToInt16(3));
|
}
|
else if (item.tpgd == true && item.wlgd == false)
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_2f, Convert.ToInt16(2));
|
}
|
else
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_2f, Convert.ToInt16(1));
|
}
|
}
|
|
OperateResult W_HCJ_StationCode = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorCode_2f, item.stationCode.ToString());
|
OperateResult W_HCJ_ComErr = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + comErr_2f, item.connect);
|
|
comErr_2f += 30;
|
doorCode_2f += 30;
|
doorState_2f += 30;
|
|
}
|
|
|
double comErr_1f_kf = 8820;//是否掉线
|
double doorCode_1f_kf = 8822.0;//缓存架ID
|
double doorState_1f_kf = 8844.0;//缓存架物料状态(1:空位,2:空托盘,3:满托盘)
|
double gdState_1f_kf = 8846.0;//预留
|
var dt_stationinfo_1f_kf = freeDB.Select<dt_stationinfo>().Where(d => d.area == "1F" && d.remark.Contains("一楼隔膜库3缓存架")).OrderBy(t => t.sort)
|
.ToList();
|
foreach (var item in dt_stationinfo_1f_kf)
|
{
|
if (item.connect == true )
|
{
|
//掉线
|
}
|
else
|
{
|
if (item.tpgd == true && item.wlgd == true)
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_1f_kf, Convert.ToInt16(3));
|
} else if (item.tpgd == true && item.wlgd == false) {
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_1f_kf, Convert.ToInt16(2));
|
}
|
else
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_1f_kf, Convert.ToInt16(1));
|
}
|
}
|
|
OperateResult W_HCJ_StationCode = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorCode_1f_kf, item.stationCode.ToString());
|
OperateResult W_HCJ_ComErr = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + comErr_1f_kf, item.connect);
|
|
comErr_1f_kf += 30;
|
doorCode_1f_kf += 30;
|
doorState_1f_kf += 30;
|
|
}
|
|
|
|
double comErr_1f_cx = 9090;//是否掉线
|
double doorCode_1f_cx = 9092.0;//缓存架ID
|
double doorState_1f_cx = 9114;//缓存架物料状态(1:空位,2:空托盘,3:满托盘)
|
double gdState_1f_cx = 9116;//预留
|
var dt_stationinfo_1f_cx = freeDB.Select<dt_stationinfo>().Where(d=>d.area== "1F"&&d.remark.Contains("铝盒缓存架"))
|
.OrderBy(t => t.sort)
|
.ToList();
|
foreach (var item in dt_stationinfo_1f_cx)
|
{
|
|
if (item.connect == true)
|
{
|
//掉线
|
}
|
else
|
{
|
if (item.tpgd == true && item.wlgd == true)
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_1f_cx, Convert.ToInt16(3));
|
}
|
else if (item.tpgd == true && item.wlgd == false)
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_1f_cx, Convert.ToInt16(2));
|
}
|
else
|
{
|
OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_1f_cx, Convert.ToInt16(1));
|
}
|
}
|
|
OperateResult W_HCJ_StationCode = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorCode_1f_cx, item.stationCode.ToString());
|
OperateResult W_HCJ_ComErr = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + comErr_1f_cx, item.connect);
|
|
comErr_1f_cx += 30;
|
doorCode_1f_cx += 30;
|
doorState_1f_cx += 30;
|
|
}
|
}
|
|
private void agvtaskAdd(string agv_remark, string begin, string end,bool communi)
|
{
|
|
dt_agvtask agvtask = new dt_agvtask
|
{
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
|
agv_fromaddress = begin,
|
agv_toaddress = end,
|
agv_code = "组装AGV调度",
|
agv_remark = agv_remark,
|
agv_taskstate = AGVTaskStateEnum.Create.ToString(),
|
agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
|
agv_worktype = 1,//工作类型
|
agv_materielid = "",
|
agv_qty = 1,
|
agv_createtime = DateTime.Now,
|
agv_grade = 0,//任务优先级
|
agv_userid = "WCS",
|
agv_barcode = ""
|
};
|
|
UpdateLightInfo(agvtask, communi);
|
int A= freeDB.Add(agvtask);
|
|
|
}
|
|
/// <summary>
|
/// 实时轮询更新缓存架的状态
|
/// </summary>
|
private void UpdateHCJInfoByRealTime(PLCClient client)
|
{
|
ModbusTcpNet ModbusPLCClient = client.ModbusPLCClient.ModbusTcpNetClient;
|
var stationList = centerEqDBList.FirstOrDefault(t => t.HCJCenterName == client.PLCName);
|
foreach (var item in stationList.stationInfos)
|
{
|
dt_stationinfo station = freeDB.Select<dt_stationinfo>()
|
.Where(x => x.stationCode == item.HCJCode)
|
.First();
|
////Console.WriteLine($"{station.stationCode}------{DateTime.Now}");
|
if (station == null)
|
{
|
continue;
|
}
|
if (stationList.HCJCenterName == "铝壳缓存架二楼")
|
{
|
string ButtonEnsureDB = item.RPLCDB[0];//确认按钮(绿色)信号点位
|
string tpgdstateDB = item.RPLCDB[1];//托盘光电状态信号点位
|
string wlgdstateDB = item.RPLCDB[2];//物料光电状态信号点位
|
|
////确认按钮(绿色)
|
OperateResult<bool> R_TBR_XT = ModbusPLCClient.ReadBool(ButtonEnsureDB);
|
if (!R_TBR_XT.IsSuccess)
|
{
|
//Console.WriteLine($"-{ModbusPLCClient.IpAddress}---{station.stationCode}----{ButtonEnsureDB}--------false--{R_TBR_XT.Message}----------------");
|
station.connect = true;
|
var stationoff = freeDB.Update(station).UpdateColumns(t => new
|
{
|
t.connect
|
}).ExecuteAffrows();
|
continue;
|
}
|
bool ButtonEnsure = ModbusPLCClient.ReadBool(ButtonEnsureDB).Content;
|
//托盘光电状态
|
bool pgdstate = ModbusPLCClient.ReadBool(tpgdstateDB).Content;
|
//物料光电状态
|
bool wlgdstate = ModbusPLCClient.ReadBool(wlgdstateDB).Content;
|
|
//根据读到的PLC信息,轮询更新数据库信息
|
station.getLastTime = DateTime.Now;
|
station.greenbutton = ButtonEnsure;
|
station.tpgd = pgdstate;
|
station.wlgd = wlgdstate;
|
|
string LampYellowDB = item.WPLCDB[0];//黄灯信号点位
|
string LampGreenDB = item.WPLCDB[1];//绿灯信号点位
|
string LampRedDB = item.WPLCDB[2];//红灯信号点位
|
|
//货架存在任务任务时
|
if (station.task)
|
{
|
if (station.LampYellow)
|
{
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
// Console.WriteLine($"{station.stationCode}---亮---{DateTime.Now}");
|
station.LampRed = false;
|
station.LampYellow = false;
|
station.LampGreen = false;
|
|
}
|
else
|
{
|
ModbusPLCClient.Write(LampYellowDB, true); //黄灯
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
// Console.WriteLine($"{station.stationCode}---灭---{DateTime.Now}");
|
station.LampRed = false;
|
station.LampYellow = true;
|
station.LampGreen = false;
|
|
}
|
}
|
else
|
{
|
//当有人按下绿色按钮时:
|
//将缓存架的灯光亮绿灯
|
if (ButtonEnsure && pgdstate && wlgdstate)
|
{
|
DateTime date = DateTime.Now;
|
DateTime time2 = station.greenbuttontime;
|
Double STAMP = (date - time2).TotalSeconds;
|
Console.WriteLine(STAMP);
|
if (STAMP > 4)
|
{
|
if (station.LampGreen)
|
{
|
Console.WriteLine($"{station.stationCode}---------false");
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampGreen = false;
|
|
}
|
else
|
{
|
Console.WriteLine($"{station.stationCode}---------true");
|
ModbusPLCClient.Write(LampGreenDB, true); //绿灯
|
station.LampGreen = true;
|
}
|
|
//ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
//station.LampRed = false;
|
station.LampYellow = false;
|
station.greenbuttontime = DateTime.Now;
|
}
|
}
|
else if (station.LampGreen && (!pgdstate || !wlgdstate))
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampRed = false;
|
station.LampYellow = false;
|
station.LampGreen = false;
|
}
|
//检测托盘光电有料,但未按确认按钮,亮黄灯
|
else if (!station.LampGreen && pgdstate)
|
{
|
// ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, true); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
// station.LampRed = false;
|
station.LampYellow = true;
|
station.LampGreen = false;
|
}
|
else if (!station.LampGreen && !pgdstate&&!wlgdstate)
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
|
station.LampRed = false;
|
station.LampYellow = false;
|
station.LampGreen = false;
|
}
|
//else
|
//{
|
// Console.WriteLine("elsel11111111111");
|
// ModbusPLCClient.Write(LampRedDB, false); //红灯
|
// ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
// ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
// station.LampRed = false;
|
// station.LampYellow = false;
|
// station.LampGreen = false;
|
//}
|
|
}
|
|
station.connect = false;
|
|
var executeAffrows = freeDB.Update(station).UpdateColumns(t => new
|
{
|
t.connect,
|
t.getLastTime,
|
t.greenbutton,
|
t.tpgd,
|
t.wlgd,
|
t.LampRed,
|
t.LampGreen,
|
t.LampYellow
|
}).ExecuteAffrows();
|
}
|
else if (stationList.HCJCenterName == "铝壳缓存架一楼")
|
{
|
string ButtonResetDB = item.RPLCDB[0]; //复位按钮(黄色)信号点位
|
string ButtonEnsureDB = item.RPLCDB[1];//确认按钮(绿色)信号点位
|
string ButtonAlarmDB = item.RPLCDB[2];//报警按钮(红色))信号点位
|
string tpgdstateDB = item.RPLCDB[3];//托盘光电状态信号点位
|
string wlgdstateDB = item.RPLCDB[4];//物料光电状态信号点位
|
|
OperateResult<bool> R_TBR_XT = ModbusPLCClient.ReadBool(ButtonResetDB);
|
if (!R_TBR_XT.IsSuccess)
|
{
|
//Console.WriteLine($"-{ModbusPLCClient.IpAddress}----{station.stationCode}--{ButtonEnsureDB}--------false--{R_TBR_XT.Message}----------------");
|
station.connect = true;
|
var stationoff = freeDB.Update(station).UpdateColumns(t => new
|
{
|
t.connect
|
}).ExecuteAffrows();
|
continue;
|
}
|
//复位按钮(黄色)
|
var ButtonReset = ModbusPLCClient.ReadBool(ButtonResetDB).Content;
|
//确认按钮(绿色)
|
var ButtonEnsure = ModbusPLCClient.ReadBool(ButtonEnsureDB).Content;
|
//报警按钮(红色)
|
var ButtonAlarm = ModbusPLCClient.ReadBool(ButtonAlarmDB).Content;
|
//托盘光电状态
|
var pgdstate = ModbusPLCClient.ReadBool(tpgdstateDB).Content;
|
//物料光电状态
|
var wlgdstate = ModbusPLCClient.ReadBool(wlgdstateDB).Content;
|
|
//根据读到的PLC信息,轮询更新数据库信息
|
station.getLastTime = DateTime.Now;
|
station.YellowButton = ButtonReset;
|
station.greenbutton = ButtonEnsure;
|
station.RedButton = ButtonAlarm;
|
station.tpgd = pgdstate;
|
station.wlgd = wlgdstate;
|
|
string LampRedDB = item.WPLCDB[2];//红灯信号点位
|
string LampGreenDB = item.WPLCDB[1];//绿灯信号点位
|
string LampYellowDB = item.WPLCDB[0];//黄灯信号点位
|
//货架存在任务任务时
|
if (station.task)
|
{
|
if (station.LampYellow)
|
{
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯 // Console.WriteLine($"{station.stationCode}---亮---{DateTime.Now}");
|
station.LampRed = false;
|
station.LampYellow = false;
|
station.LampGreen = false;
|
}
|
else
|
{
|
ModbusPLCClient.Write(LampYellowDB, true); //黄灯
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
// Console.WriteLine($"{station.stationCode}---灭---{DateTime.Now}");
|
station.LampRed = false;
|
station.LampYellow = true;
|
station.LampGreen = false;
|
}
|
}
|
else
|
{
|
if (!item.HCJName.Contains("一楼隔膜库3缓存柜"))
|
{
|
//当有人按下绿色按钮时:
|
//将缓存架的灯光亮绿灯(1.空位按绿按钮亮绿灯,2.空托盘按黄色按钮亮绿灯)
|
if ((ButtonEnsure && !pgdstate && !wlgdstate)||(ButtonReset && pgdstate && !wlgdstate))
|
{
|
DateTime date= DateTime.Now;
|
DateTime time2 = station.greenbuttontime;
|
Double STAMP = (date - time2).TotalSeconds;
|
// Console.WriteLine(STAMP);
|
if (STAMP>3)
|
{
|
if (station.LampGreen)
|
{
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampGreen = false;
|
//Console.WriteLine(station.stationCode);
|
//Console.WriteLine(station.LampGreen);
|
//Console.WriteLine(false);
|
}
|
else
|
{
|
ModbusPLCClient.Write(LampGreenDB, true); //绿灯
|
station.LampGreen = true;
|
//Console.WriteLine(station.stationCode);
|
//Console.WriteLine(station.LampGreen);
|
//Console.WriteLine(true);
|
|
}
|
|
station.greenbuttontime = DateTime.Now;
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
station.LampRed = false;
|
station.LampYellow = false;
|
}
|
}//检测托盘光电有料,但未按确认按钮,亮黄灯
|
else if (!station.LampGreen && pgdstate)
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, true); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampRed = false;
|
station.LampYellow = true;
|
station.LampGreen = false;
|
}
|
else if (station.LampGreen && pgdstate && wlgdstate)
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, true); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampRed = false;
|
station.LampYellow = true;
|
station.LampGreen = false;
|
}
|
else if (!station.LampGreen && !pgdstate && !wlgdstate)
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampRed = false;
|
station.LampYellow = false;
|
station.LampGreen = false;
|
}
|
//else
|
//{
|
// ModbusPLCClient.Write(LampRedDB, false); //红灯
|
// ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
// ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
// station.LampRed = false;
|
// station.LampYellow = false;
|
// station.LampGreen = false;
|
//}
|
}
|
else
|
{
|
if (pgdstate)
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, true); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampRed = false;
|
station.LampYellow = true;
|
station.LampGreen = false;
|
}
|
else
|
{
|
ModbusPLCClient.Write(LampRedDB, false); //红灯
|
ModbusPLCClient.Write(LampYellowDB, false); //黄灯
|
ModbusPLCClient.Write(LampGreenDB, false); //绿灯
|
station.LampRed = false;
|
station.LampYellow = false;
|
station.LampGreen = false;
|
}
|
}
|
|
}
|
station.connect = false;
|
|
var executeAffrows = freeDB.Update(station).UpdateColumns(t => new
|
{ t.connect,
|
t.getLastTime,
|
t.greenbuttontime,
|
t.YellowButton,
|
t.greenbutton,
|
t.RedButton,
|
t.tpgd,
|
t.wlgd,
|
t.LampRed,
|
t.LampGreen,
|
t.LampYellow
|
}).ExecuteAffrows();
|
}
|
}
|
}
|
|
/// <summary>
|
/// 更新缓存架灯光等信息(任务创建时)
|
/// </summary>
|
/// <param name="task">此时的agv任务</param>
|
private void UpdateLightInfo(dt_agvtask task, bool state)
|
{
|
var fromStation = freeDB.Select<dt_stationinfo>().Where(t => t.stationCode == task.agv_fromaddress)
|
.First();
|
var toStation = freeDB.Select<dt_stationinfo>().Where(t => t.stationCode == task.agv_toaddress).First();
|
if (fromStation != null && toStation != null)
|
{
|
if (state)
|
{
|
PLCClient pLCClient1F = WCSService.Clients.Find(V => V.PLCName.Equals(PLCConst.PLCName1FLKHCJ));
|
PLCClient pLCClient2F = WCSService.Clients.Find(V => V.PLCName.Equals(PLCConst.PLCName2FLKHCJ));
|
if (pLCClient1F != null && pLCClient2F != null)
|
{
|
ModbusTcpNet ModbusPLCClient1F = pLCClient1F.ModbusPLCClient.ModbusTcpNetClient;
|
ModbusTcpNet ModbusPLCClient2F = pLCClient2F.ModbusPLCClient.ModbusTcpNetClient;
|
var stationList1F = centerEqDBList.FirstOrDefault(t => t.HCJCenterName == pLCClient1F.PLCName);
|
var stationList2F = centerEqDBList.FirstOrDefault(t => t.HCJCenterName == pLCClient2F.PLCName);
|
hcjStationInfo toaddress;
|
hcjStationInfo fromaddress;
|
if (task.agv_remark.Contains("铝壳缓存架任务空托回流"))
|
{
|
toaddress = stationList1F.stationInfos.Where(d => d.HCJCode == task.agv_fromaddress).First();
|
fromaddress = stationList2F.stationInfos.Where(d => d.HCJCode == task.agv_toaddress).First();
|
}
|
else
|
{
|
fromaddress = stationList2F.stationInfos.Where(d => d.HCJCode == task.agv_fromaddress).First();
|
toaddress = stationList1F.stationInfos.Where(d => d.HCJCode == task.agv_toaddress).First();
|
|
}
|
|
|
//起点货架三色灯信号点位
|
string beginLampYellowDB = fromaddress.WPLCDB[0];//黄灯信号点位
|
string beginLampGreenDB = fromaddress.WPLCDB[1];//绿灯信号点位
|
string beginLampRedDB = fromaddress.WPLCDB[2];//红灯信号点位
|
//终点货架三色灯信号点位
|
string endLampYellowDB = toaddress.WPLCDB[0];//黄灯信号点位
|
string endLampGreenDB = toaddress.WPLCDB[1];//绿灯信号点位
|
string endLampRedDB = toaddress.WPLCDB[2];//红灯信号点位
|
|
ModbusPLCClient2F.Write(beginLampYellowDB, true); //黄灯
|
ModbusPLCClient2F.Write(beginLampGreenDB, false); //绿灯
|
ModbusPLCClient2F.Write(beginLampRedDB, false); //红灯
|
ModbusPLCClient1F.Write(endLampYellowDB, true); //黄灯
|
ModbusPLCClient1F.Write(endLampGreenDB, false); //绿灯
|
ModbusPLCClient1F.Write(endLampRedDB, false); //红灯
|
|
fromStation.LampRed = false;
|
fromStation.LampGreen = false;
|
fromStation.LampYellow = true;
|
fromStation.task = true;
|
fromStation.lastUpdateTime = DateTime.Now;
|
toStation.LampRed = false;
|
toStation.LampGreen = false;
|
toStation.LampYellow = true;
|
toStation.task = true;
|
toStation.lastUpdateTime = DateTime.Now;
|
}
|
|
freeDB.Update(fromStation)
|
.UpdateColumns(t => new { t.LampRed, t.LampGreen, t.LampYellow, t.task, t.lastUpdateTime })
|
.ExecuteAffrows();
|
freeDB.Update(toStation)
|
.UpdateColumns(t => new { t.LampRed, t.LampGreen, t.LampYellow, t.task, t.lastUpdateTime })
|
.ExecuteAffrows();
|
|
}
|
else
|
{
|
PLCClient pLCClient1F = WCSService.Clients.Find(V => V.PLCName.Equals(PLCConst.PLCName1FLKHCJ));
|
if (pLCClient1F != null)
|
{
|
ModbusTcpNet ModbusPLCClient1F = pLCClient1F.ModbusPLCClient.ModbusTcpNetClient;
|
var stationList1F = centerEqDBList.FirstOrDefault(t => t.HCJCenterName == pLCClient1F.PLCName);
|
var toaddress = stationList1F.stationInfos.Where(d => d.HCJCode == task.agv_toaddress).First();
|
var fromaddress = stationList1F.stationInfos.Where(d => d.HCJCode == task.agv_fromaddress).First();
|
|
//起点货架三色灯信号点位
|
string beginLampYellowDB = fromaddress.WPLCDB[0];//黄灯信号点位
|
string beginLampGreenDB = fromaddress.WPLCDB[1];//绿灯信号点位
|
string beginLampRedDB = fromaddress.WPLCDB[2];//红灯信号点位
|
|
//终点货架三色灯信号点位
|
string endLampYellowDB = toaddress.WPLCDB[0];//黄灯信号点位
|
string endLampGreenDB = toaddress.WPLCDB[1];//绿灯信号点位
|
string endLampRedDB = toaddress.WPLCDB[2];//红灯信号点位
|
|
ModbusPLCClient1F.Write(beginLampYellowDB, true); //黄灯
|
ModbusPLCClient1F.Write(beginLampGreenDB, false); //绿灯
|
ModbusPLCClient1F.Write(beginLampRedDB, false); //红灯
|
ModbusPLCClient1F.Write(endLampYellowDB, true); //黄灯
|
ModbusPLCClient1F.Write(endLampGreenDB, false); //绿灯
|
ModbusPLCClient1F.Write(endLampRedDB, false); //红灯
|
|
fromStation.LampRed = false;
|
fromStation.LampGreen = false;
|
fromStation.LampYellow = true;
|
fromStation.task = true;
|
fromStation.lastUpdateTime = DateTime.Now;
|
toStation.LampRed = false;
|
toStation.LampGreen = false;
|
toStation.LampYellow = true;
|
toStation.task = true;
|
toStation.lastUpdateTime = DateTime.Now;
|
}
|
|
freeDB.Update(fromStation)
|
.UpdateColumns(t => new { t.LampRed, t.LampGreen, t.LampYellow, t.task, t.lastUpdateTime })
|
.ExecuteAffrows();
|
freeDB.Update(toStation)
|
.UpdateColumns(t => new { t.LampRed, t.LampGreen, t.LampYellow, t.task, t.lastUpdateTime })
|
.ExecuteAffrows();
|
}
|
}
|
}
|
|
|
}
|
}
|