using System; namespace MewtocolNet.RegisterAttributes { /// /// Defines the behavior of a register property /// [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class RegisterAttribute : Attribute { internal int MemoryArea; internal int StringLength; internal RegisterType RegisterType; internal byte SpecialAddress = 0x0; internal BitCount BitCount; internal int AssignedBitIndex = -1; /// /// Attribute for string type or numeric registers /// /// The area in the plcs memory /// The max string length in the plc public RegisterAttribute(int memoryArea, int stringLength = 1) { MemoryArea = memoryArea; StringLength = stringLength; } /// /// Attribute for boolean registers /// public RegisterAttribute(IOType type, byte spAdress = 0x0) { MemoryArea = 0; RegisterType = (RegisterType)(int)type; SpecialAddress = spAdress; } /// /// Attribute for boolean registers /// public RegisterAttribute(IOType type, int memoryArea, byte spAdress = 0x0) { MemoryArea = memoryArea; RegisterType = (RegisterType)(int)type; SpecialAddress = spAdress; } /// /// Attribute to read numeric registers as bitwise /// /// The area in the plcs memory /// The number of bits to parse public RegisterAttribute(int memoryArea, BitCount bitcount) { MemoryArea = memoryArea; StringLength = 0; BitCount = bitcount; } /// /// Attribute to read numeric registers as bitwise /// /// The area in the plcs memory /// The number of bits to parse /// The index of the bit that gets linked to the bool public RegisterAttribute(int memoryArea, uint assignBit, BitCount bitcount) { if (assignBit > 15 && bitcount == BitCount.B16) { throw new NotSupportedException("The assignBit parameter cannot be greater than 15 in a 16 bit var"); } if (assignBit > 31 && bitcount == BitCount.B32) { throw new NotSupportedException("The assignBit parameter cannot be greater than 31 in a 32 bit var"); } MemoryArea = memoryArea; StringLength = 0; BitCount = bitcount; AssignedBitIndex = (int)assignBit; } } }