using NewLife;
namespace WorkerSynReport.Plc;
public class UntiStatusHMIArrayEntity
{
public UntiStatusHMIArrayEntity(byte[] content)
{
byte byt = content[0];
Mode = byt.GetBit(0);
Status = byt.GetBit(1);
Batch = PlcConnect.Instance.ByteTransform.TransUInt16(content, 2);
Step = PlcConnect.Instance.ByteTransform.TransUInt16(content, 4);
StepCode = PlcConnect.Instance.ByteTransform.TransUInt16(content, 6);
TotalTime = PlcConnect.Instance.ByteTransform.TransInt32(content, 8);
StepTime = PlcConnect.Instance.ByteTransform.TransInt32(content, 12);
Temperature = PlcConnect.Instance.ByteTransform.TransSingle(content, 16);
Speed = PlcConnect.Instance.ByteTransform.TransSingle(content, 20);
FeedValue = PlcConnect.Instance.ByteTransform.TransSingle(content, 24);
ActTolerance = PlcConnect.Instance.ByteTransform.TransSingle(content, 28);
}
public bool Mode { get; private set; }
public bool Status { get; private set; }
public ushort Batch { get; private set; }
public ushort Step { get; private set; }
public ushort StepCode { get; private set; }
public int TotalTime { get; private set; }
public int StepTime { get; private set; }
public float Temperature { get; private set; }
public float Speed { get; private set; }
public float FeedValue { get; private set; }
public float ActTolerance { get; private set; }
}
public class UntiStatusHMIArrayManager
{
private int Length;
private int StartSet;
private int SLength;
private byte[] Bytes;
///
/// 数组处理
///
/// 数组长度
/// 数组起始偏移量
/// 数组单个元素长度
public UntiStatusHMIArrayManager(ushort length, int startSet, int sLength, byte[] bytes)
{
Length = length;
StartSet = startSet;
SLength = sLength;
Bytes = bytes;
}
public List GetList()
{
List ListE = new List(Length);
//var getListE = PlcConnect.Instance.Read("DB2107." + StartSet + ".0", Convert.ToUInt16(Length * SLength));
//if (!getListE.IsSuccess)
//{
// throw new Exception(getListE.Message);
//}
var content = Bytes.Skip(StartSet).Take(Length * SLength).ToArray();
for (int i = 0; i < Length; i++)
{
var singleBlock = content.Skip(SLength * i).Take(SLength).ToArray();
ListE.Add(new UntiStatusHMIArrayEntity(singleBlock));
}
return ListE;
}
}