master
CZ 6 months ago
parent e250244ee4
commit 21ed823057

@ -69,27 +69,28 @@ namespace Service
*/ */
private static void BatchReadPlc(ModbusTcpMaster master) private static void BatchReadPlc(ModbusTcpMaster master)
{ {
if (PlcApi.con) if (PlcMgr.ModbusTcpMaster!=null)
{ {
var bytes01 = master.BatchReadHolderRegister(1, 115); var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null) if (bytes01 != null)
{ {
PlcApi.DataValidityTime = DateTime.Now; PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData); ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData);
} }
var bytes02 = master.BatchReadHolderRegister(201, 222); var bytes02 = master.BatchReadHolderRegister(201, 222);
if (bytes02 != null) if (bytes02 != null)
{ {
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData); ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData);
} }
var bytes03 = master.BatchReadHolderRegister(701, 10); var bytes03 = master.BatchReadHolderRegister(701, 10);
if (bytes03 != null) if (bytes03 != null)
{ {
PlcApi.DataValidityTime = DateTime.Now; PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData); ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData);
} }
//OperateResult<byte[]> result2 = ModbusTcpNet.Read("x=3;201", 222); //OperateResult<byte[]> result2 = ModbusTcpNet.Read("x=3;201", 222);

@ -33,14 +33,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool IsRemote() public static bool IsRemote()
{ {
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) return PlcMgr.IsRemote();
{
return PlcMgr.PlcToHostData.RemoteLocalControlState.Value == 1010 ? true : false;
}
else
{
return false;
}
} }
/// <summary> /// <summary>
@ -49,14 +42,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool EntranceRadar() public static bool EntranceRadar()
{ {
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) return PlcMgr.EntranceRadar();
{
return PlcMgr.PlcToHostData.RadarStatesIn.Value == 1000 ? true : false;
}
else
{
return false;
}
} }
/// <summary> /// <summary>
@ -65,14 +51,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool ExitRadar() public static bool ExitRadar()
{ {
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds) return PlcMgr.ExitRadar();
{
return PlcMgr.PlcToHostData.RadarStatesOut.Value == 1000 ? true : false;
}
else
{
return false;
}
} }
/// <summary> /// <summary>
@ -84,8 +63,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool WriteEntranceLamp(int data) public static bool WriteEntranceLamp(int data)
{ {
return PlcMgr.WriteEntranceLamp((byte)data); return PlcMgr.WriteEntranceLamp((byte)data);
} }
/// <summary> /// <summary>
@ -97,13 +75,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool WriteExistLamp(int data) public static bool WriteExistLamp(int data)
{ {
/*if (master != null) return PlcMgr.WriteExistLamp(data);
{
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.LightOut.Value = (ushort)data;
return master.WriteValue(writeHostToPlc.LightIn);
}*/
return false;
} }
/// <summary> /// <summary>
@ -114,16 +86,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) return PlcMgr.DistributeSelectPack(inBinNo, outBinNo);
{
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo);
writeHostToPlc.ExitSelection.Value = Convert.ToUInt16(outBinNo);
bool write1 = master.WriteValue(writeHostToPlc.EntrySelection);
bool write2 = master.WriteValue(writeHostToPlc.ExitSelection);
return write1 && write2;
}*/
return false;
} }
@ -133,19 +96,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool StartSwapping() public static bool StartSwapping()
{ {
/*if (master != null) return PlcMgr.StartSwapping();
{
if (plcToHost.TaskType.Value == 0)//是否允许换电
return false;
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.TaskType.Value = (ushort)1;
writeHostToPlc.TaskEnablement.Value = (ushort)1000;
bool write1 = master.WriteValue(writeHostToPlc.TaskType);
bool write2 = master.WriteValue(writeHostToPlc.TaskEnablement);
return write1 && write2;
}*/
return false;
} }
/// <summary> /// <summary>
@ -154,7 +105,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static byte ChannelStatus() public static byte ChannelStatus()
{ {
return 0; return PlcMgr.ChannelStatus();
} }
@ -164,11 +115,7 @@ public class PlcApi
/// <returns>6未连接</returns> /// <returns>6未连接</returns>
public static int ReadPlcTaskStatus() public static int ReadPlcTaskStatus()
{ {
/*if (master != null) return PlcMgr.ReadPlcTaskStatus();
{
return plcToHost.TaskType.Value;
}*/
return (-1);
} }
} }

