### Run D-Bus Service Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Execute the vedbusservice_example.py script to demonstrate publishing data on the D-Bus. This example shows how to export a service and its associated data. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ python vedbusservice_example.py vedbusservice_example.py starting up /Position value is 5 /Position value is now 10 ``` -------------------------------- ### Enum with `start` Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to use the `start` parameter to specify the starting value for the first enum member. ```python --> class Count(Enum, start=11): ... eleven ... twelve ... --> Count.twelve.value == 12 True ``` -------------------------------- ### Install dbus-serialbattery GUIv2 Web Version Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_dbus-serialbattery_gui-v2/README.md Run this script to install the web version of the dbus-serialbattery GUIv2. Ensure you select the correct Venus OS version if downloading manually. ```bash wget -O - https://raw.githubusercontent.com/mr-manuel/venus-os_dbus-serialbattery_gui-v2/master/install-new-webgui.sh | bash ``` -------------------------------- ### Install overlay-fs Script Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_overlay-fs/README.md These commands download and execute the installation script for overlay-fs. Ensure you have root access via SSH to your Venus OS device before running. ```bash wget -O /tmp/install_overlay-fs.sh https://raw.githubusercontent.com/mr-manuel/venus-os_overlay-fs/master/install.sh bash /tmp/install_overlay-fs.sh ``` -------------------------------- ### Example Modbus RTU FC 0x03 Read for Device Info Registers Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/bms-docs/JKBMS-PB.md Example of reading 10 device information registers (starting from 0x1400) using Modbus RTU FC 0x03. The response contains device identification strings. ```text 01 03 1400 000A crc → response 01 03 14 4a4b5f504232... — 10 about registers ("JK_PB2A16S20P...15A") ``` -------------------------------- ### Auto-Numbering Enum with Start Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates using `start=1` to enable auto-numbering for enum members. This assigns sequential numbers starting from the specified value. ```python >>> class Color(Enum, start=1): # doctest: +SKIP ... red, green, blue ... >>> Color.blue ``` -------------------------------- ### Planet Enum Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Illustrates the Planet enumeration, showing how values are passed to __new__ or __init__ methods if they are defined within the enumeration class. ```python class Planet(Enum): ``` -------------------------------- ### Flag Enumeration Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates the basic usage of Flag enumerations, including bitwise operations and boolean evaluation. ```python >>> from aenum import Flag, auto >>> class Color(Flag): ... RED = auto() ... BLUE = auto() ... GREEN = auto() ... >>> Color.RED & Color.GREEN >>> bool(Color.RED & Color.GREEN) False ``` -------------------------------- ### Configure and Enable Daly CAN Simulator Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/test/README.md Add the virtual CAN port to the configuration file and run the enable script to start the simulator as a service. This method is suitable for persistent configurations. ```ini CAN_PORT = vcan0 BATTERY_ADDRESSES = BMS_TYPE = Daly_Can ``` ```bash ./enable.sh ``` -------------------------------- ### Run Daly CAN Simulator Manually Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/test/README.md Execute the Python script directly to start the simulator on the specified virtual CAN port. Ensure you are in the correct directory. ```bash cd /data/apps/dbus-serialbattery ./dbus-serialbattery.py vcan0 ``` -------------------------------- ### extend_enum Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Illustrates how to add new members to an Enum after its initial creation using the 'extend_enum' function. ```python >>> from aenum import extend_enum >>> class Color(Enum): ... ``` -------------------------------- ### Custom Enum Subclass Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to create a custom Enum subclass by mixing in other types, like 'int'. ```python class MyIntEnum(int, Enum): pass ``` -------------------------------- ### Example Modbus RTU FC 0x03 Read for Status Registers Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/bms-docs/JKBMS-PB.md Example of reading 10 status registers (starting from 0x1200) using Modbus RTU FC 0x03. The response contains cell voltages in mV. ```text 01 03 1200 000A crc → response 01 03 14 0d0d 0d0e 0d0d... — 10 status registers (cell voltages in mV, big-endian) ``` -------------------------------- ### Planet Enum Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Defines an Enum for planets with mass and radius, including a computed surface gravity property. Accessing enum values and properties is demonstrated. ```python MERCURY = (3.303e+23, 2.4397e6) VENUS = (4.869e+24, 6.0518e6) EARTH = (5.976e+24, 6.37814e6) MARS = (6.421e+23, 3.3972e6) JUPITER = (1.9e+27, 7.1492e7) SATURN = (5.688e+26, 6.0268e7) URANUS = (8.686e+25, 2.5559e7) NEPTUNE = (1.024e+26, 2.4746e7) def __init__(self, mass, radius): self.mass = mass # in kilograms self.radius = radius # in meters @property def surface_gravity(self): # universal gravitational constant (m3 kg-1 s-2) G = 6.67300E-11 return G * self.mass / (self.radius * self.radius) ``` ```python Planet.EARTH.value ``` ```python Planet.EARTH.surface_gravity ``` -------------------------------- ### Example Modbus RTU FC 0x03 Read with Address Filtering Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/bms-docs/JKBMS-PB.md Demonstrates Modbus RTU FC 0x03 read targeting address 0x04, confirming address filtering works as expected. ```text 04 03 1200 000A crc → response from addr 0x04, cells=[3341,3341,...] (correct address filtering confirmed) ``` -------------------------------- ### AutoNumber Enumeration Example Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates the AutoNumber enumeration, which automatically assigns sequential integer values to members without explicit assignment. This is useful for simple counters. ```python class AutoNumber(Enum): def __new__(cls): value = len(cls.__members__) + 1 obj = object.__new__(cls) obj._value_ = value return obj ``` ```python class Color(AutoNumber): _order_ = "red green blue" # only needed in 2.x red = () green = () blue = () ``` ```python Color.green.value == 2 ``` -------------------------------- ### Inspect a Specific D-Bus Service Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Get a detailed list of object paths exported by a specific D-Bus service. This helps in understanding the structure and available data within a service. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ dbus com.victronenergy.example / /Float /Int /NegativeInt /Position /RPM /String ``` -------------------------------- ### Defining Custom Behavior in Enums Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Enums can have methods and special methods. This example shows a describe method and a class method favorite_mood. ```python >>> class Mood(Enum): ... funky = 1 ... happy = 3 ... ... def describe(self): ... # self is the member here ... return self.name, self.value ... ... def __str__(self): ... return 'my custom str! {0}'.format(self.value) ... ... @classmethod ... def favorite_mood(cls): ... # cls here is the enumeration ... return cls.happy ... ``` ```python >>> Mood.favorite_mood() >>> Mood.happy.describe() ('happy', 3) >>> str(Mood.funky) 'my custom str! 1' ``` -------------------------------- ### Modify D-Bus Service Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Change the value of a D-Bus item from the command line using dbus-send. This example demonstrates setting the /RPM value, with feedback on acceptance. ```bash dbus-send --print-reply --dest=com.victronenergy.example /RPM com.victronenergy.BusItem.SetValue int32:1200 ``` -------------------------------- ### Enable Overlay Filesystem Mount Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_overlay-fs/README.md Execute this command to enable the overlay-fs mount on boot. It will mount all configured overlays, making your persistent changes active. ```bash bash /data/etc/overlay-fs/enable.sh ``` -------------------------------- ### Initialize standalone_serialbattery Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/standalone_README.md Import the library and create an instance of the standalone_serialbattery class. Specify the device path, driver option, Bluetooth address (if applicable), and log level. ```python from standalone_serialbattery import * sasb = standalone_serialbattery(DEVPATH, 0, "", LOGLEVEL) ``` -------------------------------- ### Enum Helper for Initialization Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates using the 'enum' helper to initialize Enum members with multiple values using keyword arguments. ```python >>> from aenum import enum >>> class Presidents(Enum): ... Washington = enum('George Washington', circa=1776, death=1797) ... Jackson = enum('Andrew Jackson', circa=1830, death=1837) ... Lincoln = enum('Abraham Lincoln', circa=1860, death=1865) ... >>> Presidents.Lincoln ``` -------------------------------- ### Enum Initialization with `_init_` (Python 2) Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to use `_init_ = 'db user'` in Python 2 for enum initialization, similar to the `init` keyword argument in Python 3. ```python >>> from aenum import Enum >>> class SelectionEnum(Enum): ... _init_ = 'db user' ... def __new__(cls, *args, **kwds): ... count = len(cls.__members__) ... obj = object.__new__(cls) ... obj._count = count ... obj._value_ = args ... return obj ... @staticmethod ... def _generate_next_value_(name, start, count, values, *args, **kwds): ... return (name, ) + args ... >>> class NotificationType(SelectionEnum): ... # usually, name is the same as db ... # but not for blanks ... blank = '', '' ... C = 'Catalog' ... S = 'Sheet' ... B = 'Both' ... >>> NotificationType.blank >>> NotificationType.B >>> NotificationType.B.db 'B' >>> NotificationType.B.user 'Both' ``` -------------------------------- ### Add App-Directory Combination for Overlay Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_overlay-fs/README.md Use this command to specify a directory that should be overlaid for a particular app. This ensures changes to the directory are isolated to that app's overlay. ```bash bash /data/apps/overlay-fs/add-app-and-directory.sh ``` ```bash bash /data/apps/overlay-fs/add-app-and-directory.sh custom-web-app /var/www/venus ``` -------------------------------- ### Enum with `init` for Attribute Initialization Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates using the `init` parameter to specify attribute names for storing creation values. ```python --> class Planet(Enum, init='mass radius'): ... MERCURY = (3.303e+23, 2.4397e6) ... EARTH = (5.976e+24, 6.37814e6) ... --> Planet.EARTH.value (5.976e+24, 6378140.0) --> Planet.EARTH.radius 2.4397e6 ``` -------------------------------- ### Dynamic Enum Creation with Settings Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates dynamic creation of an Enum class using `vars()` and applying settings like `NoAlias` and `_init_` for custom initialization. The `_ignore_` attribute prevents specified names from appearing in the final enumeration. ```python from datetime import timedelta from aenum import NoAlias class Period(timedelta, Enum): ''' different lengths of time ''' _init_ = 'value period' _settings_ = NoAlias _ignore_ = 'Period i' Period = vars() for i in range(31): Period['day_%d' % i] = i, 'day' for i in range(15): Period['week_%d' % i] = i*7, 'week' ``` ```python hasattr(Period, '_ignore_') ``` ```python hasattr(Period, 'Period') ``` ```python hasattr(Period, 'i') ``` -------------------------------- ### Enum Initialization with `init` Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates using `init='mass radius'` to automatically create an `__init__` method that assigns the provided arguments to instance attributes. This is useful for enums where members have associated data. ```python >>> from aenum import Enum, constant, init >>> class Planet(Enum, init='mass radius'): # doctest: +SKIP ... MERCURY = (3.303e+23, 2.4397e6) ... EARTH = (5.976e+24, 6.37814e6) ... JUPITER = (1.9e+27, 7.1492e7) ... URANUS = (8.686e+25, 2.5559e7) ... G = constant(6.67300E-11) ... @property ... def surface_gravity(self): ... # universal gravitational constant (m3 kg-1 s-2) ... return self.G * self.mass / (self.radius * self.radius) ... >>> Planet.JUPITER.value (1.9e+27, 71492000.0) >>> Planet.JUPITER.mass 1.9e+27 ``` -------------------------------- ### Get D-Bus Item Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Retrieve the current value of a specific D-Bus item using the 'GetValue' method. This is useful for inspecting data exported by services. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ dbus com.victronenergy.example /RPM GetValue 100 ``` -------------------------------- ### Advanced Enum Class Syntax with Settings Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates advanced class syntax for creating enums with settings like `AddValue`, `MultiValue`, `NoAlias`, and `Unique`. ```python --> class Color( ... Enum, ... settings=(AddValue, MultiValue, NoAlias, Unique), ... init='field_name1 field_name2 ...', ... start=7, ... ) ... ``` -------------------------------- ### List Available D-Bus Services Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Query the D-Bus system to list all active services. This command helps in identifying available services and their names. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ dbus org.freedesktop.DBus org.freedesktop.PowerManagement com.victronenergy.example org.xfce.Terminal5 org.xfce.Xfconf [and many more services in which we are not interested] ``` -------------------------------- ### Create Enum with Functional API Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Use the Enum class as a function to create enumerations. The second argument can be a whitespace-separated string of names, a sequence of names, a sequence of 2-tuples, or a mapping. Values are auto-assigned integers starting from 1 unless specified. ```python >>> Animal = Enum('Animal', 'ant bee cat dog') >>> Animal >>> Animal.ant >>> Animal.ant.value 1 >>> list(Animal) [, , , ] ``` -------------------------------- ### Configure Custom Serial Port with Socat Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/bms-docs/JKBMS-PB.md Use this script to set up a custom serial port (e.g., via a network bridge) for the dbus-serialbattery driver. It creates a PTY, registers a service entry, and ensures persistence across reboots. ```shell # 1. Create the PTY (example: Waveshare RS485↔TCP server at :) socat -d pty,link=/dev/ttyV0,raw,echo=0,b115200,user=root,group=dialout,mode=0660 \ tcp:: & # 2. Create a permanent service entry under /data/ PORT=ttyV0 SVC=/data/etc/dbus-serialbattery-custom/dbus-serialbattery.$PORT mkdir -p "$SVC/log" cp /data/apps/dbus-serialbattery/service/run "$SVC/run" cp /data/apps/dbus-serialbattery/service/log/run "$SVC/log/run" ln -sf "$SVC" "/service/dbus-serialbattery.$PORT" # 3. Persist across reboot (Venus wipes /service/ symlinks) echo "ln -sf $SVC /service/dbus-serialbattery.$PORT" >> /data/rc.local ``` -------------------------------- ### Configure Git for Tab Size Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Configure git diff to display tabs as 4 spaces for consistent code viewing. Use --local for current repository or --global for all repositories. ```bash git config --local core.pager 'less -x4' ``` -------------------------------- ### Auto-Numbering Enum with _start_ Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows an alternative method for auto-numbering using `_start_ = 1` and `auto()`, which is compatible with both Python 2 and 3. ```python >>> from aenum import auto >>> class Color(Enum): # doctest: +SKIP ... _start_ = 1 ... red = auto() ... green = auto() ... blue = auto() ... >>> Color.blue ``` -------------------------------- ### Instantiate a NamedTuple with positional and keyword arguments Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Instances of a NamedTuple can be created using positional arguments, keyword arguments, or a combination of both. Ensure all fields are provided. ```python b1 = Book('Lord of the Rings', 'J.R.R. Tolkien', 'fantasy') b2 = Book(title='Jhereg', author='Steven Brust', genre='fantasy') b3 = Book('Empire', 'Orson Scott Card', genre='scifi') ``` -------------------------------- ### Create Virtual CAN Port (vcan0) Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/test/README.md Use these commands to add and configure a virtual CAN interface named vcan0. This is necessary for simulating CAN bus traffic. ```bash ip link add dev vcan0 type vcan ip link set vcan0 down ip link set vcan0 mtu 16 ip link set vcan0 up ``` -------------------------------- ### Create a NamedTuple instance using _make() Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst The `_make()` class method creates a new instance of a NamedTuple from an iterable of values. This is an alternative to direct instantiation. ```python Point._make((4, 5)) ``` -------------------------------- ### Subclassing a NamedTuple and Managing Fields Manually Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Illustrates subclassing a NamedTuple and manually defining fields with default values and docstrings. Field numbering must be managed explicitly. ```python Point = NamedTuple('Point', 'x y') class Pixel(Point): r = 2, 'red component', 11 g = 3, 'green component', 29 b = 4, 'blue component', 37 Pixel.__fields__ ``` -------------------------------- ### Uninstall overlay-fs Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_overlay-fs/README.md This command completely removes overlay-fs from the system. It disables the mount on boot, unmounts active overlays, restores the previous state, and deletes all associated files. ```bash bash /data/etc/overlay-fs/unenable.sh ``` -------------------------------- ### Remove App and its Overlays Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_overlay-fs/README.md This command removes an app and any associated overlay filesystems it uses. Overlays are only removed if no other apps are currently using them. ```bash bash /data/apps/overlay-fs/remove-app.sh ``` ```bash bash /data/apps/overlay-fs/remove-app.sh custom-web-app ``` -------------------------------- ### Enum Type and Instance Check Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates how to check the type of an enum member and if an object is an instance of an enum. ```python >>> type(Color.red) >>> isinstance(Color.green, Color) True ``` -------------------------------- ### Programmatic Enum Member Access by Name Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates accessing enum members by their names using item access. ```python >>> Color['red'] >>> Color['green'] ``` -------------------------------- ### Define Enum with Constants Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to define an enum with both regular members and constants using `aenum.constant`. Constants cannot be rebound after initialization. ```python >>> from aenum import constant >>> class Planet(Enum): ... MERCURY = (3.303e+23, 2.4397e6) ... EARTH = (5.976e+24, 6.37814e6) ... JUPITER = (1.9e+27, 7.1492e7) ... URANUS = (8.686e+25, 2.5559e7) ... G = constant(6.67300E-11) ... def __init__(self, mass, radius): ... self.mass = mass # in kilograms ... self.radius = radius # in meters ... @property ... def surface_gravity(self): ... # universal gravitational constant (m3 kg-1 s-2) ... return self.G * self.mass / (self.radius * self.radius) ... >>> Planet.EARTH.value (5.976e+24, 6378140.0) >>> Planet.EARTH.surface_gravity 9.802652743337129 >>> Planet.G 6.673e-11 >>> Planet.G = 9 Traceback (most recent call last): ...AttributeError: Planet: cannot rebind constant 'G' ``` -------------------------------- ### Check Code Style with pep8 Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Verify Python code against PEP8 standards, enforcing a maximum line length of 110 characters and ignoring tab width warnings. ```bash pep8 --max-line-length=110 --ignore=W191 *.py ``` -------------------------------- ### Disable Overlay Filesystem Mount Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/venus-os_overlay-fs/README.md Run this command to disable the overlay-fs mount on boot. It unmounts any active overlays and restores the system to its state before enabling overlays. ```bash bash /data/etc/overlay-fs/disable.sh ``` -------------------------------- ### Flag Enumeration with Combined Members Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to define combined members in a Flag enumeration and their resulting values. ```python --> class Color(Flag): ... RED = auto() ... BLUE = auto() ... GREEN = auto() ... WHITE = RED | BLUE | GREEN ... --> Color.WHITE ``` -------------------------------- ### Introspect D-Bus Object Interfaces Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Examine the interfaces and methods supported by a D-Bus object. This command helps in understanding how to interact with a specific D-Bus service. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ dbus com.victronenergy.example /RPM Interface org.freedesktop.DBus: String Introspect() Interface com.victronenergy.BusItem: Int32 SetValue(Variant newvalue) String GetDescription(String language, Int32 length) String GetText() Variant GetValue() ``` -------------------------------- ### Iterating Over Flag Members Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates how to iterate over a Flag enumeration to retrieve individual truthy flags. ```python >>> class Color(Flag): ... _order_ = 'BLACK RED BLUE GREEN WHITE' ... BLACK = 0 ... RED = auto() ... BLUE = auto() ... GREEN = auto() ... WHITE = RED | BLUE | GREEN ... >>> list(Color.GREEN) [] >>> list(Color.WHITE) [, , ] ``` -------------------------------- ### Create an Enum using Class Syntax Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Define an enumeration by subclassing Enum. Members have names and values. Use this for creating sets of symbolic names bound to unique, constant values. ```python from aenum import Enum class Color(Enum): red = 1 green = 2 blue = 3 ``` -------------------------------- ### Creating a NamedTuple with Variable Tuple Size Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates how to define a NamedTuple where the number of fields can vary. Use TupleSize.variable to allow for flexible field assignments. ```python from aenum import NamedTuple, TupleSize class Person(NamedTuple): _size_ = TupleSize.variable first = 0 last = 1 Person('Ethan') Person(last='Furman') ``` -------------------------------- ### Enum Class Membership Check Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates how Enum classes support membership testing using the 'in' operator. ```python list(Color) ``` ```python some_var in Color ``` -------------------------------- ### Duplicate Enum Member Name Handling (Python 2) Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how Python 2.x handles duplicate member names by overwriting the earlier definition. ```python # python 2.x --> class Shape(Enum): ... square = 2 ... square = 3 ... --> Shape.square ``` -------------------------------- ### Naming IntFlag Combinations Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst It is possible to name specific combinations of IntFlag members, such as defining a 'RWX' member for the combination of R, W, and X. ```python >>> class Perm(IntFlag): ... _order_ = 'R W X' ... R = 4 ... W = 2 ... X = 1 ... RWX = 7 >>> Perm.RWX >>> ~Perm.RWX ``` -------------------------------- ### Open BMS Connection and Read Data Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/standalone_README.md Use bms_open() to establish a connection to the BMS and bms_read() to retrieve the latest data. The read data can be accessed directly via object attributes or as a list. ```python sasb.bms_open() ST = sasb.bms_read() ``` -------------------------------- ### Attempt to Set Invalid D-Bus Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Demonstrates setting an unsupported value to a D-Bus item and observing the error code returned. A return value other than 0 indicates failure. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ dbus com.victronenergy.example /RPM SetValue %2000 2 ``` -------------------------------- ### Check Simulator Log Output Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/test/README.md Monitor the log file for the simulator to verify its operation and troubleshoot any issues. The `tai64nlocal` command converts timestamps for readability. ```bash tail -f /var/log/dbus-canbattery.vcan0/current | tai64nlocal ``` -------------------------------- ### Extend Enum with New Member Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates extending an existing enum with a new member using the `extend_enum` function. Shows how to check for membership and access properties of the new member. ```python >>> from aenum import Enum, extend_enum >>> class Color(Enum): ... red = 1 ... green = 2 ... blue = 3 ... >>> list(Color) [, , ] >>> extend_enum(Color, 'opacity', 4) >>> list(Color) [, , , ] >>> Color.opacity in Color True >>> Color.opacity.name == 'opacity' True >>> Color.opacity.value == 4 True >>> Color(4) >>> Color['opacity'] --> Color.__members__ OrderedDict([ ('red', ), ('green', ), ('blue', ), ('opacity', ) ]) ``` -------------------------------- ### Configure NamedTuple size with TupleSize.minimum Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Set `_size_ = TupleSize.minimum` to allow for more fields than explicitly named. This is useful when the last few fields are optional or not always provided. ```python from aenum import TupleSize class Person(NamedTuple): _size_ = TupleSize.minimum first = 0 last = 1 Person('Ethan', 'Furman') Person('Ethan', 'Furman', 'ethan.furman') Person('Ethan', 'Furman', 'ethan.furman', 'yay Python!') ``` -------------------------------- ### Programmatic Enum Member Access by Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to access enum members programmatically using their values. ```python >>> Color(1) >>> Color(3) ``` -------------------------------- ### NamedTuple with fields containing docstrings and default values Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Fields can include docstrings and default values. This allows for more flexible instantiation, including calling the NamedTuple with no arguments if all fields have defaults. ```python class Point(NamedTuple): x = 0, 'horizontal coordinate', 0 y = 1, 'vertical coordinate', 0 Point() Point(1) Point(y=2) ``` -------------------------------- ### IntEnum Comparison with Standard Enum Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates that IntEnum members cannot be compared to standard Enum members, even if their values are the same. ```python >>> class Shape(IntEnum): ... circle = 1 ... square = 2 ... >>> class Color(Enum): ... red = 1 ... green = 2 ... >>> Shape.circle == Color.red False ``` -------------------------------- ### Accessing Enum Member Name and Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Illustrates how to retrieve the `name` and `value` attributes of an enum member. ```python >>> member = Color.red >>> member.name 'red' >>> member.value 1 ``` -------------------------------- ### IntFlag Bitwise Operations Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst IntFlag members support bitwise operations (&, |, ^, ~), and the results remain IntFlag members. Standard addition results in an integer. ```python >>> from aenum import IntFlag >>> class Perm(IntFlag): ... _order_ = 'R W X' ... R = 4 ... W = 2 ... X = 1 ... >>> Perm.R | Perm.W >>> Perm.R + Perm.W 6 >>> RW = Perm.R | Perm.W >>> Perm.R in RW True ``` -------------------------------- ### Iterating Over Enum Members Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates iterating over enum members. Note that aliases are not included in this direct iteration. ```python >>> list(Shape) [, , ] ``` -------------------------------- ### Access BMS Data via List Index Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/standalone_README.md Alternatively, access BMS data as a list where specific indices correspond to different parameters such as cell count, cell voltages, temperatures, battery voltage, current, and state of charge. ```python ST[0] = cellcount ST[1] = Cellvoltage of cell 1 ST[0..cellcount] = Cellvoltage of cell x ST[cellcount + 1] = Temperature_Fet ST[cellcount + 2] = Temperature_1 ST[cellcount + 3] = Temperature_2 ST[cellcount + 4] = BatVolt ST[cellcount + 5] = Current ST[cellcount + 6] = SOC ``` -------------------------------- ### Creating a NamedTuple by Concatenating Existing NamedTuples Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Shows how to create a new NamedTuple by combining fields from existing NamedTuple classes. Field numbering is automatically adjusted. ```python Point = NamedTuple('Point', 'x y') Color = NamedTuple('Color', 'r g b') Pixel = NamedTuple('Pixel', Point+Color, module=__name__) Pixel ``` -------------------------------- ### Set D-Bus Item Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/velib_python/README.md Set the value of a D-Bus item from the command line. The '%' symbol ensures the value is interpreted as an integer. ```bash matthijs@matthijs-VirtualBox:~/dev/velib_python/examples$ dbus com.victronenergy.example /RPM SetValue %1 0 ``` -------------------------------- ### Enum Member Hashing Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Illustrates that enum members are hashable and can be used as dictionary keys or set elements. ```python >>> apples = {} >>> apples[Color.red] = 'red delicious' >>> apples[Color.green] = 'granny smith' >>> apples == {Color.red: 'red delicious', Color.green: 'granny smith'} True ``` -------------------------------- ### Create a NamedTuple using the functional API Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Use the functional API to create a NamedTuple with specified fields. The `module` argument is set to `__name__` for proper module association. ```python from aenum import NamedTuple Book = NamedTuple('Book', 'title author genre', module=__name__) ``` -------------------------------- ### Enum with Aliases for Same Value Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Illustrates how multiple enum members can share the same value, with later members becoming aliases of the first. ```python >>> class Shape(Enum): ... _order_ = 'square diamond circle' # needed in 2.x ... square = 2 ... diamond = 1 ... circle = 3 ... alias_for_square = 2 ... >>> Shape.square >>> Shape.alias_for_square >>> Shape(2) ``` -------------------------------- ### Allowed Enum Subclassing Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst This demonstrates allowed subclassing where the base enum does not define members, allowing for shared behavior. ```python >>> class Foo(Enum): ... def some_behavior(self): ... pass ... >>> class Bar(Foo): ... happy = 1 ... sad = 2 ... ``` -------------------------------- ### NamedTuple instantiation with insufficient arguments Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Providing too few arguments during NamedTuple instantiation will raise a TypeError, indicating which fields are missing values. ```python b4 = Book('Hidden Empire') Traceback (most recent call last): ... TypeError: values not provided for field(s): author, genre b5 = Book(genre='business') Traceback (most recent call last): ... TypeError: values not provided for field(s): title, author ``` -------------------------------- ### Temperature Encoding Logic Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/bms-docs/JKBMS-PB.md This Python code snippet decodes raw temperature readings from JKBMS. It handles both positive and negative Celsius values based on the raw integer representation. ```python raw = unpack_from(">> class Shake(Enum): ... _order_ = 'vanilla chocolate cookies mint' # only needed in 2.x ... vanilla = 7 ... chocolate = 4 ... cookies = 9 ... mint = 3 ... >>> for shake in Shake: ... print(shake) ... Shake.vanilla Shake.chocolate Shake.cookies Shake.mint ``` -------------------------------- ### Duplicate Enum Member Name Handling (Python 3) Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Demonstrates that Python 3.x raises a `TypeError` when attempting to reuse a member name in an enum. ```python # python 3.x --> class Shape(Enum): ... square = 2 ... square = 3 ...Traceback (most recent call last): ...TypeError: Attempted to reuse key: 'square' ``` -------------------------------- ### Access BMS Data via Object Attributes Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/standalone_README.md Directly access various BMS parameters like cell count, individual cell voltages, temperatures, battery voltage, current, and state of charge using object attributes. ```python sasb.cell_count sasb.cells[Nr_of_Cell] sasb.temperature_fet sasb.temperature_1 sasb.temperature_2 sasb.voltage sasb.act_current sasb.soc ``` -------------------------------- ### Specify Module for Pickling Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst When pickling enums created with the functional API, explicitly specify the module name using the 'module' argument to avoid issues with frame stack implementation details, especially when using utility functions in separate modules. ```python >>> Animals = Enum('Animals', 'ant bee cat dog', module=__name__) ``` -------------------------------- ### Access NamedTuple data using _asdict() Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst The `_asdict()` method converts a NamedTuple instance into an OrderedDict, mapping field names to their values. ```python pixel._asdict() # doctest: +SKIP # OrderedDict([('x', 99), ('y', -101), ('r', 255), ('g', 128), ('b', 0)]) ``` -------------------------------- ### Enum Member Identity Comparison Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst Enumeration members are compared by identity. Use 'is' or 'is not' for comparisons. ```python >>> Color.red is Color.red True >>> Color.red is Color.blue False >>> Color.red is not Color.blue True ``` -------------------------------- ### Create a NamedTuple with named and unnamed fields Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst It's possible to create NamedTuples where only some fields have names. Unnamed fields can still be accessed by index. ```python class Person(NamedTuple): fullname = 2 phone = 5 p = Person('Ethan', 'Furman', 'Ethan Furman', 'ethan at stoneleaf dot us', 'ethan.furman', '999.555.1212') p.fullname p.phone p[0] ``` -------------------------------- ### Define a NamedTuple using class syntax Source: https://github.com/mr-manuel/venus-os_dbus-serialbattery/blob/master/dbus-serialbattery/ext/aenum/doc/aenum.rst A NamedTuple can also be defined using class syntax, where fields are assigned integer values corresponding to their index. ```python class Book(NamedTuple): title = 0 author = 1 genre = 2 ```