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