@ -11,6 +11,16 @@ public abstract class PlcMgr
public static readonly PlcFault PlcFaultData = new PlcFault(); public static readonly PlcFault PlcFaultData = new PlcFault();
/// <summary>
/// 数据有效时间。单位秒
/// </summary>
static int DataTimeSeconds = 2;
/// <summary>
/// 数据刷新时间
/// </summary>
public static DateTime DataValidityTime = DateTime.Now;
/// <summary> /// <summary>
/// 写入口灯 /// 写入口灯
@ -21,7 +31,142 @@ public abstract class PlcMgr
/// <returns></returns> /// <returns></returns>
public static bool WriteEntranceLamp(byte value) public static bool WriteEntranceLamp(byte value)
{ {
HostToPlcData.LightIn.Value = value; if (ModbusTcpMaster != null)
return ModbusTcpMaster.WriteValue(HostToPlcData.LightIn); {
HostToPlcData.LightIn.Value = value;
return ModbusTcpMaster.WriteValue(HostToPlcData.LightIn);
}
return false;
}
/// <summary>
/// 是否远程模式
/// </summary>
/// <returns></returns>
public static bool IsRemote()
{
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{
return PlcToHostData.RemoteLocalControlState.Value == 1010 ? true : false;
}
else
{
return false;
}
}
/// <summary>
/// 入口雷达检测
/// </summary>
/// <returns></returns>
public static bool EntranceRadar()
{
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{
return PlcToHostData.RadarStatesIn.Value == 1000 ? true : false;
}
else
{
return false;
}
}
/// <summary>
/// 出口雷达检测
/// </summary>
/// <returns></returns>
public static bool ExitRadar()
{
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{
return PlcToHostData.RadarStatesOut.Value == 1000 ? true : false;
}
else
{
return false;
}
}
/// <summary>
/// 写出口灯
/// 红灯1020
/// 绿灯1000
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static bool WriteExistLamp(int data)
{
if (ModbusTcpMaster != null)
{
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.LightOut.Value = (ushort)data;
return ModbusTcpMaster.WriteValue(writeHostToPlc.LightIn);
}
return false;
}
/// <summary>
/// 下发选包
/// </summary>
/// <param name="inBinNo">入仓位,仓位号</param>
/// <param name="outBinNo">出仓位,仓位号</param>
/// <returns></returns>
public static bool DistributeSelectPack(string inBinNo, string outBinNo)
{
if (ModbusTcpMaster != null)
{
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.EntrySelection.Value = Convert.ToUInt16(inBinNo);
writeHostToPlc.ExitSelection.Value = Convert.ToUInt16(outBinNo);
bool write1 = ModbusTcpMaster.WriteValue(writeHostToPlc.EntrySelection);
bool write2 = ModbusTcpMaster.WriteValue(writeHostToPlc.ExitSelection);
return write1 && write2;
}
return false;
}
/// <summary>
/// 下发启动换电
/// </summary>
/// <returns></returns>
public static bool StartSwapping()
{
if (ModbusTcpMaster != null)
{
if (PlcToHostData.TaskType.Value == 0)//是否允许换电
return false;
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.TaskType.Value = (ushort)1;
writeHostToPlc.TaskEnablement.Value = (ushort)1000;
bool write1 = ModbusTcpMaster.WriteValue(writeHostToPlc.TaskType);
bool write2 = ModbusTcpMaster.WriteValue(writeHostToPlc.TaskEnablement);
return write1 && write2;
}
return false;
}
/// <summary>
/// 查看拍照状态
/// </summary>
/// <returns></returns>
public static byte ChannelStatus()
{
return 0;
}
/// <summary>
/// 读plc任务状态
/// </summary>
/// <returns>6未连接</returns>
public static int ReadPlcTaskStatus()
{
if (ModbusTcpMaster != null)
{
return PlcToHostData.TaskType.Value;
}
return (-1);
} }
} }

