Browse Source

变量状态添加

reconfiguration
pry 3 months ago
parent
commit
5323e4db15
5 changed files with 131 additions and 61 deletions
  1. +10
    -0
      BPASmartClient.Academy/50L/AddData.cs
  2. +21
    -0
      BPASmartClient.Academy/50L/AlarmData.cs
  3. +27
    -0
      BPASmartClient.Academy/50L/ExtendMethod.cs
  4. +24
    -60
      BPASmartClient.Academy/50L/FeedbackData.cs
  5. +49
    -1
      BPASmartClient.Academy/50L/PlcControl.cs

+ 10
- 0
BPASmartClient.Academy/50L/AddData.cs View File

@@ -11,6 +11,7 @@ namespace BPASmartClient.Academy._50L
{
protected Dictionary<BoolAddEnum, string> boolAdds { get; set; } = new Dictionary<BoolAddEnum, string>();
protected Dictionary<FloatAddEnum, string> floatAdds { get; set; } = new Dictionary<FloatAddEnum, string>();
public ConcurrentDictionary<FeedbackData, object> Data { get; set; } = new ConcurrentDictionary<FeedbackData, object>();

protected Dictionary<T, string> GetAdd<T>() where T : Enum
{
@@ -41,6 +42,15 @@ namespace BPASmartClient.Academy._50L
{
boolAdds = GetAdd<BoolAddEnum>();
floatAdds = GetAdd<FloatAddEnum>();
Enum.GetNames(typeof(FeedbackData)).ToList().ForEach(x => {
if (x.TryToEnum(out FeedbackData fbd))
{
Data.TryAdd(fbd, 0);
}
});
AlarmHelper.GetInstance.AddNotify = (s) => { MessageNotify.GetInstance.ShowAlarmLog(s.Info); };
AlarmHelper.GetInstance.Register<AlarmData>("50L反应釜");
AlarmHelper.GetInstance.Start();
}
}
}

+ 21
- 0
BPASmartClient.Academy/50L/AlarmData.cs View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AlarmAttribute = BPA.Helper.AlarmAttribute;

namespace BPASmartClient.Academy._50L
{
public class AlarmData
{
[Alarm("急停")]
public bool EStop { get; set; }

[Alarm("反应釜旋转电机异常")]
public bool RotatingMachinesError { get; set; }

[Alarm("负压风机异常")]
public bool AbnormalNegativePressureFan { get; set; }
}
}

+ 27
- 0
BPASmartClient.Academy/50L/ExtendMethod.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Academy._50L
{
public static class ExtendMethod
{
public static T GetValue<T>(this FeedbackData fbd) {
if (PlcControl.GetInstance.Data.ContainsKey(fbd))
{
try
{
return (T)Convert.ChangeType(PlcControl.GetInstance.Data[fbd], typeof(T));
}
catch (Exception e) {
return default(T);
}
}
else {
return default(T);
}
}
}
}

+ 24
- 60
BPASmartClient.Academy/50L/FeedbackData.cs View File

@@ -1,4 +1,5 @@
using System;
using Opc.Ua.Bindings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,66 +7,29 @@ using System.Threading.Tasks;

namespace BPASmartClient.Academy._50L
{
public class FeedbackData
public enum FeedbackData
{
/// <summary>
/// 旋转电机启停反馈
/// </summary>
public bool RotatingMachines { get; set; }
旋转电机启停反馈,
负压风机启动反馈,
压缩空气进气阀反馈,
排热空气阀反馈,
泄压阀反馈,
进冷却水阀反馈,
出冷却水阀反馈,
蒸汽梳水阀反馈,
冷凝水罐进水阀反馈,
称重水罐负压阀反馈,
反应釜原点位置反馈,
心跳,
反应釜温度,
反应釜蒸汽压力,
反应釜蒸汽流量,
冷凝水罐温度,
冷凝水罐湿度,
负压流量,
称重水罐重量,
反应釜编码器值,
蒸汽比例阀实际开度,

/// <summary>
/// 负压风机启动反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 压缩空气进气阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 排热空气阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 泄压阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 进冷却水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 出冷却水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 蒸汽梳水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 冷凝水罐进水阀反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 称重水罐负压阀
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 反应釜原点位置反馈
/// </summary>
public string MachineName { get; set; }

/// <summary>
/// 心跳
/// </summary>
public string MachineName { get; set; }
}
}

+ 49
- 1
BPASmartClient.Academy/50L/PlcControl.cs View File

@@ -5,6 +5,8 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Diagnostics;

namespace BPASmartClient.Academy._50L
{
@@ -15,18 +17,64 @@ namespace BPASmartClient.Academy._50L
private PlcControl() { }

private ICommSiemens comm = CommHelper.Siemens;
public void Init()
{
CommHelper.CreateSiemens(CpuType.S71200, Json<DevicePar>.Data.IpAddress).OnSuccess(s =>
{
comm = s.Content;
Read();
});
}



private void Read()
{
TaskManage.GetInstance.StartLong(() => {
comm.Read<bool[]>("DB1.DBX2000.0", 11).OnSuccess(s =>
{
Data[FeedbackData.旋转电机启停反馈] = s.Content[0];
Data[FeedbackData.负压风机启动反馈] = s.Content[1];
Data[FeedbackData.压缩空气进气阀反馈] = s.Content[2];
Data[FeedbackData.排热空气阀反馈] = s.Content[3];
Data[FeedbackData.泄压阀反馈] = s.Content[4];
Data[FeedbackData.进冷却水阀反馈] = s.Content[5];
Data[FeedbackData.出冷却水阀反馈] = s.Content[6];
Data[FeedbackData.蒸汽梳水阀反馈] = s.Content[7];
Data[FeedbackData.冷凝水罐进水阀反馈] = s.Content[8];
Data[FeedbackData.称重水罐负压阀反馈] = s.Content[9];
Data[FeedbackData.反应釜原点位置反馈] = s.Content[10];
});

comm.Read<float[]>("DB1.DBD2006", 9).OnSuccess(s =>
{
Data[FeedbackData.反应釜温度] = s.Content[0];
Data[FeedbackData.反应釜蒸汽压力] = s.Content[1];
Data[FeedbackData.反应釜蒸汽流量] = s.Content[2];
Data[FeedbackData.冷凝水罐温度] = s.Content[3];
Data[FeedbackData.冷凝水罐湿度] = s.Content[4];
Data[FeedbackData.负压流量] = s.Content[5];
Data[FeedbackData.称重水罐重量] = s.Content[6];
Data[FeedbackData.反应釜编码器值] = s.Content[7];
Data[FeedbackData.蒸汽比例阀实际开度] = s.Content[8];
});

comm.Read<bool[]>("DB1.DBX1003.7", 1).OnSuccess(s =>{ Data[FeedbackData.心跳] = s.Content[0]; });

comm.Read<bool[]>("DB1.DBX2004.0", 3).OnSuccess(s =>
{
AlarmHelper.GetInstance.Get<AlarmData>("50L反应釜").EStop = s.Content[0];
AlarmHelper.GetInstance.Get<AlarmData>("50L反应釜").RotatingMachinesError = s.Content[1];
AlarmHelper.GetInstance.Get<AlarmData>("50L反应釜").AbnormalNegativePressureFan = s.Content[2];
});

if (Delay.GetInstance("心跳").Start(FeedbackData.心跳.GetValue<bool>(), 3)) {
Write(BoolAddEnum.心跳, true);
}
Thread.Sleep(10);
}, "数据获取", true);

}



Loading…
Cancel
Save