pub struct VoltageCurrentBricklet { /* private fields */ }
Expand description
Measures power, DC voltage and DC current up to 720W/36V/20A
Implementations
sourceimpl VoltageCurrentBricklet
impl VoltageCurrentBricklet
pub const DEVICE_IDENTIFIER: u16 = 227u16
pub const DEVICE_DISPLAY_NAME: &'static str = "Voltage/Current Bricklet"
sourcepub fn new(uid: &str, ip_connection: &IpConnection) -> VoltageCurrentBricklet
pub fn new(uid: &str, ip_connection: &IpConnection) -> VoltageCurrentBricklet
Creates an object with the unique device ID uid
. This object can then be used after the IP Connection ip_connection
is connected.
sourcepub fn get_response_expected(
&mut self,
fun: VoltageCurrentBrickletFunction
) -> Result<bool, GetResponseExpectedError>
pub fn get_response_expected(
&mut self,
fun: VoltageCurrentBrickletFunction
) -> Result<bool, GetResponseExpectedError>
Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.
For getter functions this is enabled by default and cannot be disabled, because those
functions will always send a response. For callback configuration functions it is enabled
by default too, but can be disabled by set_response_expected
.
For setter functions it is disabled by default and can be enabled.
Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is send and errors are silently ignored, because they cannot be detected.
See set_response_expected
for the list of function ID constants available for this function.
sourcepub fn set_response_expected(
&mut self,
fun: VoltageCurrentBrickletFunction,
response_expected: bool
) -> Result<(), SetResponseExpectedError>
pub fn set_response_expected(
&mut self,
fun: VoltageCurrentBrickletFunction,
response_expected: bool
) -> Result<(), SetResponseExpectedError>
Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.
Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is send and errors are silently ignored, because they cannot be detected.
sourcepub fn set_response_expected_all(&mut self, response_expected: bool)
pub fn set_response_expected_all(&mut self, response_expected: bool)
Changes the response expected flag for all setter and callback configuration functions of this device at once.
sourcepub fn get_current_callback_receiver(&self) -> ConvertingCallbackReceiver<i32>
pub fn get_current_callback_receiver(&self) -> ConvertingCallbackReceiver<i32>
This receiver is triggered periodically with the period that is set by
set_current_callback_period
. The parameter is the current of the
sensor.
The get_current_callback_receiver
receiver is only triggered if the current has changed since
the last triggering.
sourcepub fn get_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<i32>
pub fn get_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<i32>
This receiver is triggered periodically with the period that is set by
set_voltage_callback_period
. The parameter is the voltage of
the sensor.
The get_voltage_callback_receiver
receiver is only triggered if the voltage has changed since
the last triggering.
sourcepub fn get_power_callback_receiver(&self) -> ConvertingCallbackReceiver<i32>
pub fn get_power_callback_receiver(&self) -> ConvertingCallbackReceiver<i32>
This receiver is triggered periodically with the period that is set by
set_power_callback_period
. The parameter is the power of the
sensor.
The get_power_callback_receiver
receiver is only triggered if the power has changed since the
last triggering.
sourcepub fn get_current_reached_callback_receiver(
&self
) -> ConvertingCallbackReceiver<i32>
pub fn get_current_reached_callback_receiver(
&self
) -> ConvertingCallbackReceiver<i32>
This receiver is triggered when the threshold as set by
set_current_callback_threshold
is reached.
The parameter is the current of the sensor.
If the threshold keeps being reached, the receiver is triggered periodically
with the period as set by set_debounce_period
.
sourcepub fn get_voltage_reached_callback_receiver(
&self
) -> ConvertingCallbackReceiver<i32>
pub fn get_voltage_reached_callback_receiver(
&self
) -> ConvertingCallbackReceiver<i32>
This receiver is triggered when the threshold as set by
set_voltage_callback_threshold
is reached.
The parameter is the voltage of the sensor.
If the threshold keeps being reached, the receiver is triggered periodically
with the period as set by set_debounce_period
.
sourcepub fn get_power_reached_callback_receiver(
&self
) -> ConvertingCallbackReceiver<i32>
pub fn get_power_reached_callback_receiver(
&self
) -> ConvertingCallbackReceiver<i32>
This receiver is triggered when the threshold as set by
set_power_callback_threshold
is reached.
The parameter is the power of the sensor.
If the threshold keeps being reached, the receiver is triggered periodically
with the period as set by set_debounce_period
.
sourcepub fn get_current(&self) -> ConvertingReceiver<i32>
pub fn get_current(&self) -> ConvertingReceiver<i32>
Returns the current. The value is in mA and between -20000mA and 20000mA.
If you want to get the current periodically, it is recommended to use the
get_current_callback_receiver
receiver and set the period with
set_current_callback_period
.
sourcepub fn get_voltage(&self) -> ConvertingReceiver<i32>
pub fn get_voltage(&self) -> ConvertingReceiver<i32>
Returns the voltage. The value is in mV and between 0mV and 36000mV.
If you want to get the voltage periodically, it is recommended to use the
get_voltage_callback_receiver
receiver and set the period with
set_voltage_callback_period
.
sourcepub fn get_power(&self) -> ConvertingReceiver<i32>
pub fn get_power(&self) -> ConvertingReceiver<i32>
Returns the power. The value is in mW and between 0mV and 720000mW.
If you want to get the power periodically, it is recommended to use the
get_power_callback_receiver
receiver and set the period with
set_power_callback_period
.
sourcepub fn set_configuration(
&self,
averaging: u8,
voltage_conversion_time: u8,
current_conversion_time: u8
) -> ConvertingReceiver<()>
pub fn set_configuration(
&self,
averaging: u8,
voltage_conversion_time: u8,
current_conversion_time: u8
) -> ConvertingReceiver<()>
Sets the configuration of the Voltage/Current Bricklet. It is possible to configure number of averages as well as voltage and current conversion time.
Averaging:
Value | Number of Averages |
---|---|
0 | 1 |
1 | 4 |
2 | 16 |
3 | 64 |
4 | 128 |
5 | 256 |
6 | 512 |
>=7 | 1024 |
Voltage/Current conversion:
Value | Conversion time |
---|---|
0 | 140µs |
1 | 204µs |
2 | 332µs |
3 | 588µs |
4 | 1.1ms |
5 | 2.116ms |
6 | 4.156ms |
>=7 | 8.244ms |
The default values are 3, 4 and 4 (64, 1.1ms, 1.1ms) for averaging, voltage conversion and current conversion.
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_1
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_4
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_16
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_64
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_128
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_256
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_512
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_1024
sourcepub fn get_configuration(&self) -> ConvertingReceiver<Configuration>
pub fn get_configuration(&self) -> ConvertingReceiver<Configuration>
Returns the configuration as set by set_configuration
.
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_1
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_4
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_16
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_64
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_128
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_256
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_512
- VOLTAGE_CURRENT_BRICKLET_AVERAGING_1024
sourcepub fn set_calibration(
&self,
gain_multiplier: u16,
gain_divisor: u16
) -> ConvertingReceiver<()>
pub fn set_calibration(
&self,
gain_multiplier: u16,
gain_divisor: u16
) -> ConvertingReceiver<()>
Since the shunt resistor that is used to measure the current is not perfectly precise, it needs to be calibrated by a multiplier and divisor if a very precise reading is needed.
For example, if you are expecting a measurement of 1000mA and you are measuring 1023mA, you can calibrate the Voltage/Current Bricklet by setting the multiplier to 1000 and the divisor to 1023.
sourcepub fn get_calibration(&self) -> ConvertingReceiver<Calibration>
pub fn get_calibration(&self) -> ConvertingReceiver<Calibration>
Returns the calibration as set by set_calibration
.
sourcepub fn set_current_callback_period(&self, period: u32) -> ConvertingReceiver<()>
pub fn set_current_callback_period(&self, period: u32) -> ConvertingReceiver<()>
Sets the period in ms with which the get_current_callback_receiver
receiver is triggered
periodically. A value of 0 turns the receiver off.
The get_current_callback_receiver
receiver is only triggered if the current has changed since
the last triggering.
The default value is 0.
sourcepub fn get_current_callback_period(&self) -> ConvertingReceiver<u32>
pub fn get_current_callback_period(&self) -> ConvertingReceiver<u32>
Returns the period as set by set_current_callback_period
.
sourcepub fn set_voltage_callback_period(&self, period: u32) -> ConvertingReceiver<()>
pub fn set_voltage_callback_period(&self, period: u32) -> ConvertingReceiver<()>
Sets the period in ms with which the get_voltage_callback_receiver
receiver is triggered
periodically. A value of 0 turns the receiver off.
The get_voltage_callback_receiver
receiver is only triggered if the voltage has changed since
the last triggering.
The default value is 0.
sourcepub fn get_voltage_callback_period(&self) -> ConvertingReceiver<u32>
pub fn get_voltage_callback_period(&self) -> ConvertingReceiver<u32>
Returns the period as set by set_voltage_callback_period
.
sourcepub fn set_power_callback_period(&self, period: u32) -> ConvertingReceiver<()>
pub fn set_power_callback_period(&self, period: u32) -> ConvertingReceiver<()>
Sets the period in ms with which the get_power_callback_receiver
receiver is triggered
periodically. A value of 0 turns the receiver off.
The get_power_callback_receiver
receiver is only triggered if the power has changed since the
last triggering.
The default value is 0.
sourcepub fn get_power_callback_period(&self) -> ConvertingReceiver<u32>
pub fn get_power_callback_period(&self) -> ConvertingReceiver<u32>
Returns the period as set by get_power_callback_period
.
sourcepub fn set_current_callback_threshold(
&self,
option: char,
min: i32,
max: i32
) -> ConvertingReceiver<()>
pub fn set_current_callback_threshold(
&self,
option: char,
min: i32,
max: i32
) -> ConvertingReceiver<()>
Sets the thresholds for the get_current_reached_callback_receiver
receiver.
The following options are possible:
Option | Description |
---|---|
‘x’ | Receiver is turned off |
‘o’ | Receiver is triggered when the current is outside the min and max values |
‘i’ | Receiver is triggered when the current is inside the min and max values |
‘<’ | Receiver is triggered when the current is smaller than the min value (max is ignored) |
‘>’ | Receiver is triggered when the current is greater than the min value (max is ignored) |
The default value is (‘x’, 0, 0).
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OFF
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_INSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_SMALLER
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_GREATER
sourcepub fn get_current_callback_threshold(
&self
) -> ConvertingReceiver<CurrentCallbackThreshold>
pub fn get_current_callback_threshold(
&self
) -> ConvertingReceiver<CurrentCallbackThreshold>
Returns the threshold as set by set_current_callback_threshold
.
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OFF
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_INSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_SMALLER
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_GREATER
sourcepub fn set_voltage_callback_threshold(
&self,
option: char,
min: i32,
max: i32
) -> ConvertingReceiver<()>
pub fn set_voltage_callback_threshold(
&self,
option: char,
min: i32,
max: i32
) -> ConvertingReceiver<()>
Sets the thresholds for the get_voltage_reached_callback_receiver
receiver.
The following options are possible:
Option | Description |
---|---|
‘x’ | Receiver is turned off |
‘o’ | Receiver is triggered when the voltage is outside the min and max values |
‘i’ | Receiver is triggered when the voltage is inside the min and max values |
‘<’ | Receiver is triggered when the voltage is smaller than the min value (max is ignored) |
‘>’ | Receiver is triggered when the voltage is greater than the min value (max is ignored) |
The default value is (‘x’, 0, 0).
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OFF
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_INSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_SMALLER
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_GREATER
sourcepub fn get_voltage_callback_threshold(
&self
) -> ConvertingReceiver<VoltageCallbackThreshold>
pub fn get_voltage_callback_threshold(
&self
) -> ConvertingReceiver<VoltageCallbackThreshold>
Returns the threshold as set by set_voltage_callback_threshold
.
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OFF
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_INSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_SMALLER
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_GREATER
sourcepub fn set_power_callback_threshold(
&self,
option: char,
min: i32,
max: i32
) -> ConvertingReceiver<()>
pub fn set_power_callback_threshold(
&self,
option: char,
min: i32,
max: i32
) -> ConvertingReceiver<()>
Sets the thresholds for the get_power_reached_callback_receiver
receiver.
The following options are possible:
Option | Description |
---|---|
‘x’ | Receiver is turned off |
‘o’ | Receiver is triggered when the power is outside the min and max values |
‘i’ | Receiver is triggered when the power is inside the min and max values |
‘<’ | Receiver is triggered when the power is smaller than the min value (max is ignored) |
‘>’ | Receiver is triggered when the power is greater than the min value (max is ignored) |
The default value is (‘x’, 0, 0).
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OFF
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_INSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_SMALLER
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_GREATER
sourcepub fn get_power_callback_threshold(
&self
) -> ConvertingReceiver<PowerCallbackThreshold>
pub fn get_power_callback_threshold(
&self
) -> ConvertingReceiver<PowerCallbackThreshold>
Returns the threshold as set by set_power_callback_threshold
.
Associated constants:
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OFF
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_INSIDE
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_SMALLER
- VOLTAGE_CURRENT_BRICKLET_THRESHOLD_OPTION_GREATER
sourcepub fn set_debounce_period(&self, debounce: u32) -> ConvertingReceiver<()>
pub fn set_debounce_period(&self, debounce: u32) -> ConvertingReceiver<()>
Sets the period in ms with which the threshold receivers
get_current_reached_callback_receiver
,get_voltage_reached_callback_receiver
,get_power_reached_callback_receiver
are triggered, if the thresholds
keep being reached.
The default value is 100.
sourcepub fn get_debounce_period(&self) -> ConvertingReceiver<u32>
pub fn get_debounce_period(&self) -> ConvertingReceiver<u32>
Returns the debounce period as set by set_debounce_period
.
sourcepub fn get_identity(&self) -> ConvertingReceiver<Identity>
pub fn get_identity(&self) -> ConvertingReceiver<Identity>
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
The position can be ‘a’, ‘b’, ‘c’ or ‘d’.
The device identifier numbers can be found here. |device_identifier_constant|
Trait Implementations
sourceimpl Clone for VoltageCurrentBricklet
impl Clone for VoltageCurrentBricklet
sourcefn clone(&self) -> VoltageCurrentBricklet
fn clone(&self) -> VoltageCurrentBricklet
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more