|
|
@ -3,15 +3,14 @@ using HybirdFrameworkServices.Plc;
|
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
|
|
using Service.Cloud.Msg.Cloud.Req;
|
|
|
|
using Service.Cloud.Msg.Cloud.Req;
|
|
|
|
using Service.Init.Entity;
|
|
|
|
using Service.Init.Entity;
|
|
|
|
|
|
|
|
using Service.Plc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Service.Execute.Api;
|
|
|
|
namespace Service.Execute.Api;
|
|
|
|
|
|
|
|
|
|
|
|
public class PlcApi
|
|
|
|
public class PlcApi
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public static HostToPlc hostToPlc = new HostToPlc();
|
|
|
|
private const int TimeSpan = 60;
|
|
|
|
public static PlcToHost plcToHost = new PlcToHost();
|
|
|
|
|
|
|
|
public static PlcFault plcFault = new PlcFault();
|
|
|
|
|
|
|
|
public static ModbusTcpMaster master;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// PLC是否连接
|
|
|
|
/// PLC是否连接
|
|
|
@ -36,7 +35,7 @@ public class PlcApi
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return plcToHost.RemoteLocalControlState.Value == 1010 ? true : false;
|
|
|
|
return PlcMgr.PlcToHostData.RemoteLocalControlState.Value == 1010 ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -52,7 +51,7 @@ public class PlcApi
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return plcToHost.RadarStatesIn.Value == 1000 ? true : false;
|
|
|
|
return PlcMgr.PlcToHostData.RadarStatesIn.Value == 1000 ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -68,7 +67,7 @@ public class PlcApi
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return plcToHost.RadarStatesOut.Value == 1000 ? true : false;
|
|
|
|
return PlcMgr.PlcToHostData.RadarStatesOut.Value == 1000 ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -85,13 +84,8 @@ public class PlcApi
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool WriteEntranceLamp(int data)
|
|
|
|
public static bool WriteEntranceLamp(int data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (master != null)
|
|
|
|
return PlcMgr.WriteEntranceLamp((byte)data);
|
|
|
|
{
|
|
|
|
|
|
|
|
HostToPlc writeHostToPlc = new HostToPlc();
|
|
|
|
|
|
|
|
writeHostToPlc.LightIn.Value = (ushort)data;
|
|
|
|
|
|
|
|
return master.WriteValue(writeHostToPlc.LightIn);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -103,12 +97,12 @@ public class PlcApi
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool WriteExistLamp(int data)
|
|
|
|
public static bool WriteExistLamp(int data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (master != null)
|
|
|
|
/*if (master != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HostToPlc writeHostToPlc = new HostToPlc();
|
|
|
|
HostToPlc writeHostToPlc = new HostToPlc();
|
|
|
|
writeHostToPlc.LightOut.Value = (ushort)data;
|
|
|
|
writeHostToPlc.LightOut.Value = (ushort)data;
|
|
|
|
return master.WriteValue(writeHostToPlc.LightIn);
|
|
|
|
return master.WriteValue(writeHostToPlc.LightIn);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -120,7 +114,7 @@ public class PlcApi
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool DistributeSelectPack(string inBinNo, string outBinNo)
|
|
|
|
public static bool DistributeSelectPack(string inBinNo, string outBinNo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (master != null)
|
|
|
|
/*if (master != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HostToPlc writeHostToPlc = new HostToPlc();
|
|
|
|
HostToPlc writeHostToPlc = new HostToPlc();
|
|
|
|
writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo);
|
|
|
|
writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo);
|
|
|
@ -128,7 +122,7 @@ public class PlcApi
|
|
|
|
bool write1 = master.WriteValue(writeHostToPlc.EntrySelection);
|
|
|
|
bool write1 = master.WriteValue(writeHostToPlc.EntrySelection);
|
|
|
|
bool write2 = master.WriteValue(writeHostToPlc.ExitSelection);
|
|
|
|
bool write2 = master.WriteValue(writeHostToPlc.ExitSelection);
|
|
|
|
return write1 && write2;
|
|
|
|
return write1 && write2;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -139,7 +133,7 @@ public class PlcApi
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool StartSwapping()
|
|
|
|
public static bool StartSwapping()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (master != null)
|
|
|
|
/*if (master != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (plcToHost.TaskType.Value == 0)//是否允许换电
|
|
|
|
if (plcToHost.TaskType.Value == 0)//是否允许换电
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -150,7 +144,7 @@ public class PlcApi
|
|
|
|
bool write1 = master.WriteValue(writeHostToPlc.TaskType);
|
|
|
|
bool write1 = master.WriteValue(writeHostToPlc.TaskType);
|
|
|
|
bool write2 = master.WriteValue(writeHostToPlc.TaskEnablement);
|
|
|
|
bool write2 = master.WriteValue(writeHostToPlc.TaskEnablement);
|
|
|
|
return write1 && write2;
|
|
|
|
return write1 && write2;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -170,10 +164,10 @@ public class PlcApi
|
|
|
|
/// <returns>6未连接</returns>
|
|
|
|
/// <returns>6未连接</returns>
|
|
|
|
public static int ReadPlcTaskStatus()
|
|
|
|
public static int ReadPlcTaskStatus()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (master != null)
|
|
|
|
/*if (master != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return plcToHost.TaskType.Value;
|
|
|
|
return plcToHost.TaskType.Value;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
return (-1);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|