Daly BMS
This RUST project can read and write a Daly BMS module from the command line.
Compilation
- Install Rust e.g. using these instructions.
- Ensure that you have a C compiler and linker.
- Clone
git clone https://github.com/acpiccolo/Daly-BMS.git - Run
cargo install --path .to install the binary. Alternatively, check out the repository and runcargo build --release. This will compile the binary totarget/release/dalybms.
Getting started
The dalybms command-line tool allows you to interact with your Daly BMS from the terminal.
Basic Help
To see all available commands and options:
To get help for a specific subcommand, for example set-soc:
CLI Examples
Here are some examples of how to use the dalybms tool. Replace /dev/ttyUSB0 with the actual serial port your BMS is connected to, if different.
1. Fetching Basic Information
-
Get State of Charge (SOC), total voltage, and current:
(Output will be similar to:
SOC: Soc { total_voltage: 53.6, current: -0.0, soc_percent: 87.5 }) -
Get general status information (number of cells, temperature sensors, charger/load status, cycles):
(Assumes default device or you can specify
--device) -
Get MOSFET status (mode, charging/discharging MOSFET state, BMS cycles, capacity):
-
Get cell voltage range (highest/lowest cell voltage and which cell):
-
Get temperature range (highest/lowest temperature and which sensor):
-
Get current error codes:
(Output will be like:
Errors: []if no errors, or show a list of active errors)
2. Fetching Detailed Information
Important: For commands like cell-voltages, cell-temperatures, and balancing, the BMS needs to know the number of cells/sensors. The dalybms tool automatically calls status first if you haven't, but it's good practice to be aware of this.
-
Get individual cell voltages:
-
Get individual cell/temperature sensor readings:
-
Get cell balancing status (shows which cells are currently being balanced):
3. Setting Values and Controlling MOSFETs
-
Set the State of Charge (SOC) to 80.5%:
-
Enable the discharge MOSFET:
-
Disable the discharge MOSFET:
-
Enable the charge MOSFET:
-
Disable the charge MOSFET:
4. Fetching All Information
- Get all available information from the BMS (runs most of the read commands sequentially):
(This is very useful for a quick overview.)
5. Specifying Connection Parameters
-
Use a different serial device:
-
Change the communication timeout (e.g., to 1 second):
-
Change the delay between commands (e.g., to 100 milliseconds):
(Useful if you experience communication issues with the default delay.)
6. Resetting the BMS
- Reset the BMS to factory defaults (Use with extreme caution!):
These examples should help you get started with using the dalybms command-line tool. Always refer to dalybms --help and dalybms <subcommand> --help for the most up-to-date options and parameters.
Library Usage
This crate can also be used as a library (dalybms_lib) to interact with Daly BMS programmatically from your own Rust projects.
Adding as a Dependency
To use dalybms_lib, add it to your Cargo.toml. Replace "x.y.z" with the desired version of dalybms_lib:
[]
# For the synchronous client:
= { = "x.y.z", = ["serialport"] }
# For the asynchronous client:
# dalybms_lib = { version = "x.y.z", features = ["tokio-serial-async"] }
# For both clients:
# dalybms_lib = { version = "x.y.z", features = ["serialport", "tokio-serial-async"] }
You need to specify which client(s) you intend to use via feature flags:
serialport: For the synchronous client.tokio-serial-async: For the asynchronous Tokio-based client.
You can enable both if needed: features = ["serialport", "tokio-serial-async"]
Synchronous Client Example
The synchronous client uses the serialport crate.
Feature flag required: serialport
use DalyBMS;
use Duration;
Asynchronous Client Example
The asynchronous client uses tokio and tokio-serial.
Feature flag required: tokio-serial-async
use DalyBMS;
use Duration;
async
Cargo Features
This crate (dalybms_lib) uses feature flags to manage optional dependencies and client implementations. This allows users to compile only the parts they need.
| Feature | Purpose | Client Enabled | Default |
|---|---|---|---|
serialport |
Enables the synchronous client using the serialport crate. |
Synchronous | No |
tokio-serial-async |
Enables the asynchronous client using tokio and tokio-serial. |
Asynchronous | No |
serde |
Enables serde support for serializing/deserializing data structures. |
Both (if enabled) | No |
bin-dependencies |
Enables all features required by the dalybms binary executable. |
serialport |
Yes (for dalybms binary target) |
Notes on Features:
- When using
dalybms_libas a library, you should explicitly enableserialportand/ortokio-serial-asyncdepending on your needs. - The
serdefeature can be combined with either client feature if you need serialization capabilities (e.g.,features = ["serialport", "serde"]). - The
defaultfeature for thedalybmscrate as a whole isbin-dependencies. However, fordalybms_libwhen used as a dependency, no client features are enabled by default. - The
bin-dependenciesfeature enablesserialportbecause thedalybmscommand-line tool currently uses the synchronous client.
Protocol Details
For those interested in the low-level communication details, the Daly BMS UART/RS485 communication protocol specification (version 1.2) is available in the repository at docs/Daly UART_485 Communications Protocol V1.2.pdf.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.