@ -1,6 +1,6 @@
{ {
"Version": 1, "Version": 1,
"Hash": "SIbd/wMGDFDb4PVjR2gB4U/BUVTP3CxZPCnoMCemIoA=", "Hash": "zLyz6C3YNcAfQ4a3PqNREUoaDzuSSMCXv5JiEIrUCxU=",
"Source": "WebStarter", "Source": "WebStarter",
"BasePath": "_content/WebStarter", "BasePath": "_content/WebStarter",
"Mode": "Default", "Mode": "Default",
@ -10,24 +10,22 @@
{ {
"Name": "WebStarter\\wwwroot", "Name": "WebStarter\\wwwroot",
"Source": "WebStarter", "Source": "WebStarter",
"ContentRoot": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\", "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter", "BasePath": "_content/WebStarter",
"Pattern": "**" "Pattern": "**"
} }
], ],
"Assets": [ "Assets": [
{ {
"Identity": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\20240523\\0.jpg", "Identity": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\20240523\\0.jpg",
"SourceId": "WebStarter", "SourceId": "WebStarter",
"SourceType": "Discovered", "SourceType": "Discovered",
"ContentRoot": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\", "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter", "BasePath": "_content/WebStarter",
"RelativePath": "20240523/0.jpg", "RelativePath": "20240523/0.jpg",
"AssetKind": "All", "AssetKind": "All",
"AssetMode": "All", "AssetMode": "All",
"AssetRole": "Primary", "AssetRole": "Primary",
"AssetMergeBehavior": "PreferTarget",
"AssetMergeSource": "",
"RelatedAsset": "", "RelatedAsset": "",
"AssetTraitName": "", "AssetTraitName": "",
"AssetTraitValue": "", "AssetTraitValue": "",
@ -36,17 +34,15 @@
"OriginalItemSpec": "wwwroot\\20240523\\0.jpg" "OriginalItemSpec": "wwwroot\\20240523\\0.jpg"
}, },
{ {
"Identity": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\20240524\\0.jpg", "Identity": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\20240524\\0.jpg",
"SourceId": "WebStarter", "SourceId": "WebStarter",
"SourceType": "Discovered", "SourceType": "Discovered",
"ContentRoot": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\", "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter", "BasePath": "_content/WebStarter",
"RelativePath": "20240524/0.jpg", "RelativePath": "20240524/0.jpg",
"AssetKind": "All", "AssetKind": "All",
"AssetMode": "All", "AssetMode": "All",
"AssetRole": "Primary", "AssetRole": "Primary",
"AssetMergeBehavior": "PreferTarget",
"AssetMergeSource": "",
"RelatedAsset": "", "RelatedAsset": "",
"AssetTraitName": "", "AssetTraitName": "",
"AssetTraitValue": "", "AssetTraitValue": "",
@ -55,17 +51,15 @@
"OriginalItemSpec": "wwwroot\\20240524\\0.jpg" "OriginalItemSpec": "wwwroot\\20240524\\0.jpg"
}, },
{ {
"Identity": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\20240524\\0.png", "Identity": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\20240524\\0.png",
"SourceId": "WebStarter", "SourceId": "WebStarter",
"SourceType": "Discovered", "SourceType": "Discovered",
"ContentRoot": "D:\\AprojectFile\\huanneng\\huannengMain\\WebStarter\\wwwroot\\", "ContentRoot": "D:\\项目文件\\项目报表\\19焕能后背式站控\\04项目源码\\主服务\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter", "BasePath": "_content/WebStarter",
"RelativePath": "20240524/0.png", "RelativePath": "20240524/0.png",
"AssetKind": "All", "AssetKind": "All",
"AssetMode": "All", "AssetMode": "All",
"AssetRole": "Primary", "AssetRole": "Primary",
"AssetMergeBehavior": "PreferTarget",
"AssetMergeSource": "",
"RelatedAsset": "", "RelatedAsset": "",
"AssetTraitName": "", "AssetTraitName": "",
"AssetTraitValue": "", "AssetTraitValue": "",

Loading…
Cancel
Save