using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob;
using WIDESEA_Common.Log;
using System.Xml.Linq;
using SixLabors.ImageSharp;
using WIDESEAWCS_QuartzJob.Service;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
namespace WIDESEAWCS_Tasks.StackerCraneJob
{
public class GetDeviceAddress
{
///
/// 传入设备,获取当前位置位置
///
/// 设备
///
public static int GetEquipmentlocation(string ChildPosiDeviceCode)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
if (speStackerCrane == null) return 0;
DeviceProDTO? deviceProDTO = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
int MCGStatus = GetDeviceAddress.RGVGetLine(speStackerCrane, deviceProDTO.DeviceProAddress);
return MCGStatus;
}
///
/// 传入设备,返回设备信息
///
/// 设备
///
public static GetStackerObject GetChildDeviceCode(string ChildPosiDeviceCode)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
if (speStackerCrane == null)
{
Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},002");
return null;
}
GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
return getStackerObject;
}
///
/// 传入设备,返回当前设备信息
///
/// 设备
///
public static int GetEquipmentInformation(string ChildPosiDeviceCode)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
if (speStackerCrane == null)
{
Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},003");
return 0;
}
GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
{
return getStackerObject.RGVCurrentlocation;
}
else
{
return 0;
}
}
///
/// 传入设备,返回当前设备信息(入库母车,需要加入是否有货判断)
///
/// 设备
///
public static int GetEquipmentInMuche(string ChildPosiDeviceCode)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
if (speStackerCrane == null)
{
Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},004");
return 0;
}
GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
{
return getStackerObject.RGVCurrentlocation;
}
else
{
return 0;
}
}
///
/// 传入设备编号,判断设备状态是否可进入
///
///
///
public static bool ReturnCurrentStatus(string ChildPosiDeviceCode)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
if (speStackerCrane == null)
{
Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},005");
return false;
}
GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
{
return true;
}
else
{
return false;
}
}
///
/// 查询HCJ站台设备
///
///
///
///
///
public static DeviceProDTO? GetDeviceProDTO(CommonConveyorLine Commonstacker, string SCAddress, string Interactivet)
{
return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet && x.DeviceProParamType == "ReadDeviceCommand");
}
///
/// 查询RGV设备
///
///
///
///
///
public static DeviceProDTO? GetRGVDeviceProDTO(SpeStackerCrane Commonstacker, string SCAddress, string Interactivet)
{
return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet && x.DeviceProParamType == "RGV_Rgvtaskstutas");
}
///
/// 读取设备信息
///
///
///
///
public static int GetLine(CommonConveyorLine Commonstacker, string DeviceProDataBlock)
{
return Commonstacker.Communicator.Read(DeviceProDataBlock);
}
public static int RGVGetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
{
return Commonstacker.Communicator.Read(DeviceProDataBlock);
}
///
/// 日志记录
///
/// 设备名称
/// 文件名称
/// 日志类型
/// 内容
public void wcsWriteLog(string SCLLinStack,string Filename, string Logtype, string Magessadd)
{
WriteLog.Write_Log(SCLLinStack, Filename, Logtype, new { 信息 = Magessadd });
}
///
/// 传入站台编号,判断是否有货
///
/// 站台编号
public static bool HCJIsstock(string Platformnumber)
{
//获取需要区分是否去入库与去不合格载货台任务
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
CommonConveyorLine Commonstacker = (CommonConveyorLine)device;
DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, Platformnumber.ToString(), "HCJ_GoodsStatus");
int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (HCJGStatus == 0) //为无货
{
return true;
}
else
{
return false;
}
}
///
/// 判断设备是否有货
///
public static bool Mucheywhaddres(string DeviceCode)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == "RgvEquipmentStatus" && x.DeviceProParamType == "RgvEquipmentStatus");
int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if(MCGStatus== (int)RgvEquipmentStatus.NoCargo)
{
return true;
}
return false;
}
///
/// 判断3个站台
///
public static bool AQMStatus(List aGVStatList)
{
try
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
CommonConveyorLine Commonstacker = (CommonConveyorLine)device;
foreach (var item in aGVStatList)
{
DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, item.Station_code.ToString(), "HCJ_GoodsStatus");
int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (HCJGStatus != 0) //为无货
{
return false;
}
}
return true;
}
catch (Exception ex)
{
return false;
throw;
}
}
public static List StationareaList = new List() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115","RGV118" };
public static List InStationareaList = new List() { "RGV101", "RGV103", "RGV105", "RGV108", "RGV109", "RGV104","RGV107" };
public static bool OutbounMotherChildCartbool(string DeviceChildCode)
{
if (StationareaList.Contains(DeviceChildCode))
{
return true;
}
else
{
return false;
}
}
public static bool OutbounMotherChildCartbool2(string DeviceChildCode)
{
if (DeviceChildCode=="RGV104" || DeviceChildCode == "RGV107")
{
return true;
}
else
{
return false;
}
}
///
/// 读取子是否为手动
///
public static bool OutRGVStatice()
{
bool rgvbool=true;
foreach (string AGVStation in StationareaList)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
if (device == null) continue;
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (RGVState == 1)
{
return false;
}
}
return rgvbool;
}
public static bool InRGVStatice()
{
bool rgvbool = true;
foreach (string AGVStation in InStationareaList)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
if (device == null) continue;
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (RGVState == 1)
{
return false;
}
}
return rgvbool;
}
///
/// 出库,读取RGV是否为空闲
///
///
public static bool OutRGVRGVStepprocess()
{
bool rgvbool = true;
foreach (string AGVStation in StationareaList)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
if (device == null) continue;
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (RGVState != 0)
{
return false;
}
}
return rgvbool;
}
public static bool InRGVRGVStepprocess()
{
bool rgvbool = true;
foreach (string AGVStation in InStationareaList)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
if (device == null) continue;
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (RGVState != 0)
{
return false;
}
}
return rgvbool;
}
public static bool WriteSecurityDoorpolice(string DeviceCode,string WriteType,int Writevalue)
{
try
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
if (device == null) return false;
CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
DeviceProDTO? deviceProDTO = commonConveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == WriteType && x.DeviceProParamType == "DeviceCommand");
return commonConveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (short)Writevalue);
}
catch (Exception)
{
return false;
throw;
}
}
public static List AQMListdata = new List() { "AQM001", "AQM002"};
///
/// 判断安全门状态
///
/// 1为出库安全门3号,2为入库安全门判断
///
public static bool ReadAqmDecicStice(int aqmtype)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
if (aqmtype == 1)
{
DeviceProDTO? deviceProDTO = commonConveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == "AQM003" && x.DeviceProParamName == "IndicatorStatus" && x.DeviceProParamType == "ReadDeviceCommand");
short AQMldeng = commonConveyorLine.Communicator.Read(deviceProDTO.DeviceProDataBlock);
if (AQMldeng == 2) return false;
}
else
{
foreach (string aqmname in AQMListdata)
{
DeviceProDTO? deviceProDTO = commonConveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == aqmname && x.DeviceProParamName == "IndicatorStatus" && x.DeviceProParamType == "ReadDeviceCommand");
short AQMldeng = commonConveyorLine.Communicator.Read(deviceProDTO.DeviceProDataBlock);
if (AQMldeng == 2) return false;
}
}
return true;
}
}
}