|
mbserver 0.5.0
|


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) | |
Base class for the memory objects mem0x, mem1x, mem3x, mem4x. Class is abstract (can't be used directly).
| 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`.
| 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()
| 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.
| 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
| 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()
| str mbserver._MemoryBlock.getbyteorder | ( | self | ) |
Return current byte order as string: 'little' or 'big'.
Note:
Since v0.4.2
| 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.
| 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
| int mbserver._MemoryBlock.getid | ( | self | ) |
Returns id (0, 1, 3 or 4) of the current memory object as integer.
| 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
| 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
| 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.
| 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.
| 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
| 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.
| 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
| 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