|
|
|
|
using DataBlockHelper.DBHelpers;
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web.UI.WebControls;
|
|
|
|
|
|
|
|
|
|
namespace DataBlockHelper.Entity
|
|
|
|
|
{
|
|
|
|
|
public class Db2101Entity
|
|
|
|
|
{
|
|
|
|
|
public Db2101Entity() { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Db2101Entity(ushort startSet, byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
byte[] content = bytes.Skip(startSet).Take(4).ToArray();
|
|
|
|
|
|
|
|
|
|
var trans = PlcConnect.Instance.ByteTransform;
|
|
|
|
|
|
|
|
|
|
var a = content[0];
|
|
|
|
|
var b = content[1];
|
|
|
|
|
enable = a.GetBit(0);
|
|
|
|
|
finished = a.GetBit(1);
|
|
|
|
|
time= trans.TransInt16(content,2);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool enable { get; set; }
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|