Instrument readouts and controls

Bit Field <smart-bit-field>

BitField displays a fixed-width register as individual bits with names, keeping the word value and the bits in sync.

<smart-bit-field> · 8 properties, 3 methods, 1 events · source/modules/smart.bitfield.js

Usage in Blazor

The Razor component is <BitField> in Smart.Blazor.Industrial: every property is a parameter in PascalCase, every event an EventCallback<Event> named On<Event> whose ev["Detail"] is the typed detail class, and the methods are called on the @ref. String choices are enums. In a Blazor Web App (.NET 8 and later) the page needs an interactive render mode, for example @rendermode InteractiveServer; a statically rendered component stays empty.

@using Smart.Blazor.Industrial
@* .NET 8 and later: an interactive render mode, on the page or for the whole app *@
@rendermode InteractiveServer

<BitField @ref="bitField" Interactive="true" Interactive="true"
    OnChange="OnChange" />

@code {
    BitField bitField;

    void OnChange(Event ev)
    {
        BitFieldChangeEventDetail detail = ev["Detail"];
    }

    // Task<bool> Bit(int index)
    void Call() => bitField.Bit(42);
}

Properties

ParameterType, defaultDescription
BitOrder
bitOrder
BitFieldBitOrder
msbFirst
Sets or retrieves the display order of the bits. It affects the display only; bits are always numbered from the least significant bit, so bit 3 is the same bit in both orders.
Bits
bits
IEnumerable<object>Sets or retrieves the register map, as [{ index, label, description, readOnly, color }]. index counts from the least significant bit. A bit marked readOnly refuses to change, a register map is a contract, and a UI that lets an operator flip a reserved bit is lying about the hardware. An entry that is not an object is skipped.
GroupSize
groupSize
int
4
Sets or gets the number of bits grouped together visually. Groups are counted from the least significant end, so nibble boundaries line up with the hexadecimal digits underneath. 0 removes the grouping.
Interactive
interactive
bool
false
Sets or retrieves whether the bits can be toggled by click or keyboard. The property is named for the enabled state because boolean attributes are presence-based, and a property that defaulted to true could not be turned off from markup. When false the bits are not buttons and not in the tab order.
RadixDisplay
radixDisplay
BitFieldRadixDisplay
hex
Sets or retrieves how the word value is written beneath the bits.
ShowIndices
showIndices
bool
true
Sets or retrieves whether each bit shows its number. Boolean attributes are presence-based, so set the property from script to turn it off.
Value
value
object
0
Sets or retrieves the word. Accepts a number, a BigInt, a boolean, or a string with an optional sign and 0x, 0b or 0o prefix (-0x1 is minus one; 1e3 is 1000); a negative value is treated as two's complement. The value is read back as a decimal string - signed for a signed word length, so an int16 at all ones reads -1 - because a 64-bit value cannot be represented exactly as a number. A value wider than the word length is masked, and one that cannot be read becomes 0: whatever was assigned, the property reads back in this form.
WordLength
wordLength
BitFieldWordLength
uint16
Sets or retrieves the register width and signedness. Signedness shows only in the decimal readout: the same bit pattern is 65535 as a uint16 and -1 as an int16.

Methods

MethodDescription
Task<bool> Bit(int index)Returns the value of one bit. The index counts from the least significant bit regardless of the bitOrder property.
index number Bit position from the least significant bit.
void Mask(object mask)Sets or clears every bit that is set in the mask, as a "clear faults" command does. A bit marked readOnly in the register map is not changed, and bits beyond the word length are ignored.
mask number | string | bigint The bits to act on.
on boolean Set them (the default) or clear them.
void SetBit(int index)Sets, clears or toggles one bit. A bit marked readOnly in the register map is not changed.
index number Bit position from the least significant bit.
on boolean Force a state instead of toggling.

Events

Every event is an EventCallback<Event>; Event is a dictionary and ev["Detail"] converts to the detail class named under the event.

EventDescription and detail
OnChange
change
BitFieldChangeEventDetail
This event is triggered when the word changes through the component, a click, the keyboard, setBit or mask. Assigning the value property directly does not raise it.
Value string The new word, as a decimal string.
OldValue string The previous word.
Bit int Which bit changed, or null when a mask changed several at once.

Types

enum BitFieldBitOrder

BitFieldBitOrder.MsbFirst "msbFirst" BitFieldBitOrder.LsbFirst "lsbFirst"

enum BitFieldRadixDisplay

BitFieldRadixDisplay.Hex "hex" BitFieldRadixDisplay.Dec "dec" BitFieldRadixDisplay.Bin "bin" BitFieldRadixDisplay.Oct "oct" BitFieldRadixDisplay.None "none"

enum BitFieldWordLength

BitFieldWordLength.Int8 "int8" BitFieldWordLength.Uint8 "uint8" BitFieldWordLength.Int16 "int16" BitFieldWordLength.Uint16 "uint16" BitFieldWordLength.Int32 "int32" BitFieldWordLength.Uint32 "uint32" BitFieldWordLength.Int64 "int64" BitFieldWordLength.Uint64 "uint64"

CSS variables

The component declares 5 CSS variables; the CSS page shows how to set them.

--smart-bit-size --smart-bit-off-color --smart-bit-on-color --smart-bit-gap --smart-bit-group-gap