tinkerforge_async/bindings/
rs232_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//! Communicates with RS232 devices.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/RS232_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 Rs232BrickletFunction {
24    Write,
25    Read,
26    EnableReadCallback,
27    DisableReadCallback,
28    IsReadCallbackEnabled,
29    SetConfiguration,
30    GetConfiguration,
31    SetBreakCondition,
32    SetFrameReadableCallbackConfiguration,
33    GetFrameReadableCallbackConfiguration,
34    ReadFrame,
35    GetIdentity,
36    CallbackRead,
37    CallbackError,
38    CallbackFrameReadable,
39}
40impl From<Rs232BrickletFunction> for u8 {
41    fn from(fun: Rs232BrickletFunction) -> Self {
42        match fun {
43            Rs232BrickletFunction::Write => 1,
44            Rs232BrickletFunction::Read => 2,
45            Rs232BrickletFunction::EnableReadCallback => 3,
46            Rs232BrickletFunction::DisableReadCallback => 4,
47            Rs232BrickletFunction::IsReadCallbackEnabled => 5,
48            Rs232BrickletFunction::SetConfiguration => 6,
49            Rs232BrickletFunction::GetConfiguration => 7,
50            Rs232BrickletFunction::SetBreakCondition => 10,
51            Rs232BrickletFunction::SetFrameReadableCallbackConfiguration => 11,
52            Rs232BrickletFunction::GetFrameReadableCallbackConfiguration => 12,
53            Rs232BrickletFunction::ReadFrame => 14,
54            Rs232BrickletFunction::GetIdentity => 255,
55            Rs232BrickletFunction::CallbackRead => 8,
56            Rs232BrickletFunction::CallbackError => 9,
57            Rs232BrickletFunction::CallbackFrameReadable => 13,
58        }
59    }
60}
61pub const RS232_BRICKLET_BAUDRATE_300: u8 = 0;
62pub const RS232_BRICKLET_BAUDRATE_600: u8 = 1;
63pub const RS232_BRICKLET_BAUDRATE_1200: u8 = 2;
64pub const RS232_BRICKLET_BAUDRATE_2400: u8 = 3;
65pub const RS232_BRICKLET_BAUDRATE_4800: u8 = 4;
66pub const RS232_BRICKLET_BAUDRATE_9600: u8 = 5;
67pub const RS232_BRICKLET_BAUDRATE_14400: u8 = 6;
68pub const RS232_BRICKLET_BAUDRATE_19200: u8 = 7;
69pub const RS232_BRICKLET_BAUDRATE_28800: u8 = 8;
70pub const RS232_BRICKLET_BAUDRATE_38400: u8 = 9;
71pub const RS232_BRICKLET_BAUDRATE_57600: u8 = 10;
72pub const RS232_BRICKLET_BAUDRATE_115200: u8 = 11;
73pub const RS232_BRICKLET_BAUDRATE_230400: u8 = 12;
74pub const RS232_BRICKLET_PARITY_NONE: u8 = 0;
75pub const RS232_BRICKLET_PARITY_ODD: u8 = 1;
76pub const RS232_BRICKLET_PARITY_EVEN: u8 = 2;
77pub const RS232_BRICKLET_PARITY_FORCED_PARITY_1: u8 = 3;
78pub const RS232_BRICKLET_PARITY_FORCED_PARITY_0: u8 = 4;
79pub const RS232_BRICKLET_STOPBITS_1: u8 = 1;
80pub const RS232_BRICKLET_STOPBITS_2: u8 = 2;
81pub const RS232_BRICKLET_WORDLENGTH_5: u8 = 5;
82pub const RS232_BRICKLET_WORDLENGTH_6: u8 = 6;
83pub const RS232_BRICKLET_WORDLENGTH_7: u8 = 7;
84pub const RS232_BRICKLET_WORDLENGTH_8: u8 = 8;
85pub const RS232_BRICKLET_HARDWARE_FLOWCONTROL_OFF: u8 = 0;
86pub const RS232_BRICKLET_HARDWARE_FLOWCONTROL_ON: u8 = 1;
87pub const RS232_BRICKLET_SOFTWARE_FLOWCONTROL_OFF: u8 = 0;
88pub const RS232_BRICKLET_SOFTWARE_FLOWCONTROL_ON: u8 = 1;
89pub const RS232_BRICKLET_ERROR_OVERRUN: u8 = 1;
90pub const RS232_BRICKLET_ERROR_PARITY: u8 = 2;
91pub const RS232_BRICKLET_ERROR_FRAMING: u8 = 4;
92
93#[derive(Clone, Copy)]
94pub struct Read {
95    pub message: [char; 60],
96    pub length: u8,
97}
98impl FromByteSlice for Read {
99    fn bytes_expected() -> usize {
100        61
101    }
102    fn from_le_byte_slice(bytes: &[u8]) -> Read {
103        Read { message: <[char; 60]>::from_le_byte_slice(&bytes[0..60]), length: <u8>::from_le_byte_slice(&bytes[60..61]) }
104    }
105}
106
107#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
108pub struct Configuration {
109    pub baudrate: u8,
110    pub parity: u8,
111    pub stopbits: u8,
112    pub wordlength: u8,
113    pub hardware_flowcontrol: u8,
114    pub software_flowcontrol: u8,
115}
116impl FromByteSlice for Configuration {
117    fn bytes_expected() -> usize {
118        6
119    }
120    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
121        Configuration {
122            baudrate: <u8>::from_le_byte_slice(&bytes[0..1]),
123            parity: <u8>::from_le_byte_slice(&bytes[1..2]),
124            stopbits: <u8>::from_le_byte_slice(&bytes[2..3]),
125            wordlength: <u8>::from_le_byte_slice(&bytes[3..4]),
126            hardware_flowcontrol: <u8>::from_le_byte_slice(&bytes[4..5]),
127            software_flowcontrol: <u8>::from_le_byte_slice(&bytes[5..6]),
128        }
129    }
130}
131
132#[derive(Clone, Copy)]
133pub struct ReadEvent {
134    pub message: [char; 60],
135    pub length: u8,
136}
137impl FromByteSlice for ReadEvent {
138    fn bytes_expected() -> usize {
139        61
140    }
141    fn from_le_byte_slice(bytes: &[u8]) -> ReadEvent {
142        ReadEvent { message: <[char; 60]>::from_le_byte_slice(&bytes[0..60]), length: <u8>::from_le_byte_slice(&bytes[60..61]) }
143    }
144}
145
146#[derive(Clone, Copy)]
147pub struct ReadFrame {
148    pub message: [char; 60],
149    pub length: u8,
150}
151impl FromByteSlice for ReadFrame {
152    fn bytes_expected() -> usize {
153        61
154    }
155    fn from_le_byte_slice(bytes: &[u8]) -> ReadFrame {
156        ReadFrame { message: <[char; 60]>::from_le_byte_slice(&bytes[0..60]), length: <u8>::from_le_byte_slice(&bytes[60..61]) }
157    }
158}
159
160#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
161pub struct Identity {
162    pub uid: String,
163    pub connected_uid: String,
164    pub position: char,
165    pub hardware_version: [u8; 3],
166    pub firmware_version: [u8; 3],
167    pub device_identifier: u16,
168}
169impl FromByteSlice for Identity {
170    fn bytes_expected() -> usize {
171        25
172    }
173    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
174        Identity {
175            uid: <String>::from_le_byte_slice(&bytes[0..8]),
176            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
177            position: <char>::from_le_byte_slice(&bytes[16..17]),
178            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
179            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
180            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
181        }
182    }
183}
184
185/// Communicates with RS232 devices
186#[derive(Clone)]
187pub struct Rs232Bricklet {
188    device: Device,
189}
190impl Rs232Bricklet {
191    pub const DEVICE_IDENTIFIER: u16 = 254;
192    pub const DEVICE_DISPLAY_NAME: &'static str = "RS232 Bricklet";
193    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
194    pub fn new(uid: Uid, connection: AsyncIpConnection) -> Rs232Bricklet {
195        let mut result = Rs232Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
196        result.device.response_expected[u8::from(Rs232BrickletFunction::Write) as usize] = ResponseExpectedFlag::AlwaysTrue;
197        result.device.response_expected[u8::from(Rs232BrickletFunction::Read) as usize] = ResponseExpectedFlag::AlwaysTrue;
198        result.device.response_expected[u8::from(Rs232BrickletFunction::EnableReadCallback) as usize] = ResponseExpectedFlag::True;
199        result.device.response_expected[u8::from(Rs232BrickletFunction::DisableReadCallback) as usize] = ResponseExpectedFlag::True;
200        result.device.response_expected[u8::from(Rs232BrickletFunction::IsReadCallbackEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
201        result.device.response_expected[u8::from(Rs232BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
202        result.device.response_expected[u8::from(Rs232BrickletFunction::GetConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
203        result.device.response_expected[u8::from(Rs232BrickletFunction::SetBreakCondition) as usize] = ResponseExpectedFlag::False;
204        result.device.response_expected[u8::from(Rs232BrickletFunction::SetFrameReadableCallbackConfiguration) as usize] =
205            ResponseExpectedFlag::True;
206        result.device.response_expected[u8::from(Rs232BrickletFunction::GetFrameReadableCallbackConfiguration) as usize] =
207            ResponseExpectedFlag::AlwaysTrue;
208        result.device.response_expected[u8::from(Rs232BrickletFunction::ReadFrame) as usize] = ResponseExpectedFlag::AlwaysTrue;
209        result.device.response_expected[u8::from(Rs232BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
210        result
211    }
212
213    /// Returns the response expected flag for the function specified by the function ID parameter.
214    /// It is true if the function is expected to send a response, false otherwise.
215    ///
216    /// For getter functions this is enabled by default and cannot be disabled, because those
217    /// functions will always send a response. For callback configuration functions it is enabled
218    /// by default too, but can be disabled by [`set_response_expected`](crate::rs232_bricklet::Rs232Bricklet::set_response_expected).
219    /// For setter functions it is disabled by default and can be enabled.
220    ///
221    /// Enabling the response expected flag for a setter function allows to detect timeouts
222    /// and other error conditions calls of this setter as well. The device will then send a response
223    /// for this purpose. If this flag is disabled for a setter function then no response is sent
224    /// and errors are silently ignored, because they cannot be detected.
225    ///
226    /// See [`set_response_expected`](crate::rs232_bricklet::Rs232Bricklet::set_response_expected) for the list of function ID constants available for this function.
227    pub fn get_response_expected(&mut self, fun: Rs232BrickletFunction) -> Result<bool, GetResponseExpectedError> {
228        self.device.get_response_expected(u8::from(fun))
229    }
230
231    /// Changes the response expected flag of the function specified by the function ID parameter.
232    /// This flag can only be changed for setter (default value: false) and callback configuration
233    /// functions (default value: true). For getter functions it is always enabled.
234    ///
235    /// Enabling the response expected flag for a setter function allows to detect timeouts and
236    /// other error conditions calls of this setter as well. The device will then send a response
237    /// for this purpose. If this flag is disabled for a setter function then no response is sent
238    /// and errors are silently ignored, because they cannot be detected.
239    pub fn set_response_expected(&mut self, fun: Rs232BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
240        self.device.set_response_expected(u8::from(fun), response_expected)
241    }
242
243    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
244    pub fn set_response_expected_all(&mut self, response_expected: bool) {
245        self.device.set_response_expected_all(response_expected)
246    }
247
248    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
249    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
250    pub fn get_api_version(&self) -> [u8; 3] {
251        self.device.api_version
252    }
253
254    /// This receiver is called if new data is available. The message has
255    /// a maximum size of 60 characters. The actual length of the message
256    /// is given in addition.
257    ///
258    /// To enable this receiver, use [`enable_read_callback`].
259    ///
260    /// [`enable_read_callback`]: #method.enable_read_callback
261    pub async fn get_read_callback_receiver(&mut self) -> impl Stream<Item = ReadEvent> {
262        self.device
263            .get_callback_receiver(u8::from(Rs232BrickletFunction::CallbackRead))
264            .await
265            .map(|p| ReadEvent::from_le_byte_slice(p.body()))
266    }
267
268    /// This receiver is called if an error occurs.
269    /// Possible errors are overrun, parity or framing error.
270    ///
271    ///
272    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
273    pub async fn get_error_callback_receiver(&mut self) -> impl Stream<Item = u8> {
274        self.device.get_callback_receiver(u8::from(Rs232BrickletFunction::CallbackError)).await.map(|p| u8::from_le_byte_slice(p.body()))
275    }
276
277    /// This receiver is called if at least one frame of data is readable. The frame size is configured with [`set_frame_readable_callback_configuration`].
278    /// The frame count parameter is the number of frames that can be read.
279    /// This receiver is triggered only once until [`read`] or [`read_frame`] is called. This means, that if you have configured a frame size of X bytes,
280    /// you can read exactly X bytes using the [`read_frame`] function, every time the receiver triggers without checking the frame count parameter.
281    ///
282    ///
283    /// .. versionadded:: 2.0.4$nbsp;(Plugin)
284    pub async fn get_frame_readable_callback_receiver(&mut self) -> impl Stream<Item = u8> {
285        self.device
286            .get_callback_receiver(u8::from(Rs232BrickletFunction::CallbackFrameReadable))
287            .await
288            .map(|p| u8::from_le_byte_slice(p.body()))
289    }
290
291    /// Writes a string of up to 60 characters to the RS232 interface. The string
292    /// can be binary data, ASCII or similar is not necessary.
293    ///
294    /// The length of the string has to be given as an additional parameter.
295    ///
296    /// The return value is the number of bytes that could be written.
297    ///
298    /// See [`set_configuration`] for configuration possibilities
299    /// regarding baudrate, parity and so on.
300    pub async fn write(&mut self, message: &[char; 60], length: u8) -> Result<u8, TinkerforgeError> {
301        let mut payload = [0; 61];
302        message.write_to_slice(&mut payload[0..60]);
303        length.write_to_slice(&mut payload[60..61]);
304
305        #[allow(unused_variables)]
306        let result = self.device.get(u8::from(Rs232BrickletFunction::Write), &payload).await?;
307        Ok(u8::from_le_byte_slice(result.body()))
308    }
309
310    /// Returns the currently buffered message. The maximum length
311    /// of message is 60. If the returned length is 0, no new data was available.
312    ///
313    /// Instead of polling with this function, you can also use
314    /// callbacks. See [`enable_read_callback`] and [`get_read_callback_receiver`] receiver.
315    pub async fn read(&mut self) -> Result<Read, TinkerforgeError> {
316        let payload = [0; 0];
317
318        #[allow(unused_variables)]
319        let result = self.device.get(u8::from(Rs232BrickletFunction::Read), &payload).await?;
320        Ok(Read::from_le_byte_slice(result.body()))
321    }
322
323    /// Enables the [`get_read_callback_receiver`] receiver. This will disable the [`get_frame_readable_callback_receiver`] receiver.
324    ///
325    /// By default the receiver is disabled.
326    pub async fn enable_read_callback(&mut self) -> Result<(), TinkerforgeError> {
327        let payload = [0; 0];
328
329        #[allow(unused_variables)]
330        let result = self.device.set(u8::from(Rs232BrickletFunction::EnableReadCallback), &payload).await?;
331        Ok(())
332    }
333
334    /// Disables the [`get_read_callback_receiver`] receiver.
335    ///
336    /// By default the receiver is disabled.
337    pub async fn disable_read_callback(&mut self) -> Result<(), TinkerforgeError> {
338        let payload = [0; 0];
339
340        #[allow(unused_variables)]
341        let result = self.device.set(u8::from(Rs232BrickletFunction::DisableReadCallback), &payload).await?;
342        Ok(())
343    }
344
345    /// Returns *true* if the [`get_read_callback_receiver`] receiver is enabled,
346    /// *false* otherwise.
347    pub async fn is_read_callback_enabled(&mut self) -> Result<bool, TinkerforgeError> {
348        let payload = [0; 0];
349
350        #[allow(unused_variables)]
351        let result = self.device.get(u8::from(Rs232BrickletFunction::IsReadCallbackEnabled), &payload).await?;
352        Ok(bool::from_le_byte_slice(result.body()))
353    }
354
355    /// Sets the configuration for the RS232 communication.
356    ///
357    /// Hard-/Software flow control can either be on or off but not both simultaneously on.
358    ///
359    /// Associated constants:
360    /// * RS232_BRICKLET_BAUDRATE_300
361    ///	* RS232_BRICKLET_BAUDRATE_600
362    ///	* RS232_BRICKLET_BAUDRATE_1200
363    ///	* RS232_BRICKLET_BAUDRATE_2400
364    ///	* RS232_BRICKLET_BAUDRATE_4800
365    ///	* RS232_BRICKLET_BAUDRATE_9600
366    ///	* RS232_BRICKLET_BAUDRATE_14400
367    ///	* RS232_BRICKLET_BAUDRATE_19200
368    ///	* RS232_BRICKLET_BAUDRATE_28800
369    ///	* RS232_BRICKLET_BAUDRATE_38400
370    ///	* RS232_BRICKLET_BAUDRATE_57600
371    ///	* RS232_BRICKLET_BAUDRATE_115200
372    ///	* RS232_BRICKLET_BAUDRATE_230400
373    ///	* RS232_BRICKLET_PARITY_NONE
374    ///	* RS232_BRICKLET_PARITY_ODD
375    ///	* RS232_BRICKLET_PARITY_EVEN
376    ///	* RS232_BRICKLET_PARITY_FORCED_PARITY_1
377    ///	* RS232_BRICKLET_PARITY_FORCED_PARITY_0
378    ///	* RS232_BRICKLET_STOPBITS_1
379    ///	* RS232_BRICKLET_STOPBITS_2
380    ///	* RS232_BRICKLET_WORDLENGTH_5
381    ///	* RS232_BRICKLET_WORDLENGTH_6
382    ///	* RS232_BRICKLET_WORDLENGTH_7
383    ///	* RS232_BRICKLET_WORDLENGTH_8
384    ///	* RS232_BRICKLET_HARDWARE_FLOWCONTROL_OFF
385    ///	* RS232_BRICKLET_HARDWARE_FLOWCONTROL_ON
386    ///	* RS232_BRICKLET_SOFTWARE_FLOWCONTROL_OFF
387    ///	* RS232_BRICKLET_SOFTWARE_FLOWCONTROL_ON
388    pub async fn set_configuration(
389        &mut self,
390        baudrate: u8,
391        parity: u8,
392        stopbits: u8,
393        wordlength: u8,
394        hardware_flowcontrol: u8,
395        software_flowcontrol: u8,
396    ) -> Result<(), TinkerforgeError> {
397        let mut payload = [0; 6];
398        baudrate.write_to_slice(&mut payload[0..1]);
399        parity.write_to_slice(&mut payload[1..2]);
400        stopbits.write_to_slice(&mut payload[2..3]);
401        wordlength.write_to_slice(&mut payload[3..4]);
402        hardware_flowcontrol.write_to_slice(&mut payload[4..5]);
403        software_flowcontrol.write_to_slice(&mut payload[5..6]);
404
405        #[allow(unused_variables)]
406        let result = self.device.set(u8::from(Rs232BrickletFunction::SetConfiguration), &payload).await?;
407        Ok(())
408    }
409
410    /// Returns the configuration as set by [`set_configuration`].
411    ///
412    /// Associated constants:
413    /// * RS232_BRICKLET_BAUDRATE_300
414    ///	* RS232_BRICKLET_BAUDRATE_600
415    ///	* RS232_BRICKLET_BAUDRATE_1200
416    ///	* RS232_BRICKLET_BAUDRATE_2400
417    ///	* RS232_BRICKLET_BAUDRATE_4800
418    ///	* RS232_BRICKLET_BAUDRATE_9600
419    ///	* RS232_BRICKLET_BAUDRATE_14400
420    ///	* RS232_BRICKLET_BAUDRATE_19200
421    ///	* RS232_BRICKLET_BAUDRATE_28800
422    ///	* RS232_BRICKLET_BAUDRATE_38400
423    ///	* RS232_BRICKLET_BAUDRATE_57600
424    ///	* RS232_BRICKLET_BAUDRATE_115200
425    ///	* RS232_BRICKLET_BAUDRATE_230400
426    ///	* RS232_BRICKLET_PARITY_NONE
427    ///	* RS232_BRICKLET_PARITY_ODD
428    ///	* RS232_BRICKLET_PARITY_EVEN
429    ///	* RS232_BRICKLET_PARITY_FORCED_PARITY_1
430    ///	* RS232_BRICKLET_PARITY_FORCED_PARITY_0
431    ///	* RS232_BRICKLET_STOPBITS_1
432    ///	* RS232_BRICKLET_STOPBITS_2
433    ///	* RS232_BRICKLET_WORDLENGTH_5
434    ///	* RS232_BRICKLET_WORDLENGTH_6
435    ///	* RS232_BRICKLET_WORDLENGTH_7
436    ///	* RS232_BRICKLET_WORDLENGTH_8
437    ///	* RS232_BRICKLET_HARDWARE_FLOWCONTROL_OFF
438    ///	* RS232_BRICKLET_HARDWARE_FLOWCONTROL_ON
439    ///	* RS232_BRICKLET_SOFTWARE_FLOWCONTROL_OFF
440    ///	* RS232_BRICKLET_SOFTWARE_FLOWCONTROL_ON
441    pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
442        let payload = [0; 0];
443
444        #[allow(unused_variables)]
445        let result = self.device.get(u8::from(Rs232BrickletFunction::GetConfiguration), &payload).await?;
446        Ok(Configuration::from_le_byte_slice(result.body()))
447    }
448
449    /// Sets a break condition (the TX output is forced to a logic 0 state).
450    /// The parameter sets the hold-time of the break condition.
451    ///
452    ///
453    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
454    pub async fn set_break_condition(&mut self, break_time: u16) -> Result<(), TinkerforgeError> {
455        let mut payload = [0; 2];
456        break_time.write_to_slice(&mut payload[0..2]);
457
458        #[allow(unused_variables)]
459        let result = self.device.set(u8::from(Rs232BrickletFunction::SetBreakCondition), &payload).await?;
460        Ok(())
461    }
462
463    /// Configures the [`get_frame_readable_callback_receiver`] receiver. The frame size is the number of bytes, that have to be readable to trigger the receiver.
464    /// A frame size of 0 disables the receiver. A frame size greater than 0 enables the receiver and disables the [`get_read_callback_receiver`] receiver.
465    ///
466    /// By default the receiver is disabled.
467    ///
468    ///
469    /// .. versionadded:: 2.0.4$nbsp;(Plugin)
470    pub async fn set_frame_readable_callback_configuration(&mut self, frame_size: u8) -> Result<(), TinkerforgeError> {
471        let mut payload = [0; 1];
472        frame_size.write_to_slice(&mut payload[0..1]);
473
474        #[allow(unused_variables)]
475        let result = self.device.set(u8::from(Rs232BrickletFunction::SetFrameReadableCallbackConfiguration), &payload).await?;
476        Ok(())
477    }
478
479    /// Returns the receiver configuration as set by [`set_frame_readable_callback_configuration`].
480    ///
481    ///
482    /// .. versionadded:: 2.0.4$nbsp;(Plugin)
483    pub async fn get_frame_readable_callback_configuration(&mut self) -> Result<u8, TinkerforgeError> {
484        let payload = [0; 0];
485
486        #[allow(unused_variables)]
487        let result = self.device.get(u8::from(Rs232BrickletFunction::GetFrameReadableCallbackConfiguration), &payload).await?;
488        Ok(u8::from_le_byte_slice(result.body()))
489    }
490
491    /// Returns up to one frame of bytes from the read buffer.
492    /// The frame size is configured with [`set_frame_readable_callback_configuration`].
493    /// If the returned length is 0, no new data was available.
494    ///
495    ///
496    /// .. versionadded:: 2.0.4$nbsp;(Plugin)
497    pub async fn read_frame(&mut self) -> Result<ReadFrame, TinkerforgeError> {
498        let payload = [0; 0];
499
500        #[allow(unused_variables)]
501        let result = self.device.get(u8::from(Rs232BrickletFunction::ReadFrame), &payload).await?;
502        Ok(ReadFrame::from_le_byte_slice(result.body()))
503    }
504
505    /// Returns the UID, the UID where the Bricklet is connected to,
506    /// the position, the hardware and firmware version as well as the
507    /// device identifier.
508    ///
509    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
510    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
511    /// position 'z'.
512    ///
513    /// The device identifier numbers can be found [here](device_identifier).
514    /// |device_identifier_constant|
515    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
516        let payload = [0; 0];
517
518        #[allow(unused_variables)]
519        let result = self.device.get(u8::from(Rs232BrickletFunction::GetIdentity), &payload).await?;
520        Ok(Identity::from_le_byte_slice(result.body()))
521    }
522}