3 Replies Latest reply on Jul 9, 2013 4:18 PM by fbatista

    bit mapping from double in PI-AF

    francois_ruel

      Hi!

       

      Just completed a bunch of searches in documentation and discussions and didn't find the answer...

       

      I have a double that each bit represent a status.

       

      I have a PI-Point Attribute (double) for the status word in my elements and I would like to create additional attributes (boolean) that point to a specific bit in this double.

       

      Is there a way to format my Configuration String like |StatusWord(0) for bit 0? 

       

      Thanks!

       

      Francois

        • Re: bit mapping from double in PI-AF
          fbatista

          François,

           

          Try to create a Formula attribute with something like this:

           

          (A AND 2^n)/(2^n),

           

          Where:

           

          A = your variable mapped to the attribute you want to get the bit info from

           

          n=bit position

           

          Regards,

           

          Fabiano Batista

            • Re: bit mapping from double in PI-AF
              mhamel

              @François: I have created a demonstration for the PI Application Development course that handles this type of bit masking. This is handled by the StringBuilder data reference. You can have access to this demo via the exercise 8.17 in the package file.

               

              I have implemented a three bit masking tests: BINARY, BINARY_AND and BINARY_OR.

               

               

               

               

               

              BINARY(<Attribute>, "<bit to read starting from 0>" This function tests a single bit of any numerical value returned by the given attribute name and return true (1) or false (0). The attribute would be of type relative or absolute following the syntax known from the PI Point Data Reference.

               

              Examples

               

              BINARY(%@..\..\Element1|Attribute1|SubAttribute1%, "2")

               

              This relative path example would test the 3rd bit from the SubAttribute1 attribute of Element1 element located 2 levels above this element's attribute.

               

              or

               

              BINARY(%@\\AFServer\DB\\Element1\SubElement3|Attribute|SubAttribute1%, "2")

               

              This absolute path example would test the 3rd bit from the SubAttribute1 attribute.

               

               

               

               

               

              BINARY_AND(<Attribute name or value>, "<bit to read starting from 0>/<second bit>/.../<n bit>" This function tests all bits of any numerical value returned by the given attribute name and return true (1) if all bits are true or false (0) if one or many bits are false. The attribute would be of type relative or absolute following the syntax known from the PI Point Data Reference

               

               

               

               

               

              BINARY_OR(<Attribute name or value>, "<bit to read starting from 0>/<second bit>/.../<n bit>" This function tests all bits of any numerical value returned by the given attribute name and return true (1) if some bits are true or false (0) if all bits are false.

               

               

               

               

               

              I hope this can help.