mbserver 0.5.1
mbserver._MemoryBlock Class Reference
Inheritance diagram for mbserver._MemoryBlock:
Inheritance graph
Collaboration diagram for mbserver._MemoryBlock:
Collaboration graph

Public Member Functions

int getid (self)
str getbyteorder (self)
str getregisterorder (self)
bytes getbytes (self, int byteoffset, int bytecount)
bytearray getbytearray (self, int byteoffset, int bytecount)
 setbytes (self, int byteoffset, Union[bytes, bytearray] value)
bytearray getbitbytearray (self, int bitoffset, int bitcount)
bytes getbitbytes (self, int bitoffset, int bitcount)
 setbitbytes (self, int bitoffset, int bitcount, Union[bytes, bytearray] value)
bool getbit (self, int bitoffset)
 setbit (self, int bitoffset, bool value)
str getbitstring (self, int bitoffset, int bytecount)
 setbitstring (self, int bitoffset, str value)
str getbytestring (self, int byteoffset, int bytecount)
 setbytestring (self, int byteoffset, str value)
str getregstring (self, int regoffset, int bytecount)
 setregstring (self, int regoffset, str value)

Detailed Description

Base class for the memory objects mem0x, mem1x, mem3x, mem4x.

   Class is abstract (can't be used directly). 

Member Function Documentation

◆ getbit()

bool mbserver._MemoryBlock.getbit ( self,
int bitoffset )
Return a single bit value as bool starting at `bitoffset`.

For register memory, `bitoffset = offset * 16`.

Args:
    bitoffset  Bit offset (0-based).

Returns:
    `True` or `False`.

Note:
    If `bitoffset` is out of range, returns `False`.

◆ getbitbytearray()

bytearray mbserver._MemoryBlock.getbitbytearray ( self,
int bitoffset,
int bitcount )
Return `bytearray` from bit memory starting at `bitoffset`.

Same parameters and behavior as `getbitbytes()`.

Args:
    bitoffset  Bit offset (0-based).
    bitcount   Count of bits to read.

Returns:
    `bytearray` with data read as bits.

See Also:
    getbitbytes()

◆ getbitbytes()

bytes mbserver._MemoryBlock.getbitbytes ( self,
int bitoffset,
int bitcount )
Return `bytes` from device memory starting at `bitoffset` for `bitcount` bits.

For bit memory, `bitoffset` is the coil/bit index.
For register memory, `bitoffset = offset * 16`.

Args:
    bitoffset  Bit offset (0-based).
    bitcount   Count of bits to read.

Returns:
    `bytes` object with data read from device memory.

◆ getbitstring()

str mbserver._MemoryBlock.getbitstring ( self,
int bitoffset,
int bytecount )
Return UTF-8 string from bit memory starting at `bitoffset`.

Reads `bytecount` bytes (as bits) and decodes as UTF-8.

Args:
    bitoffset  Bit offset (0-based).
    bytecount  Number of bytes of UTF-8 data to read.

Returns:
    Decoded string value.

Note:
    Since v0.4.2

◆ getbytearray()

bytearray mbserver._MemoryBlock.getbytearray ( self,
int byteoffset,
int bytecount )
Return `bytearray` from device memory starting at `byteoffset`.

Same parameters and behavior as `getbytes()`.

Args:
    byteoffset  Byte offset (0-based).
    bytecount   Count of bytes to read.

Returns:
    `bytearray` with data read from device memory.

See Also:
    getbytes()

◆ getbyteorder()

str mbserver._MemoryBlock.getbyteorder ( self)
Return current byte order as string: 'little' or 'big'.

Note:
    Since v0.4.2

◆ getbytes()

bytes mbserver._MemoryBlock.getbytes ( self,
int byteoffset,
int bytecount )
Function returns `bytes` object from device memory  starting with `byteoffset` and `bytecount` bytes.

For bit memory `byteoffset` is calculated as `bitoffset // 8`.
So bit with offset 0 is in byte with offset 0, bit with offset 8 is in byte with offset 1, etc.
For register memory `byteoffset` is calculated as `offset * 2`.
So register with offset 0 is byte offset 0 and 1, 
register with offset 1 is byte offset 2 and 3, etc.

Args:
    byteoffset  Byte offset (0-based).
    bytecount   Count of bytes to read.

Returns:
    `bytes` object with data read from device memory.

◆ getbytestring()

str mbserver._MemoryBlock.getbytestring ( self,
int byteoffset,
int bytecount )
Return UTF-8 string from memory starting at `byteoffset`.

Args:
    byteoffset  Byte offset (0-based).
    bytecount   Count of bytes to read.

Returns:
    Decoded string value.

Note:
    Since v0.4.2

◆ getid()

int mbserver._MemoryBlock.getid ( self)
Returns id (0, 1, 3 or 4) of the current memory object as integer.

◆ getregisterorder()

str mbserver._MemoryBlock.getregisterorder ( self)
Return current register order as int.

Values:
    -1  default
     0  R0R1R2R3
     1  R3R2R1R0
     2  R1R0R3R2
     3  R2R3R0R1

Note:
    Since v0.4.2

◆ getregstring()

str mbserver._MemoryBlock.getregstring ( self,
int regoffset,
int bytecount )
Return UTF-8 string from register memory starting at `regoffset`.

`regoffset` is specified in 16-bit registers (`byteoffset = regoffset * 2`).

Args:
    regoffset  16-bit register offset (0-based).
    bytecount  Count of bytes to read.

Returns:
    Decoded string value.

Note:
    Since v0.4.2

◆ setbit()

mbserver._MemoryBlock.setbit ( self,
int bitoffset,
bool value )
Set a single bit value (`True` or `False`) at `bitoffset`.

For register memory, `bitoffset = offset * 16`.

Args:
    bitoffset  Bit offset (0-based).
    value      Value to set: `True` or `False`.

Note:
    If `bitoffset` is out of range, does nothing.

◆ setbitbytes()

mbserver._MemoryBlock.setbitbytes ( self,
int bitoffset,
int bitcount,
Union[bytes, bytearray] value )
Write `value` (`bytes` or `bytearray`) into bit memory.

Starts at `bitoffset` and writes `bitcount` bits. For register
memory, `bitoffset = offset * 16`.

Args:
    bitoffset  Bit offset (0-based).
    bitcount   Count of bits to write from `value`.
    value      Array of bytes that contains bits to write.

◆ setbitstring()

mbserver._MemoryBlock.setbitstring ( self,
int bitoffset,
str value )
Write UTF-8 string to bit memory starting at `bitoffset`.

Value is encoded as UTF-8 and written bitwise.

Args:
    bitoffset  Bit offset (0-based).
    value      String value to write.

Note:
    Since v0.4.2

◆ setbytes()

mbserver._MemoryBlock.setbytes ( self,
int byteoffset,
Union[bytes, bytearray] value )
Write `value` (`bytes` or `bytearray`) into device memory.

Starts at `byteoffset`. For bit memory, `byteoffset = bitoffset // 8`.
For register memory, `byteoffset = offset * 2`.

Args:
    byteoffset  Byte offset (0-based).
    value       `bytes` or `bytearray` value to set.

◆ setbytestring()

mbserver._MemoryBlock.setbytestring ( self,
int byteoffset,
str value )
Write UTF-8 string to memory starting at `byteoffset`.

Args:
    byteoffset  Byte offset (0-based).
    value       String value to be written.

Note:
    Since v0.4.2

◆ setregstring()

mbserver._MemoryBlock.setregstring ( self,
int regoffset,
str value )
Write UTF-8 string to register memory starting at `regoffset`.

`regoffset` is specified in 16-bit registers (`byteoffset = regoffset * 2`).

Args:
    regoffset  16-bit register offset (0-based).
    value      String value to be written.

Note:
    Since v0.4.2

The documentation for this class was generated from the following file: