2101 测试

dep_deliver
杨威 6 months ago
parent 53896dbf21
commit a9208a1b1c

@ -14,7 +14,7 @@ namespace DataBlockHelper.DBHelpers
{
public Db2101Helper()
{
OperateResult<byte[]> db = PlcConnect.Instance.Read("DB2101.0.0", 62);
OperateResult<byte[]> 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

@ -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);
}
}
}

@ -60,6 +60,7 @@
<Compile Include="DBHelpers\DB191WriteHelper.cs" />
<Compile Include="DBHelpers\DB1Helper.cs" />
<Compile Include="DBHelpers\Db2101Helper.cs" />
<Compile Include="DBHelpers\Db2101HelperWriter.cs" />
<Compile Include="DBHelpers\DB2102Helper.cs" />
<Compile Include="DBHelpers\DB2103Helper.cs" />
<Compile Include="DBHelpers\DB2104Helper.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; }
/// <summary>
/// 源仓
/// </summary>
public short Soure { get; set; }
/// <summary>
/// 1 A 2B 3 A+B
/// </summary>
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;
}
}
}

Loading…
Cancel
Save