From 16840c81fc1601cccf59630cc1008f581b4404ba Mon Sep 17 00:00:00 2001 From: nodyang Date: Tue, 24 Oct 2023 09:14:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=82=B9=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataBlockHelper/DBHelpers/DB2104Helper.cs | 42 ++++++- .../DBHelpers/DB2104WriteHelper.cs | 68 +++++++++++ DataBlockHelper/DBHelpers/DB2105Helper.cs | 106 ++++++++++++++++++ .../DBHelpers/DB2105WriteHelper.cs | 61 ++++++++++ DataBlockHelper/DataBlockHelper.csproj | 3 + .../Entity/DB2104Entity/WaterView.cs | 9 ++ 6 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 DataBlockHelper/DBHelpers/DB2104WriteHelper.cs create mode 100644 DataBlockHelper/DBHelpers/DB2105WriteHelper.cs create mode 100644 DataBlockHelper/Entity/DB2104Entity/WaterView.cs diff --git a/DataBlockHelper/DBHelpers/DB2104Helper.cs b/DataBlockHelper/DBHelpers/DB2104Helper.cs index b7f1f94..1809ffc 100644 --- a/DataBlockHelper/DBHelpers/DB2104Helper.cs +++ b/DataBlockHelper/DBHelpers/DB2104Helper.cs @@ -13,7 +13,7 @@ namespace DataBlockHelper.DBHelpers public DB2104Helper() { - this.bytes = PlcConnect.Instance.Read("DB2104.0.0", 3578).Content; + this.bytes = PlcConnect.Instance.Read("DB2104.0.0", 3618).Content; } public RecipeCommEntity RecipeComm => RecipeCom(bytes); @@ -53,5 +53,45 @@ namespace DataBlockHelper.DBHelpers public WeterEntity Weter_M8 => new WeterEntity(3378, bytes); + /// + /// 热水秤A + /// + public WaterEntity GetAHotWater => GetWater(3578); + + /// + /// 热水秤B + /// + + public WaterEntity GetBHotWater => GetWater(3588); + + + /// + /// 冷水秤A + /// + + public WaterEntity GetAColWater => GetWater(3598); + + + /// + /// 冷水秤B + /// + + public WaterEntity GetBColWater => GetWater(3608); + + private WaterEntity GetWater(int start) + { + var instanceByteTransform = PlcConnect.Instance.ByteTransform; + + var ls = bytes.Skip(start).Take(10).ToArray(); + WaterEntity entity = new WaterEntity + { + Bin = instanceByteTransform.TransInt16(ls, 0), + Set = instanceByteTransform.TransSingle(ls, 2), + TolErance = instanceByteTransform.TransSingle(ls, 6) + }; + return entity; + } + + } } diff --git a/DataBlockHelper/DBHelpers/DB2104WriteHelper.cs b/DataBlockHelper/DBHelpers/DB2104WriteHelper.cs new file mode 100644 index 0000000..5531ac2 --- /dev/null +++ b/DataBlockHelper/DBHelpers/DB2104WriteHelper.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using DataBlockHelper.Entity.DB2104Entity; + +namespace DataBlockHelper.DBHelpers +{ + public class Db2104WriteHelper + { + private static readonly string DbName = "DB2104"; + + /// + /// 写入水 写入集合顺序 A 热水 B热水 冷水A 冷水B + /// + /// + public static bool Write(List ls) + { + int start = 3578; + for (int i = 0; i < ls.Count; i++) + { + int no = start + (i * 10); + Write(no, ls[i]); + } + + return true; + } + /// + /// A 热水 + /// + /// + + public static void WriteAHostWater(WaterEntity entity) + { + Write(3578, entity); + } + /// + /// B热水 + /// + /// + public static void WriteBHostWater(WaterEntity entity) + { + Write(3588, entity); + } + /// + /// 冷水A + /// + /// + public static void WriteAColWater(WaterEntity entity) + { + Write(3598, entity); + } + /// + /// 冷水B + /// + /// + public static void WriteBColWater(WaterEntity entity) + { + Write(3608, entity); + } + + + private static void Write(int start, WaterEntity entity) + { + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}:{start}.0", entity.Bin); + siemensS7Net.Write($"{DbName}:{start+2}.0", entity.Set); + siemensS7Net.Write($"{DbName}:{start+6}.0", entity.TolErance); + } + } +} \ No newline at end of file diff --git a/DataBlockHelper/DBHelpers/DB2105Helper.cs b/DataBlockHelper/DBHelpers/DB2105Helper.cs index 6226a03..1bbe765 100644 --- a/DataBlockHelper/DBHelpers/DB2105Helper.cs +++ b/DataBlockHelper/DBHelpers/DB2105Helper.cs @@ -18,5 +18,111 @@ namespace DataBlockHelper.DBHelpers public bool[] Status => new FourBoolArrayManager(48, bytes).GetList(); public bool[] End => new FourBoolArrayManager(50, bytes).GetList(); + + /// + /// 设置启动运行 + /// + public List GetStartJob + { + get + { + List ls = new List(); + var b = bytes.Skip(52).Take(1).First(); + + for (int i = 0; i <8; i++) + { + int no = i + 1; + ls.Add(new NoVal() + { + No = no, + Val = b.GetBit(i) + }); + + } + + return ls; + } + } + + /// + /// 获取手动加粉料数据 + /// + public List GetManScrew + { + get + { + List ls = new List(); + var b = bytes.Skip(53).Take(1).First(); + + for (int i = 0; i <4; i++) + { + int no = i + 1; + ls.Add(new NoVal() + { + No = no, + Val = b.GetBit(i) + }); + + } + + return ls; + } + } + + + /// + /// 获取设定值 + /// + public List GetSetValue + { + get + { + // 54 58 + // 62 66 + // 70 74 + // 78 82 + // 86 90 + // 94 98 + // 102 106 + // 110 114 + + int start = 54; + List ls = new List(); + for (int i = 0; i < 8; i++) + { + int no = i + 1; + var b = bytes.Skip(start).Take(8).ToArray(); + + ls.Add(new SetValue() + { + No = no, + Value = PlcConnect.Instance.ByteTransform.TransSingle(b,0), + Toterance = PlcConnect.Instance.ByteTransform.TransSingle(b,4), + }); + start += 8; + } + + return ls; + } + } + } + + + public class NoVal + { + public int No { get; set; } + public bool Val { get; set; } + } + + + public class SetValue + { + public int No { get; set; } + public float Value { get; set; } + + public float Toterance { get; set; } } + + + } diff --git a/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs b/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs new file mode 100644 index 0000000..a5c9538 --- /dev/null +++ b/DataBlockHelper/DBHelpers/DB2105WriteHelper.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; + +namespace DataBlockHelper.DBHelpers +{ + public class DB2105WriteHelper + { + private static readonly string DbName = "DB2105"; + + + + + public static void WriteSetValueH1(SetValue setValue) + { + WriteSetValue(54, setValue); + } + + public static void WriteSetValueH2(SetValue setValue) + { + WriteSetValue(62, setValue); + } + + public static void WriteSetValueH3(SetValue setValue) + { + WriteSetValue(70, setValue); + } + + public static void WriteSetValueH4(SetValue setValue) + { + WriteSetValue(78, setValue); + } + + public static void WriteSetValueH5(SetValue setValue) + { + WriteSetValue(86, setValue); + } + + public static void WriteSetValueH6(SetValue setValue) + { + WriteSetValue(86, setValue); + } + + public static void WriteSetValueH7(SetValue setValue) + { + WriteSetValue(94, setValue); + } + + public static void WriteSetValueH8(SetValue setValue) + { + WriteSetValue(102, setValue); + } + + + private static void WriteSetValue(int start,SetValue setValue) + { + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}:{start}.0", setValue.Value); + siemensS7Net.Write($"{DbName}:{start+4}.0", setValue.Toterance); + + } + } +} \ No newline at end of file diff --git a/DataBlockHelper/DataBlockHelper.csproj b/DataBlockHelper/DataBlockHelper.csproj index 3fbc87c..b154cb5 100644 --- a/DataBlockHelper/DataBlockHelper.csproj +++ b/DataBlockHelper/DataBlockHelper.csproj @@ -52,7 +52,9 @@ + + @@ -72,6 +74,7 @@ + diff --git a/DataBlockHelper/Entity/DB2104Entity/WaterView.cs b/DataBlockHelper/Entity/DB2104Entity/WaterView.cs new file mode 100644 index 0000000..6770497 --- /dev/null +++ b/DataBlockHelper/Entity/DB2104Entity/WaterView.cs @@ -0,0 +1,9 @@ +namespace DataBlockHelper.Entity.DB2104Entity +{ + public class WaterEntity + { + public short Bin { get; set; } + public float Set { get; set; } + public float TolErance { get; set; } + } +} \ No newline at end of file