using Edge.Core.Parser.BinaryParser.Attributes;
using Edge.Core.Parser.BinaryParser.MessageEntity;
using System;
using System.Collections.Generic;
namespace PressureGage_3051.MessageEntity
{
public enum FunctionCode
{
///
/// Read Holding Registers
///
READ_HOLDING_REGISTERS = 0x03,
///
/// Read Input Registers
///
READ_INPUT_REGISTERS = 0x04,
///
/// Preset Single Register
///
PRESET_SINGLE_REGISTER = 0x06,
///
/// Preset Multiple Registers
///
PRESET_MULTIPLE_REGISTER = 0x10,
}
public abstract class MessageBase : MessageTemplateBase
{
[Format(1, EncodingType.BIN, -9990)]
public byte Address { get; set; }
[Format(1, EncodingType.BIN, -9980)]
public FunctionCode FunctionCode { get; set; }
[EnumerableFormat("%cascade", -9970)]
public List RawDataField { get; set; }
public static float BytesToFloat(byte[] hexBytes)
{
for (int i = 1; i < hexBytes.Length;)
{
var t = hexBytes[i - 1];
hexBytes[i - 1] = hexBytes[i];
hexBytes[i] = t;
i += 2;
}
return BitConverter.ToSingle(hexBytes, 0);
}
}
}