pub struct DalyBMS { /* private fields */ }serialport only.Expand description
The main struct for interacting with a Daly BMS over a serial port.
It handles sending commands and receiving/decoding responses from the BMS.
Most methods require a mutable reference to self as they involve serial communication
and may update internal state (like the last execution time or cached status).
Implementations§
Source§impl DalyBMS
impl DalyBMS
Sourcepub fn new(port: &str) -> Result<Self, Error>
pub fn new(port: &str) -> Result<Self, Error>
Creates a new DalyBMS instance.
§Arguments
port: The path to the serial port device (e.g.,/dev/ttyUSB0on Linux,COM3on Windows).
§Returns
A Result containing the DalyBMS instance or an Error if the serial port
cannot be opened or configured.
§Example
use dalybms_lib::serialport::DalyBMS;
let bms = DalyBMS::new("/dev/ttyUSB0");
if let Ok(mut bms_instance) = bms {
// Use the BMS instance
if let Ok(soc) = bms_instance.get_soc() {
println!("SOC: {}%", soc.soc_percent);
}
} else {
eprintln!("Failed to connect to BMS: {:?}", bms.err());
}Sourcepub fn set_retry(&mut self, n_retries: u8)
pub fn set_retry(&mut self, n_retries: u8)
sets the number of retries for a failed send_bytes operation
Sourcepub fn set_delay(&mut self, delay: Duration)
pub fn set_delay(&mut self, delay: Duration)
Sets the minimum delay between sending commands to the BMS.
If the provided delay is less than MINIMUM_DELAY from the protocol module,
MINIMUM_DELAY will be used.
§Arguments
delay: The desired minimum delay between commands.
Sourcepub fn get_soc(&mut self) -> Result<Soc, Error>
pub fn get_soc(&mut self) -> Result<Soc, Error>
Retrieves the State of Charge (SOC) and other primary battery metrics.
§Returns
A Result containing the Soc data or an Error if the command fails or decoding is unsuccessful.
§Example
let soc_data = bms.get_soc()?;
println!("Voltage: {:.1}V, Current: {:.1}A, SOC: {:.1}%",
soc_data.total_voltage, soc_data.current, soc_data.soc_percent);Sourcepub fn get_cell_voltage_range(&mut self) -> Result<CellVoltageRange, Error>
pub fn get_cell_voltage_range(&mut self) -> Result<CellVoltageRange, Error>
Retrieves the highest and lowest cell voltages in the battery pack.
§Returns
A Result containing the CellVoltageRange data or an Error.
Sourcepub fn get_temperature_range(&mut self) -> Result<TemperatureRange, Error>
pub fn get_temperature_range(&mut self) -> Result<TemperatureRange, Error>
Retrieves the highest and lowest temperatures measured by the BMS.
§Returns
A Result containing the TemperatureRange data or an Error.
Sourcepub fn get_mosfet_status(&mut self) -> Result<MosfetStatus, Error>
pub fn get_mosfet_status(&mut self) -> Result<MosfetStatus, Error>
Retrieves the status of the charging and discharging MOSFETs, and other related data.
§Returns
A Result containing the MosfetStatus data or an Error.
Sourcepub fn get_status(&mut self) -> Result<Status, Error>
pub fn get_status(&mut self) -> Result<Status, Error>
Retrieves general status information from the BMS, including cell count and temperature sensor count.
This method also caches the retrieved status internally, as this information is
required by other methods like get_cell_voltages and get_cell_temperatures.
It’s recommended to call this method at least once before calling those methods.
§Returns
A Result containing the Status data or an Error.
Sourcepub fn get_cell_voltages(&mut self) -> Result<CellVoltages, Error>
pub fn get_cell_voltages(&mut self) -> Result<CellVoltages, Error>
Retrieves the voltage of each individual cell in the battery pack.
Note: get_status() must be called at least once before this method
to determine the number of cells.
§Returns
A Result containing a CellVoltages of cell voltages or an Error.
Returns Error::StatusError if get_status() was not called previously.
Sourcepub fn get_cell_temperatures(&mut self) -> Result<Vec<i32>, Error>
pub fn get_cell_temperatures(&mut self) -> Result<Vec<i32>, Error>
Retrieves the temperature from each individual temperature sensor.
Note: get_status() must be called at least once before this method
to determine the number of temperature sensors.
§Returns
A Result containing a Vec<i32> of temperatures in Celsius or an Error.
Returns Error::StatusError if get_status() was not called previously.
Sourcepub fn get_balancing_status(&mut self) -> Result<Vec<bool>, Error>
pub fn get_balancing_status(&mut self) -> Result<Vec<bool>, Error>
Retrieves the balancing status of each individual cell.
Note: get_status() must be called at least once before this method
to determine the number of cells.
§Returns
A Result containing a Vec<bool> where true indicates the cell is currently balancing,
or an Error. Returns Error::StatusError if get_status() was not called previously.
Sourcepub fn get_errors(&mut self) -> Result<Vec<ErrorCode>, Error>
pub fn get_errors(&mut self) -> Result<Vec<ErrorCode>, Error>
Retrieves a list of active error codes from the BMS.
§Returns
A Result containing a Vec<ErrorCode> of active errors or an Error.
An empty vector means no errors are currently active.