tinkerforge_async/bindings/
industrial_dual_analog_in_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! Measures two DC voltages between -35V and +35V with 24bit resolution each.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/IndustrialDualAnalogIn_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17    low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum IndustrialDualAnalogInBrickletFunction {
24    GetVoltage,
25    SetVoltageCallbackPeriod,
26    GetVoltageCallbackPeriod,
27    SetVoltageCallbackThreshold,
28    GetVoltageCallbackThreshold,
29    SetDebouncePeriod,
30    GetDebouncePeriod,
31    SetSampleRate,
32    GetSampleRate,
33    SetCalibration,
34    GetCalibration,
35    GetAdcValues,
36    GetIdentity,
37    CallbackVoltage,
38    CallbackVoltageReached,
39}
40impl From<IndustrialDualAnalogInBrickletFunction> for u8 {
41    fn from(fun: IndustrialDualAnalogInBrickletFunction) -> Self {
42        match fun {
43            IndustrialDualAnalogInBrickletFunction::GetVoltage => 1,
44            IndustrialDualAnalogInBrickletFunction::SetVoltageCallbackPeriod => 2,
45            IndustrialDualAnalogInBrickletFunction::GetVoltageCallbackPeriod => 3,
46            IndustrialDualAnalogInBrickletFunction::SetVoltageCallbackThreshold => 4,
47            IndustrialDualAnalogInBrickletFunction::GetVoltageCallbackThreshold => 5,
48            IndustrialDualAnalogInBrickletFunction::SetDebouncePeriod => 6,
49            IndustrialDualAnalogInBrickletFunction::GetDebouncePeriod => 7,
50            IndustrialDualAnalogInBrickletFunction::SetSampleRate => 8,
51            IndustrialDualAnalogInBrickletFunction::GetSampleRate => 9,
52            IndustrialDualAnalogInBrickletFunction::SetCalibration => 10,
53            IndustrialDualAnalogInBrickletFunction::GetCalibration => 11,
54            IndustrialDualAnalogInBrickletFunction::GetAdcValues => 12,
55            IndustrialDualAnalogInBrickletFunction::GetIdentity => 255,
56            IndustrialDualAnalogInBrickletFunction::CallbackVoltage => 13,
57            IndustrialDualAnalogInBrickletFunction::CallbackVoltageReached => 14,
58        }
59    }
60}
61pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
62pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
63pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
64pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
65pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
66pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_976_SPS: u8 = 0;
67pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_488_SPS: u8 = 1;
68pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_244_SPS: u8 = 2;
69pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_122_SPS: u8 = 3;
70pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_61_SPS: u8 = 4;
71pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_4_SPS: u8 = 5;
72pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_2_SPS: u8 = 6;
73pub const INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_1_SPS: u8 = 7;
74
75#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
76pub struct VoltageCallbackThreshold {
77    pub option: char,
78    pub min: i32,
79    pub max: i32,
80}
81impl FromByteSlice for VoltageCallbackThreshold {
82    fn bytes_expected() -> usize {
83        9
84    }
85    fn from_le_byte_slice(bytes: &[u8]) -> VoltageCallbackThreshold {
86        VoltageCallbackThreshold {
87            option: <char>::from_le_byte_slice(&bytes[0..1]),
88            min: <i32>::from_le_byte_slice(&bytes[1..5]),
89            max: <i32>::from_le_byte_slice(&bytes[5..9]),
90        }
91    }
92}
93
94#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
95pub struct Calibration {
96    pub offset: [i32; 2],
97    pub gain: [i32; 2],
98}
99impl FromByteSlice for Calibration {
100    fn bytes_expected() -> usize {
101        16
102    }
103    fn from_le_byte_slice(bytes: &[u8]) -> Calibration {
104        Calibration { offset: <[i32; 2]>::from_le_byte_slice(&bytes[0..8]), gain: <[i32; 2]>::from_le_byte_slice(&bytes[8..16]) }
105    }
106}
107
108#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
109pub struct VoltageEvent {
110    pub channel: u8,
111    pub voltage: i32,
112}
113impl FromByteSlice for VoltageEvent {
114    fn bytes_expected() -> usize {
115        5
116    }
117    fn from_le_byte_slice(bytes: &[u8]) -> VoltageEvent {
118        VoltageEvent { channel: <u8>::from_le_byte_slice(&bytes[0..1]), voltage: <i32>::from_le_byte_slice(&bytes[1..5]) }
119    }
120}
121
122#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
123pub struct VoltageReachedEvent {
124    pub channel: u8,
125    pub voltage: i32,
126}
127impl FromByteSlice for VoltageReachedEvent {
128    fn bytes_expected() -> usize {
129        5
130    }
131    fn from_le_byte_slice(bytes: &[u8]) -> VoltageReachedEvent {
132        VoltageReachedEvent { channel: <u8>::from_le_byte_slice(&bytes[0..1]), voltage: <i32>::from_le_byte_slice(&bytes[1..5]) }
133    }
134}
135
136#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
137pub struct Identity {
138    pub uid: String,
139    pub connected_uid: String,
140    pub position: char,
141    pub hardware_version: [u8; 3],
142    pub firmware_version: [u8; 3],
143    pub device_identifier: u16,
144}
145impl FromByteSlice for Identity {
146    fn bytes_expected() -> usize {
147        25
148    }
149    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
150        Identity {
151            uid: <String>::from_le_byte_slice(&bytes[0..8]),
152            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
153            position: <char>::from_le_byte_slice(&bytes[16..17]),
154            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
155            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
156            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
157        }
158    }
159}
160
161/// Measures two DC voltages between -35V and +35V with 24bit resolution each
162#[derive(Clone)]
163pub struct IndustrialDualAnalogInBricklet {
164    device: Device,
165}
166impl IndustrialDualAnalogInBricklet {
167    pub const DEVICE_IDENTIFIER: u16 = 249;
168    pub const DEVICE_DISPLAY_NAME: &'static str = "Industrial Dual Analog In Bricklet";
169    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
170    pub fn new(uid: Uid, connection: AsyncIpConnection) -> IndustrialDualAnalogInBricklet {
171        let mut result = IndustrialDualAnalogInBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
172        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetVoltage) as usize] =
173            ResponseExpectedFlag::AlwaysTrue;
174        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::SetVoltageCallbackPeriod) as usize] =
175            ResponseExpectedFlag::True;
176        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetVoltageCallbackPeriod) as usize] =
177            ResponseExpectedFlag::AlwaysTrue;
178        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::SetVoltageCallbackThreshold) as usize] =
179            ResponseExpectedFlag::True;
180        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetVoltageCallbackThreshold) as usize] =
181            ResponseExpectedFlag::AlwaysTrue;
182        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::SetDebouncePeriod) as usize] =
183            ResponseExpectedFlag::True;
184        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetDebouncePeriod) as usize] =
185            ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::SetSampleRate) as usize] =
187            ResponseExpectedFlag::False;
188        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetSampleRate) as usize] =
189            ResponseExpectedFlag::AlwaysTrue;
190        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::SetCalibration) as usize] =
191            ResponseExpectedFlag::False;
192        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetCalibration) as usize] =
193            ResponseExpectedFlag::AlwaysTrue;
194        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetAdcValues) as usize] =
195            ResponseExpectedFlag::AlwaysTrue;
196        result.device.response_expected[u8::from(IndustrialDualAnalogInBrickletFunction::GetIdentity) as usize] =
197            ResponseExpectedFlag::AlwaysTrue;
198        result
199    }
200
201    /// Returns the response expected flag for the function specified by the function ID parameter.
202    /// It is true if the function is expected to send a response, false otherwise.
203    ///
204    /// For getter functions this is enabled by default and cannot be disabled, because those
205    /// functions will always send a response. For callback configuration functions it is enabled
206    /// by default too, but can be disabled by [`set_response_expected`](crate::industrial_dual_analog_in_bricklet::IndustrialDualAnalogInBricklet::set_response_expected).
207    /// For setter functions it is disabled by default and can be enabled.
208    ///
209    /// Enabling the response expected flag for a setter function allows to detect timeouts
210    /// and other error conditions calls of this setter as well. The device will then send a response
211    /// for this purpose. If this flag is disabled for a setter function then no response is sent
212    /// and errors are silently ignored, because they cannot be detected.
213    ///
214    /// See [`set_response_expected`](crate::industrial_dual_analog_in_bricklet::IndustrialDualAnalogInBricklet::set_response_expected) for the list of function ID constants available for this function.
215    pub fn get_response_expected(&mut self, fun: IndustrialDualAnalogInBrickletFunction) -> Result<bool, GetResponseExpectedError> {
216        self.device.get_response_expected(u8::from(fun))
217    }
218
219    /// Changes the response expected flag of the function specified by the function ID parameter.
220    /// This flag can only be changed for setter (default value: false) and callback configuration
221    /// functions (default value: true). For getter functions it is always enabled.
222    ///
223    /// Enabling the response expected flag for a setter function allows to detect timeouts and
224    /// other error conditions calls of this setter as well. The device will then send a response
225    /// for this purpose. If this flag is disabled for a setter function then no response is sent
226    /// and errors are silently ignored, because they cannot be detected.
227    pub fn set_response_expected(
228        &mut self,
229        fun: IndustrialDualAnalogInBrickletFunction,
230        response_expected: bool,
231    ) -> Result<(), SetResponseExpectedError> {
232        self.device.set_response_expected(u8::from(fun), response_expected)
233    }
234
235    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
236    pub fn set_response_expected_all(&mut self, response_expected: bool) {
237        self.device.set_response_expected_all(response_expected)
238    }
239
240    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
241    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
242    pub fn get_api_version(&self) -> [u8; 3] {
243        self.device.api_version
244    }
245
246    /// This receiver is triggered periodically with the period that is set by
247    /// [`set_voltage_callback_period`]. The parameter is the voltage of the
248    /// channel.
249    ///
250    /// The [`get_voltage_callback_receiver`] receiver is only triggered if the voltage has changed since the
251    /// last triggering.
252    ///
253    /// [`set_voltage_callback_period`]: #method.set_voltage_callback_period
254    /// [`get_voltage_callback_receiver`]: #method.get_voltage_callback_receiver
255    pub async fn get_voltage_callback_receiver(&mut self) -> impl Stream<Item = VoltageEvent> {
256        self.device
257            .get_callback_receiver(u8::from(IndustrialDualAnalogInBrickletFunction::CallbackVoltage))
258            .await
259            .map(|p| VoltageEvent::from_le_byte_slice(p.body()))
260    }
261
262    /// This receiver is triggered when the threshold as set by
263    /// [`set_voltage_callback_threshold`] is reached.
264    /// The parameter is the voltage of the channel.
265    ///
266    /// If the threshold keeps being reached, the receiver is triggered periodically
267    /// with the period as set by [`set_debounce_period`].
268    pub async fn get_voltage_reached_callback_receiver(&mut self) -> impl Stream<Item = VoltageReachedEvent> {
269        self.device
270            .get_callback_receiver(u8::from(IndustrialDualAnalogInBrickletFunction::CallbackVoltageReached))
271            .await
272            .map(|p| VoltageReachedEvent::from_le_byte_slice(p.body()))
273    }
274
275    /// Returns the voltage for the given channel.
276    ///
277    /// If you want to get the voltage periodically, it is recommended to use the
278    /// [`get_voltage_callback_receiver`] receiver and set the period with
279    /// [`set_voltage_callback_period`].
280    pub async fn get_voltage(&mut self, channel: u8) -> Result<i32, TinkerforgeError> {
281        let mut payload = [0; 1];
282        channel.write_to_slice(&mut payload[0..1]);
283
284        #[allow(unused_variables)]
285        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetVoltage), &payload).await?;
286        Ok(i32::from_le_byte_slice(result.body()))
287    }
288
289    /// Sets the period with which the [`get_voltage_callback_receiver`] receiver is triggered
290    /// periodically for the given channel. A value of 0 turns the receiver off.
291    ///
292    /// The [`get_voltage_callback_receiver`] receiver is only triggered if the voltage has changed since the
293    /// last triggering.
294    pub async fn set_voltage_callback_period(&mut self, channel: u8, period: u32) -> Result<(), TinkerforgeError> {
295        let mut payload = [0; 5];
296        channel.write_to_slice(&mut payload[0..1]);
297        period.write_to_slice(&mut payload[1..5]);
298
299        #[allow(unused_variables)]
300        let result = self.device.set(u8::from(IndustrialDualAnalogInBrickletFunction::SetVoltageCallbackPeriod), &payload).await?;
301        Ok(())
302    }
303
304    /// Returns the period as set by [`set_voltage_callback_period`].
305    pub async fn get_voltage_callback_period(&mut self, channel: u8) -> Result<u32, TinkerforgeError> {
306        let mut payload = [0; 1];
307        channel.write_to_slice(&mut payload[0..1]);
308
309        #[allow(unused_variables)]
310        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetVoltageCallbackPeriod), &payload).await?;
311        Ok(u32::from_le_byte_slice(result.body()))
312    }
313
314    /// Sets the thresholds for the [`get_voltage_reached_callback_receiver`] receiver for the given
315    /// channel.
316    ///
317    /// The following options are possible:
318    ///
319    ///  Option| Description
320    ///  --- | ---
321    ///  'x'|    Receiver is turned off
322    ///  'o'|    Receiver is triggered when the voltage is *outside* the min and max values
323    ///  'i'|    Receiver is triggered when the voltage is *inside* the min and max values
324    ///  '<'|    Receiver is triggered when the voltage is smaller than the min value (max is ignored)
325    ///  '>'|    Receiver is triggered when the voltage is greater than the min value (max is ignored)
326    ///
327    /// Associated constants:
328    /// * INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF
329    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE
330    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE
331    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER
332    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER
333    pub async fn set_voltage_callback_threshold(&mut self, channel: u8, option: char, min: i32, max: i32) -> Result<(), TinkerforgeError> {
334        let mut payload = [0; 10];
335        channel.write_to_slice(&mut payload[0..1]);
336        option.write_to_slice(&mut payload[1..2]);
337        min.write_to_slice(&mut payload[2..6]);
338        max.write_to_slice(&mut payload[6..10]);
339
340        #[allow(unused_variables)]
341        let result = self.device.set(u8::from(IndustrialDualAnalogInBrickletFunction::SetVoltageCallbackThreshold), &payload).await?;
342        Ok(())
343    }
344
345    /// Returns the threshold as set by [`set_voltage_callback_threshold`].
346    ///
347    /// Associated constants:
348    /// * INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF
349    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE
350    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE
351    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER
352    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER
353    pub async fn get_voltage_callback_threshold(&mut self, channel: u8) -> Result<VoltageCallbackThreshold, TinkerforgeError> {
354        let mut payload = [0; 1];
355        channel.write_to_slice(&mut payload[0..1]);
356
357        #[allow(unused_variables)]
358        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetVoltageCallbackThreshold), &payload).await?;
359        Ok(VoltageCallbackThreshold::from_le_byte_slice(result.body()))
360    }
361
362    /// Sets the period with which the threshold receiver
363    ///
364    /// * [`get_voltage_reached_callback_receiver`]
365    ///
366    /// is triggered, if the threshold
367    ///
368    /// * [`set_voltage_callback_threshold`]
369    ///
370    /// keeps being reached.
371    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
372        let mut payload = [0; 4];
373        debounce.write_to_slice(&mut payload[0..4]);
374
375        #[allow(unused_variables)]
376        let result = self.device.set(u8::from(IndustrialDualAnalogInBrickletFunction::SetDebouncePeriod), &payload).await?;
377        Ok(())
378    }
379
380    /// Returns the debounce period as set by [`set_debounce_period`].
381    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
382        let payload = [0; 0];
383
384        #[allow(unused_variables)]
385        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetDebouncePeriod), &payload).await?;
386        Ok(u32::from_le_byte_slice(result.body()))
387    }
388
389    /// Sets the sample rate. The sample rate can be between 1 sample per second
390    /// and 976 samples per second. Decreasing the sample rate will also decrease the
391    /// noise on the data.
392    ///
393    /// Associated constants:
394    /// * INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_976_SPS
395    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_488_SPS
396    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_244_SPS
397    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_122_SPS
398    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_61_SPS
399    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_4_SPS
400    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_2_SPS
401    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_1_SPS
402    pub async fn set_sample_rate(&mut self, rate: u8) -> Result<(), TinkerforgeError> {
403        let mut payload = [0; 1];
404        rate.write_to_slice(&mut payload[0..1]);
405
406        #[allow(unused_variables)]
407        let result = self.device.set(u8::from(IndustrialDualAnalogInBrickletFunction::SetSampleRate), &payload).await?;
408        Ok(())
409    }
410
411    /// Returns the sample rate as set by [`set_sample_rate`].
412    ///
413    /// Associated constants:
414    /// * INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_976_SPS
415    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_488_SPS
416    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_244_SPS
417    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_122_SPS
418    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_61_SPS
419    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_4_SPS
420    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_2_SPS
421    ///	* INDUSTRIAL_DUAL_ANALOG_IN_BRICKLET_SAMPLE_RATE_1_SPS
422    pub async fn get_sample_rate(&mut self) -> Result<u8, TinkerforgeError> {
423        let payload = [0; 0];
424
425        #[allow(unused_variables)]
426        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetSampleRate), &payload).await?;
427        Ok(u8::from_le_byte_slice(result.body()))
428    }
429
430    /// Sets offset and gain of MCP3911 internal calibration registers.
431    ///
432    /// See MCP3911 datasheet 7.7 and 7.8. The Industrial Dual Analog In Bricklet
433    /// is already factory calibrated by Tinkerforge. It should not be necessary
434    /// for you to use this function
435    pub async fn set_calibration(&mut self, offset: &[i32; 2], gain: &[i32; 2]) -> Result<(), TinkerforgeError> {
436        let mut payload = [0; 16];
437        offset.write_to_slice(&mut payload[0..8]);
438        gain.write_to_slice(&mut payload[8..16]);
439
440        #[allow(unused_variables)]
441        let result = self.device.set(u8::from(IndustrialDualAnalogInBrickletFunction::SetCalibration), &payload).await?;
442        Ok(())
443    }
444
445    /// Returns the calibration as set by [`set_calibration`].
446    pub async fn get_calibration(&mut self) -> Result<Calibration, TinkerforgeError> {
447        let payload = [0; 0];
448
449        #[allow(unused_variables)]
450        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetCalibration), &payload).await?;
451        Ok(Calibration::from_le_byte_slice(result.body()))
452    }
453
454    /// Returns the ADC values as given by the MCP3911 IC. This function
455    /// is needed for proper calibration, see [`set_calibration`].
456    pub async fn get_adc_values(&mut self) -> Result<Box<[i32; 2]>, TinkerforgeError> {
457        let payload = [0; 0];
458
459        #[allow(unused_variables)]
460        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetAdcValues), &payload).await?;
461        Ok(Box::<[i32; 2]>::from_le_byte_slice(result.body()))
462    }
463
464    /// Returns the UID, the UID where the Bricklet is connected to,
465    /// the position, the hardware and firmware version as well as the
466    /// device identifier.
467    ///
468    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
469    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
470    /// position 'z'.
471    ///
472    /// The device identifier numbers can be found [here](device_identifier).
473    /// |device_identifier_constant|
474    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
475        let payload = [0; 0];
476
477        #[allow(unused_variables)]
478        let result = self.device.get(u8::from(IndustrialDualAnalogInBrickletFunction::GetIdentity), &payload).await?;
479        Ok(Identity::from_le_byte_slice(result.body()))
480    }
481}