Class Registers

extends Object
Support for reading and writing integers to device registers.
Supports:
  • 8-, 16-, 24-, and 32-bit integers
  • Signed and unsigned integers
  • Little endian and big endian

Class summary


constructor --byte-size/int= --byte-order/ByteOrder=
Contructs a new Registers object.

Constructors

constructor --byte-size/int=0 --byte-order/ByteOrder=BIG_ENDIAN
Contructs a new Registers object.
Inheritance
The byte-size can be used to tell this class to write the register in front of data (when writing to registers).The byte-order then determines the order of the bytes.
If a non-zero byte-size is supported, then the subclass must override write-bytes_ data.

Methods

dump --from/any=128 --to/any=256 --width/any=8 -> none
Prints register values.
Prints registers starting at the given from until the given to (exclusive) as hexadecimal digits.
The width indicates the amount of bytes per line.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

read-bytes register/int count/int -> ByteArray
Reads the count bytes from the given register.
Returns a byte array of the read bytes.

read-bytes reg/any count/any [failure] -> ByteArray
Calls the failure block in case of an exception.
Deprecated. Use exception handling instead.

read-i16-be register/int -> int
Reads a signed 16-bit integer from the register.
Uses big endian.

read-i16-le register/int -> int
Reads a signed 16-bit integer from the register.
Uses little endian.

read-i24-be register/int -> int
Reads a signed 24-bit integer from the register.
Uses big endian.

read-i24-le register/int -> int
Reads a signed 24-bit integer from the register.
Uses little endian.

read-i32-be register/int -> int
Reads a signed 32-bit integer from the register.
Uses big endian.

read-i32-le register/int -> int
Reads a signed 32-bit integer from the register.
Uses little endian.

read-i8 register/int -> int
Reads a signed 8-bit integer from the register.

read-u16-be register/int -> int
Reads an unsigned 16-bit integer from the register.
Uses big endian.

read-u16-be register/int [failure] -> int
Reads an unsigned 16-bit integer from the register.
Uses little endian.
Calls the failure block in case of an exception.
Deprecated. Use exception handling instead.

read-u16-le register/int -> int
Reads an unsigned 16-bit integer from the register.
Uses little endian.

read-u24-be register/int -> int
Reads an unsigned 24-bit integer from the register.
Uses big endian.

read-u24-le register/int -> int
Reads an unsigned 24-bit integer from the register.
Uses little endian.

read-u32-be register/int -> int
Reads an unsigned 32-bit integer from the register.
Uses big endian.

read-u32-le register/int -> int
Reads an unsigned 32-bit integer from the register.
Uses little endian.

read-u8 register/int -> int
Reads an unsigned 8-bit integer from the register.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

write-32-le register/int value/int -> none
Writes the value to the given register as a signed 32-bit integer.
Uses little endian.

write-bytes register/int data/ByteArray -> none
Writes the data to the given register.

write-i16-be register/int value/int -> none
Writes the value to the given register as a signed 16-bit integer.
Uses big endian.

write-i16-le register/int value/int -> none
Writes the value to the given register as a signed 16-bit integer.
Uses little endian.

write-i24-be register/int value/int -> none
Writes the value to the given register as a signed 24-bit integer.
Uses big endian.

write-i24-le register/int value/int -> none
Writes the value to the given register as a signed 24-bit integer.
Uses little endian.

write-i32-be register/int value/int -> none
Writes the value to the given register as an unsigned 32-bit integer.
Uses big endian.

write-i8 register/int value/int -> none
Writes the value to the given register as a signed 8-bit integer.

write-u16-be register/int value/int -> none
Writes the value to the given register as an unsigned 16-bit integer.
Uses big endian.

write-u16-le register/int value/int -> none
Writes the value to the given register as an unsigned 16-bit integer.
Uses little endian.

write-u24-be register/int value/int -> none
Writes the value to the given register as an unsigned 24-bit integer.
Uses big endian.

write-u24-le register/int value/int -> none
Writes the value to the given register as an unsigned 24-bit integer.
Uses little endian.

write-u32-le register/int value/int -> none
Writes the value to the given register as an unsigned 32-bit integer.
Uses little endian.

write-u8 register/int value/int -> none
Writes the value to the given register as an unsigned 8-bit integer.