This topic provides numerous useful examples of the various ways you can use reference methods in your device template files to perform conversions with constant values and/or reference data group element values. A sample device template file using each example is available upon request; it can be loaded to a DDS and used to test your reference methods. It is called ReferenceTester.dtf. In this topic, methods are described that compute a value from or provide a value for multiple bit positions. To make a single-bit change, see Bit Position.
See the following subsections for details:
For an example of a Bit Mask data group, see the Sample Data Group below.
For information about example data group elements and values used below, see Example Values.
The following example references the data group element raw61 and applies a bit mask of 0x000F to it. The result is 13.
|
<BitMskA desc="Bit Mask Method A" readOnly="true" type="ui2" ref="raw61" bMsk="0x000F"/> |
Useful attributes to know are ref, bitShift, and bMask.
The following example uses two child elements to compute a bit mask. The first child element references the operation opAssignId and the data group element raw61 to assign the current value of raw61 as the initial value for BitMskB. The second child element references the opBitMask operation and applies a bit mask of 0x000F to the decimal value 61 from raw61. The result is the decimal value 13.
|
<BitMskB desc="Bit Mask Method B" readOnly="true" type="ui2" isRef="1"> <ref prec="0" refOp="opAssignId" deid="raw61"/> <ref prec="1" refOp="opBitMask" value="0x000F" bitShift="unsigned"/> </BitMskB> |
Useful attributes to know are isRef, prec, refOp, deid, bitShift, and value. A useful element to know is ref.
The following example references the data group element raw61 and applies a bit mask of 0x000F to it. The resulting bit mask decimal value is 13. An XOR operation is then applied to the decimal value 13. The result of the XOR mask is the decimal value 2.
|
<BitMskXA desc="XOR Bit Mask Method A" readOnly="true" type="ui2" ref="raw61" bMsk="0x000F" bXorMask="0x000F"/> |
Useful attributes to know are ref, bMask, and bXorMask.
The following example uses two child elements to compute an XOR bit mask. The first child element references the operation opAssignId and the data group element raw61 to assign the current value of raw61 as the initial value for BitMskXB. The second child element references the opBitMask operation and applies a bit mask of 0x000F to the decimal value 61 from raw61. The result is the decimal value 13. An XOR bit mask of 0x000F is then applied to the decimal value 13. The result of the XOR mask is the decimal value 2.
|
<BitMskXB desc="XOR Bit Mask Method B" readOnly="true" type="ui2" isRef="1"> <ref prec="0" refOp="opAssignId" deid="raw61"/> <ref prec="1" refOp="opBitMask" value="0x000F" bXorMask="0x000F"/> </BitMskXB> |
Useful attributes to know are isRef, prec, refOp, deid, value, and bXorMask. A useful element to know is ref.
The following example uses two child elements to compute an XOR bit mask. The first child element references the operation opAssignId and the data group element raw61 to assign the current value of raw61 as the initial value for BitMskXC. The second child element references the opBitXorMask operation and applies a bit mask of 0x000F to the decimal value 61 from raw61. The result of the XOR mask is the decimal value 32.
|
<BitMskXC desc="XOR Bit Mask Method C" readOnly="true" type="ui2" isRef="1"> <ref prec="0" refOp="opAssignId" deid="raw61"/> <ref prec="1" refOp="opBitXorMask" value="0x000F"/> </BitMskXC> |
Useful attributes to know are isRef, prec, refOp, deid, and value. A useful element to know is ref.
The following data group example grabs a binary value from a byte using hex masking and applies a decimal conversion. It uses two DEIDs (RAW_1 and RAW_2) and applies a bitmask of 0x8000 to bit 16 in both REF_1 and REF_2. In each of these, the first child element references the operation opAssignId to assign the value of RAW_<> as the initial value for REF_<>. The second child element references the opBitMask operation and applies a bit mask of 0x8000. The third child element references the opScaleFactor operation to scale the result (0 or 1) by the scaleFactor attribute's value of 32768 (in decimal). Finally, it references the results of the raw data elements and sums them together using OpAddId.
|
<BmskSample niceName="Bit-Mask Sample Datagroup" maxCnt="1" baseOrd="0" ordLabel="" devDG="true"> <dgElements secLev="4" byteOrder="bigEndian"> <RAW_1 desc="Raw DEID 1" type="ui2" regDef="1:43" /> <RAW_2 desc="Raw DEID 2" type="ui4" regDef="2:96" /> <REF_1 desc="Bit 16 of 16 of RAW_1" readOnly="true" type="ui2" isRef="1" hidden="true"> <ref prec="0" refOp="opAssignId" deid="RAW_1"/> <ref prec="1" refOp="opBitMask" value="0x8000"/> <ref prec="2" refOp="opScaleFactor" scaleFactor="32768"/> </REF_1> <REF_2 desc="Bit 16 of 32 of RAW_2" readOnly="true" type="ui2" isRef="1" hidden="true"> <ref prec="0" refOp="opAssignId" deid="RAW_2"/> <ref prec="1" refOp="opBitMask" value="0x8000"/> <ref prec="2" refOp="opScaleFactor" scaleFactor="32768"/> </REF_2> <REF_SUM desc="Bit 16 of RAW_1 + bit 16 of RAW_2" readOnly="true" type="ui4" isRef="1"> <ref prec="0" refOp="opAssignId" deid="REF_1"/> <ref prec="1" refOp="opAddId" deid="REF_2"/> </REF_SUM> </dgElements> <modbusReadBlocks regByteLen="2" regOff="0"> <block1 funcCode="3" regCnt="100" regNum="8000" ordIncrement="1000" regByteLen="2" /> <block2 funcCode="3" regCnt="100" regNum="8100" ordIncrement="1000" regByteLen="2" /> </modbusReadBlocks> </BmskSample> |
Useful attributes to know are isRef, prec, refOp, deid, scaleFactor, and value. A useful element to know is ref.