You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/DataBlockHelper/Entity/DB2107Entity/UntiStatusHMIArrayEntity.cs

85 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace DataBlockHelper.Entity.DB2107Entity
{
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);
Currnet = PlcConnect.Instance.ByteTransform.TransSingle(content, 24);
Pressure = 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 Currnet { get; private set; }
public float Pressure { get; private set; }
}
public class UntiStatusHMIArrayManager
{
private int Length;
private int StartSet;
private int SLength;
private byte[] Bytes;
/// <summary>
/// 数组处理
/// </summary>
/// <param name="length">数组长度</param>
/// <param name="startSet">数组起始偏移量</param>
/// <param name="sLength">数组单个元素长度</param>
public UntiStatusHMIArrayManager(ushort length, int startSet, int sLength, byte[] bytes)
{
Length = length;
StartSet = startSet;
SLength = sLength;
Bytes = bytes;
}
public List<UntiStatusHMIArrayEntity> GetList()
{
List<UntiStatusHMIArrayEntity> ListE = new List<UntiStatusHMIArrayEntity>(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;
}
}
}