In many cases there is a requirement to extract several bits from a serial read result. A custom calculation button has been developed for that.
A shift B and C takes the serial measurement in input A. It will then shift over B bits and do a MASK or AND function with the binary equivalent of the decimal input C.
In this case, It takes a measured serial word. Shifts over 14 bits (to the 15th) and takes the next 4 bits. AND with 1111 binary (15 decimal).
It starts from the LSB. The test plan with the button is attached.
It's a a custom button that is quite helpful for this task. To create this button in your test plan, copy the smalltalk text below:
[ :a | (RiRealD fromFloat: ((((a at:1) asInteger)
bitShift: (((a at:2) asFloat) rounded negated))
bitAnd:(((a at:3) asFloat)) rounded asInteger))]
In your test plan, add a three input calculation button which can be found in the editor under 'System>general calculation'.
Right click on the new calculation button and select 'Edit Block...'
Replace the smalltalk code within the Edit Block window with the code from above and select 'Save'. A popup dialog will let you choose the name of this block as it will appear within the button.
Type in 'A shift B and C' and click 'ok'. A Data Type Select Window will popup. Scroll down the list, select 'RiRealD' from the options and click 'select'. You can no close the Block Edit window.
You can resize the button to read the contents of the name by right clicking within the button, selecting 'Settings...' and then selecting 'Resize'.
This custom three input calculation button takes the input bit stream 'A', shifts the bits by the value 'B', and then applies a bit mask(ANDs) to extract the bits defined by the value C.
For example, for the least significant four bits(3..0) in the byte, the bit stream from the IC byte button connects to A. You do not need to shift the bits and thus B is connected to a constant of 0, and the mask would be '15' (00001111 in binary) to grab the last 4 bits.
The AND or mask value is quite versatile. If for instance you wanted the last four bits, but you were not interested in the middle two you could set C to '9' (00001001) for instance.
The result from this button is in decimal form and can be saved to a 'system save' to view the contents in a worksheet.