Class CipBOOL

  • Direct Known Subclasses:
    CipBOOL.CipBOOL16, CipBOOL.CipBOOL32, CipBOOL.CipBOOL64

    public class CipBOOL
    extends BaseDataType<java.lang.Boolean>
    Rockwell's processors don't actually use BOOL variables in arrays. The instance exposed to the world is really an array of DWORDs.

    Unlike other types, bit arrays are packed into a single-dimensional storage array, of a selected primitive type. (Byte, short, integer, long.)

    Multi-dimensional arrays are translated to/from a linear subscript as needed.

    • Field Detail

      • storageBits

        public final int storageBits
    • Constructor Detail

      • CipBOOL

        public CipBOOL​(PathSegment parentSeg,
                       BoolHost parent,
                       int bitnum)
        Construct a BOOL structure member from a specific bit of a host member of the same structure.
        Parameters:
        parent - The host member containing this BOOL.
        bitnum - The bit number, starting with zero as the least significant bit.
      • CipBOOL

        public CipBOOL​(int[] dimensions)
        Construct a stand-alone array CIP BOOL data value with the given dimensions, all initialized to false. Default is storage in bytes.
        Parameters:
        dimensions -
      • CipBOOL

        public CipBOOL​(int[] dimensions,
                       int storageBits)
      • CipBOOL

        public CipBOOL​(boolean state)
        Construct a stand-alone CIP BOOL data value with the given initial value. Default to storage in bytes.
        Parameters:
        state - Initial value
      • CipBOOL

        public CipBOOL​(boolean state,
                       int storageBits)
      • CipBOOL

        protected CipBOOL​(CipBOOL data,
                          int[] indices)
    • Method Detail

      • setDimensions

        public void setDimensions​(int[] newDimensions)
        Description copied from class: BaseDataType
        Update the lengths of the array dimensions to the given values. The number of subscripts must match the current number of subscripts. The operation must be data-preserving.

        This implementation handles pure Object storage types. Anything else must override.

        Overrides:
        setDimensions in class BaseDataType<java.lang.Boolean>
      • getNestingDef

        public DataDefinitionSeg getNestingDef()
        Description copied from class: BaseDataType
        Return the element (not including array) type definition as a Path Segment, using the abbreviated form if a composite data type.
        Specified by:
        getNestingDef in class BaseDataType<java.lang.Boolean>
      • crcName

        public java.lang.String crcName()
        Description copied from class: BaseDataType
        Obtain the name of this type as used for computing structure CRCs. Can be different from the name(s) used by the CipPath parser.
        Overrides:
        crcName in class BaseDataType<java.lang.Boolean>
        Returns:
      • get

        public java.lang.Boolean get​(int[] indices)
        Description copied from class: BaseDataType
        Application-side value retrieval. Subclasses must implement this function to retrieve elements of the storage array in the application data type.
        Specified by:
        get in class BaseDataType<java.lang.Boolean>
        Parameters:
        indices - Array subscripts. Missing subscripts not allowed.
        Returns:
      • intValue

        public int intValue​(int... indices)
        Description copied from class: BaseDataType
        For data types 32-bits wide or less, return the best available 32-bit representation. If the subscripts are incomplete, return the element with the remaining subscripts set to zero.
        Overrides:
        intValue in class BaseDataType<java.lang.Boolean>
        Parameters:
        indices - Array subscripts.
        Returns:
      • set

        public void set​(int[] indices,
                        java.lang.Boolean val)
        Description copied from class: BaseDataType
        Application-side value storage. Subclasses must implement this function to store one value or complex element into the storage array.
        Specified by:
        set in class BaseDataType<java.lang.Boolean>
        Parameters:
        indices - Array subscripts. Missing subscripts not allowed.
      • bytesEach

        public int bytesEach()
        Description copied from class: BaseDataType
        Obtain the bytes-per-element of this object's payload encoding. Objects with variable length encodings must return zero and implement the bytesImpl(), minEach(), maxEach(), and alignment() methods instead.
        Specified by:
        bytesEach in class BaseDataType<java.lang.Boolean>
        Returns:
        encoded bytes per element
      • minEach

        public int minEach()
        Description copied from class: BaseDataType
        Obtain the smallest number of bytes a single item can occupy in encoded form. Used in structures to compute min/max offset and total structure size range.

        Types where bytesEach is a constant should override this to return that constant too, as a performance optimization.

        Overrides:
        minEach in class BaseDataType<java.lang.Boolean>
        Returns:
      • maxEach

        public int maxEach()
        Description copied from class: BaseDataType
        Obtain the largest number of bytes a single item can occupy in encoded form. Used in structures to compute min/max offset and total structure size range.

        Types where bytesEach is a constant should override this to return that constant too, as a performance optimization.

        Overrides:
        maxEach in class BaseDataType<java.lang.Boolean>
        Returns:
      • alignment

        public int alignment()
        Description copied from class: BaseDataType
        Obtain the natural alignment of this data type. Used in structures to compute min/max offset and alignment.

        Types where bytesEach is a constant should override this to return a suitable constant too, as a performance optimization.

        Overrides:
        alignment in class BaseDataType<java.lang.Boolean>
        Returns:
      • leftShiftBytes

        public byte[] leftShiftBytes​(byte[] source,
                                     int by)
      • rightShiftBytes

        public byte[] rightShiftBytes​(byte[] source,
                                      int by)
      • setPayload

        public void setPayload​(java.nio.ByteBuffer source,
                               int... indices)
        Arrays of booleans require special payload handling, as bits are packed into an array of primitive types.
        Overrides:
        setPayload in class BaseDataType<java.lang.Boolean>
      • setPayloadImpl

        protected void setPayloadImpl​(java.nio.ByteBuffer source,
                                      int[] indices)
        Description copied from class: BaseDataType
        All concrete implementations must supply their per-element decoder here.
        Specified by:
        setPayloadImpl in class BaseDataType<java.lang.Boolean>
      • putPayload

        public void putPayload​(java.nio.ByteBuffer dest,
                               int... indices)
        Arrays of booleans require special payload handling, as bits are * packed into an array of primitive types.
        Overrides:
        putPayload in class BaseDataType<java.lang.Boolean>
      • putPayloadImpl

        protected void putPayloadImpl​(java.nio.ByteBuffer dest,
                                      int[] indices)
        Description copied from class: BaseDataType
        All concrete implementations must supply their per-element encoder here.
        Specified by:
        putPayloadImpl in class BaseDataType<java.lang.Boolean>
      • structCRCString

        public java.lang.String structCRCString()
        Description copied from class: BaseDataType
        Logix processors don't follow CIP Volume 1 Table C-6.9 in their tag read/write routines for structures. Instead, they run the CRC over comma-separated ASCII type strings that make up the structure. This is referred to in the Logix Data Access Programming Manual as the "Structure Handle".
        Overrides:
        structCRCString in class BaseDataType<java.lang.Boolean>
        Returns:
      • putAbbrevType

        public void putAbbrevType​(java.nio.ByteBuffer dest)
        Description copied from class: BaseDataType
        Many subclasses will be data elements supported by Logix processors. The LogixTagType interface requires this routine, which is identical for all types with a compact representation.
        Overrides:
        putAbbrevType in class BaseDataType<java.lang.Boolean>
      • getSymbolType

        public short getSymbolType()
        The BOOL data type must include the host bit number in bits 8-10 of the symbol type. Not applicable to arrays of BOOL. (Only applicable to Logix singleton tags). They must be hosted in a primitive type.
        Overrides:
        getSymbolType in class BaseDataType<java.lang.Boolean>
      • bytes

        public int bytes​(int... indices)
        Arrays of booleans require special payload handling, as bits are packed into bytes, shorts, integers, or longs.
        Overrides:
        bytes in class BaseDataType<java.lang.Boolean>
        Returns:
      • nestedBytes

        public int nestedBytes​(boolean asStruct,
                               int... indices)
        Description copied from class: BaseDataType
        Certain types (Omron strings and booleans) can have different encodings when packed into structures. CipStruct will always call this method with asStruct set true so that such types can report the correct size.
        Overrides:
        nestedBytes in class BaseDataType<java.lang.Boolean>
        Returns:
      • bytesImpl

        protected int bytesImpl​(int[] indices)
        Description copied from class: BaseDataType
        Retrieve the bytes payload size of a single array element (or sole element). Objects with fixed element sizes may simply return bytesEach() here.
        Specified by:
        bytesImpl in class BaseDataType<java.lang.Boolean>
        Returns:
      • copyToImpl

        protected void copyToImpl​(BaseDataType<?> dest,
                                  int[] indices)
        Description copied from class: BaseDataType
        Support deep copy operations one element at a time.
        Specified by:
        copyToImpl in class BaseDataType<java.lang.Boolean>
      • copyToImpl

        protected void copyToImpl​(BaseDataType<?> dest,
                                  int[] toIndices,
                                  int[] fromIndices)
        Description copied from class: BaseDataType
        Support slice copy operations one element at a time.
        Specified by:
        copyToImpl in class BaseDataType<java.lang.Boolean>
      • wrap

        public CipBOOL wrap​(int[] indices)
        Description copied from class: BaseDataType
        Application-side wrapper for inner dimensions. Implementations must update memberOffsets if not not using the protected constructor.
        Specified by:
        wrap in class BaseDataType<java.lang.Boolean>
        Parameters:
        indices - Array subscripts. Missing subscripts are allowed.
      • singleToString

        protected java.lang.String singleToString​(int[] indices)
        Overrides:
        singleToString in class BaseDataType<java.lang.Boolean>
      • main

        public static void main​(java.lang.String[] args)