diff --git a/DataBlockHelper/DBHelpers/Db2101Helper.cs b/DataBlockHelper/DBHelpers/Db2101Helper.cs index 10d0709..8f6eb4f 100644 --- a/DataBlockHelper/DBHelpers/Db2101Helper.cs +++ b/DataBlockHelper/DBHelpers/Db2101Helper.cs @@ -14,7 +14,7 @@ namespace DataBlockHelper.DBHelpers { public Db2101Helper() { - OperateResult db = PlcConnect.Instance.Read("DB2101.0.0", 62); + OperateResult db = PlcConnect.Instance.Read("DB2101.0.0", 154); bytes = db.Content; } @@ -37,6 +37,14 @@ namespace DataBlockHelper.DBHelpers public Db2101Entity SiloN => new Db2101Entity(54, bytes); public Db2101Entity Siloo => new Db2101Entity(58, bytes); + + + + public Db2101LinEntity LinA=>new Db2101LinEntity(124, bytes); + + public Db2101LinEntity LinB => new Db2101LinEntity(134, bytes); + + public Db2101LinEntity LinC => new Db2101LinEntity(144, bytes); } public class Db2101WriteHelp diff --git a/DataBlockHelper/DBHelpers/Db2101HelperWriter.cs b/DataBlockHelper/DBHelpers/Db2101HelperWriter.cs new file mode 100644 index 0000000..5059871 --- /dev/null +++ b/DataBlockHelper/DBHelpers/Db2101HelperWriter.cs @@ -0,0 +1,49 @@ +using HslCommunication.Profinet.Melsec.Helper; +using HslCommunication.Profinet.Siemens; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataBlockHelper.DBHelpers +{ + public class Db2101HelperWriter + { + private static readonly string DbName = "DB2101"; + private static SiemensS7Net siemensS7Net = PlcConnect.Instance; + public static void WriterLinAStart(bool b) + { + siemensS7Net.Write("DB2101.124.0", b); + } + + public static void WriterLinAEnd(bool b) + { + siemensS7Net.Write("DB2101.124.1", b); + } + + + + public static void WriterLinBStart(bool b) + { + siemensS7Net.Write("DB2101.134.0", b); + } + + public static void WriterLinBEnd(bool b) + { + siemensS7Net.Write("DB2101.134.1", b); + } + + + public static void WriterLinCStart(bool b) + { + siemensS7Net.Write("DB2101.144.0", b); + } + + public static void WriterLinCEnd(bool b) + { + siemensS7Net.Write("DB2101.144.1", b); + } + } +} diff --git a/DataBlockHelper/DataBlockHelper.csproj b/DataBlockHelper/DataBlockHelper.csproj index cb28de8..b194ea6 100644 --- a/DataBlockHelper/DataBlockHelper.csproj +++ b/DataBlockHelper/DataBlockHelper.csproj @@ -60,6 +60,7 @@ + diff --git a/DataBlockHelper/Entity/Db2101Entity.cs b/DataBlockHelper/Entity/Db2101Entity.cs index d1a80f8..2940c11 100644 --- a/DataBlockHelper/Entity/Db2101Entity.cs +++ b/DataBlockHelper/Entity/Db2101Entity.cs @@ -33,4 +33,79 @@ namespace DataBlockHelper.Entity public bool finished { get; set; } public short time { get; set; } } + + + public class Db2101LinEntity + { + + public Db2101LinEntity(ushort startSet, byte[] bytes) + { + byte[] content = bytes.Skip(startSet).Take(10).ToArray(); + var trans = PlcConnect.Instance.ByteTransform; + var a = content[0]; + + Start = a.GetBit(0); + End = a.GetBit(1); + Soure= trans.TransInt16(content,2); + model=trans.TransInt16(content,4); + destination = trans.TransInt16(content, 6); + number= trans.TransInt16(content, 8); + } + + + public bool Start { get; set; } + public bool End { get; set; } + /// + /// 源仓 + /// + public short Soure { get; set; } + /// + /// 1 A 2B 3 A+B + /// + + public short model { get; set; } + + public short destination { get; set; } + + + public short number { get; set; } + + + public int Get() + { + int fan = 0; + int number = destination; // 你想要检查的数字 + if (IsPowerOfTwo(number, out int exponent)) + { + fan=exponent; + + Console.WriteLine($"{number} 是 2 的 {exponent} 次方"); + } + + return fan; + + } + + bool IsPowerOfTwo(int number, out int exponent) + { + exponent = 0; + if (number < 1) + { + return false; + } + + while (number > 1) + { + if (number % 2 != 0) + { + return false; + } + number /= 2; + exponent++; + } + + return true; + } + + } }