pub struct El3356 {
pub peak_load: f32,
pub busy: bool,
pub error: bool,
pub error_message: String,
pub configured_mv_v: Option<f32>,
pub configured_full_scale_load: Option<f32>,
pub configured_scale_factor: Option<f32>,
/* private fields */
}Expand description
Function block for the Beckhoff EL3356 strain-gauge terminal.
Fields§
§peak_load: f32Largest absolute load seen since construction, last reset, or last tare.
busy: boolTrue while a configuration read or write sequence is in progress.
error: boolTrue after an SDO operation failed. Clear with clear_error.
error_message: StringLast error message, if any.
configured_mv_v: Option<f32>Current sensitivity (mV/V) value on the device. Populated by the last
successful configure or
read_configuration. None until one of
those completes. Reset to None at the start of each call.
configured_full_scale_load: Option<f32>Current full-scale load value on the device. Populated by the last
successful configure or
read_configuration. None until one
completes. Reset to None at the start of each call.
configured_scale_factor: Option<f32>Current scale factor on the device. Populated by the last successful
configure or
read_configuration. None until one
completes. Reset to None at the start of each call.
Implementations§
Source§impl El3356
impl El3356
Sourcepub fn new(device: &str) -> Self
pub fn new(device: &str) -> Self
Create a new EL3356 function block for the given EtherCAT device name.
device must match the name used in project.json’s ethercat device
list (it’s the device field sent with every SDO request).
Sourcepub fn tick(&mut self, view: &mut El3356View<'_>, client: &mut CommandClient)
pub fn tick(&mut self, view: &mut El3356View<'_>, client: &mut CommandClient)
Call every control cycle.
Performs three things, in order:
- Updates
peak_loadfrom*view.load. - Releases the tare pulse after 100 ms.
- Progresses any in-flight SDO operation from
configure.
Sourcepub fn configure(
&mut self,
client: &mut CommandClient,
full_scale_load: f32,
sensitivity_mv_v: f32,
scale_factor: f32,
)
pub fn configure( &mut self, client: &mut CommandClient, full_scale_load: f32, sensitivity_mv_v: f32, scale_factor: f32, )
Begin an SDO configuration sequence: sensitivity (mV/V), full-scale
load, and scale factor written to object 0x8000 subs 0x23, 0x24,
and 0x27 respectively. Non-blocking — sets busy = true and returns
immediately. Poll busy / error on subsequent ticks.
No-op (logs a warning) if the FB is already busy. Any existing error
flag is cleared at the start of a new sequence.
Sourcepub fn read_configuration(&mut self, client: &mut CommandClient)
pub fn read_configuration(&mut self, client: &mut CommandClient)
Begin an SDO read sequence that fetches the three calibration parameters from the terminal’s non-volatile memory.
The EL3356 stores sensitivity, full-scale load, and scale factor
persistently, so the card may power up with values from a previous
configuration — not necessarily what the current control program
expects. Call read_configuration at startup (or whenever you need
to verify the sensor parameters) to populate the configured_*
fields with the device’s current values.
Non-blocking: sets busy = true and returns immediately. Poll busy
/ error on subsequent ticks. No-op (logs a warning) if already busy.
Clears error and resets all three configured_* fields to None
at the start so intermediate values aren’t mistaken for final ones.
Sourcepub fn reset_peak(&mut self)
pub fn reset_peak(&mut self)
Reset peak_load to 0.0. Immediate; no IPC.
Sourcepub fn tare(&mut self)
pub fn tare(&mut self)
Pulse the tare bit high for 100 ms, and reset the peak.
The device-side bit (view.tare) is actually written by tick,
so tick must be called every cycle. If tare is called while a
previous pulse is still in progress, the 100 ms window restarts.
Sourcepub fn clear_error(&mut self)
pub fn clear_error(&mut self)
Clear the error flag and message.
Sourcepub fn sdo_write(
&mut self,
client: &mut CommandClient,
index: u16,
sub_index: u8,
value: Value,
)
pub fn sdo_write( &mut self, client: &mut CommandClient, index: u16, sub_index: u8, value: Value, )
Write an arbitrary SDO. Non-blocking; sets busy = true and tracks
the response through the FB’s state machine like the other operations.
Does not touch the configured_* calibration fields — generic
writes are orthogonal to the calibration cycle managed by
configure and read_configuration.
Sourcepub fn sdo_read(
&mut self,
client: &mut CommandClient,
index: u16,
sub_index: u8,
)
pub fn sdo_read( &mut self, client: &mut CommandClient, index: u16, sub_index: u8, )
Read an arbitrary SDO. Non-blocking; the response lands in the
internal result buffer, retrievable via result,
result_as_f64,
result_as_i64, or
result_as_f32 once busy clears.
Does not touch the configured_* calibration fields — generic
reads are orthogonal to the calibration cycle managed by
configure and read_configuration.
Sourcepub fn set_mode0_filter_enabled(
&mut self,
client: &mut CommandClient,
enable: bool,
)
pub fn set_mode0_filter_enabled( &mut self, client: &mut CommandClient, enable: bool, )
Enable or disable the filter on Mode 0, which is the default, slower mode of the bridge input ADC. Factory default is TRUE. Mode 0 is active when the Sample Mode bit of the Control Word is FALSE.
Sourcepub fn set_mode0_averager_enabled(
&mut self,
client: &mut CommandClient,
enable: bool,
)
pub fn set_mode0_averager_enabled( &mut self, client: &mut CommandClient, enable: bool, )
Enable or disable the averager on Mode 0, which is the default, slower mode of the bridge input ADC. The averager is low-latency and should usually be left on. Mode 0 (10.5 kSps internal rate): The 4-sample averager adds roughly 0.14 ms of latency. Factory default is TRUE. Mode 0 is active when the Sample Mode bit of the Control Word is FALSE.
Sourcepub fn set_mode0_filter(
&mut self,
client: &mut CommandClient,
filter: El3356Filters,
)
pub fn set_mode0_filter( &mut self, client: &mut CommandClient, filter: El3356Filters, )
Set the Mode 1 filter (CoE 0x8000:11).
Mode 0, the default mode, is High Precision.
Mode 0 is active when the Sample Mode bit of the Control Word is FALSE.
The ADC runs slower (yielding a hardware latency of around 7.2 ms) but delivers very high accuracy and low noise.
Mode 0 is typically used paired with a stronger IIR filter—for highly accurate, static weighing where a completely calm value is required.
Sourcepub fn set_mode1_filter_enabled(
&mut self,
client: &mut CommandClient,
enable: bool,
)
pub fn set_mode1_filter_enabled( &mut self, client: &mut CommandClient, enable: bool, )
Enable or disable the filter on Mode 1, the faster mode of the bridge input ADC. Factory default is TRUE. Mode 1 is active when the Sample Mode bit of the Control Word is TRUE.
Sourcepub fn set_mode1_averager_enabled(
&mut self,
client: &mut CommandClient,
enable: bool,
)
pub fn set_mode1_averager_enabled( &mut self, client: &mut CommandClient, enable: bool, )
Enable or disable the averager on Mode 1, the faster mode of the bridge input ADC. The averager is low-latency and should usually be left on. Mode 1 (105.5 kSps internal rate): The 4-sample averager adds roughly 0.014 ms of latency. Factory default is TRUE. Mode 1 is active when the Sample Mode bit of the Control Word is TRUE.
Sourcepub fn set_mode1_filter(
&mut self,
client: &mut CommandClient,
filter: El3356Filters,
)
pub fn set_mode1_filter( &mut self, client: &mut CommandClient, filter: El3356Filters, )
Set the Mode 1 filter (CoE 0x8000:12). Mode 1 sacrifices a bit of accuracy for speed: the ADC runs much faster (yielding a hardware latency around 0.72 ms). Mode 1 is typically paired with a very weak filter (like IIR1 or disabled entirely) to track fast transients — for example, capturing a rapid impact or tracking a high-speed dosing cycle. Mode 1 is active when the Sample Mode bit of the Control Word is TRUE.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Full reset: drop all transient state so the FB behaves as if freshly constructed (except for the cached SDO device name).
Clears the error flag, cancels any in-flight SDO operation, releases
the tare bit on the next tick, and discards the last
sdo_read result. Does not zero peak_load — call
reset_peak or tare if you need
that — and does not clear configured_*; those stay populated
from the last configure or
read_configuration so the program’s
view of the device’s calibration survives a mid-op abort.
Sourcepub fn result(&self) -> Value
pub fn result(&self) -> Value
Get the full response from the most recent sdo_read.
The returned value is the complete ethercat.read_sdo payload — an
object with value, value_hex, size, raw_bytes, etc. Prefer the
typed accessors (result_as_f64,
result_as_i64,
result_as_f32) for scalar register reads.
Sourcepub fn result_as_f64(&self) -> Option<f64>
pub fn result_as_f64(&self) -> Option<f64>
Get the value field of the most recent sdo_read
as an f64, if the SDO returned a number. Returns None if no read
has completed, the response had no value field, or the field is not
coercible to f64.
Sourcepub fn result_as_i64(&self) -> Option<i64>
pub fn result_as_i64(&self) -> Option<i64>
Get the value field of the most recent sdo_read
as an i64. See result_as_f64 for None
semantics.
Sourcepub fn result_as_f32(&self) -> Option<f32>
pub fn result_as_f32(&self) -> Option<f32>
Get the value field of the most recent sdo_read
as an f32, interpreting the returned u32 bit pattern as an
IEEE-754 single-precision float. This is the correct accessor for
REAL32 SDOs (e.g. the EL3356’s calibration parameters).