tinkerforge_async/bindings/
rs485_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 RS485/Modbus devices with full- or half-duplex.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/RS485_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, converting_high_level_callback_receiver::ConvertingHighLevelCallbackReceiver,
17    converting_receiver::BrickletRecvTimeoutError, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
18    low_level_traits::LowLevelRead,
19};
20#[allow(unused_imports)]
21use futures_core::Stream;
22#[allow(unused_imports)]
23use tokio_stream::StreamExt;
24pub enum Rs485BrickletFunction {
25    WriteLowLevel,
26    ReadLowLevel,
27    EnableReadCallback,
28    DisableReadCallback,
29    IsReadCallbackEnabled,
30    SetRs485Configuration,
31    GetRs485Configuration,
32    SetModbusConfiguration,
33    GetModbusConfiguration,
34    SetMode,
35    GetMode,
36    SetCommunicationLedConfig,
37    GetCommunicationLedConfig,
38    SetErrorLedConfig,
39    GetErrorLedConfig,
40    SetBufferConfig,
41    GetBufferConfig,
42    GetBufferStatus,
43    EnableErrorCountCallback,
44    DisableErrorCountCallback,
45    IsErrorCountCallbackEnabled,
46    GetErrorCount,
47    GetModbusCommonErrorCount,
48    ModbusSlaveReportException,
49    ModbusSlaveAnswerReadCoilsRequestLowLevel,
50    ModbusMasterReadCoils,
51    ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel,
52    ModbusMasterReadHoldingRegisters,
53    ModbusSlaveAnswerWriteSingleCoilRequest,
54    ModbusMasterWriteSingleCoil,
55    ModbusSlaveAnswerWriteSingleRegisterRequest,
56    ModbusMasterWriteSingleRegister,
57    ModbusSlaveAnswerWriteMultipleCoilsRequest,
58    ModbusMasterWriteMultipleCoilsLowLevel,
59    ModbusSlaveAnswerWriteMultipleRegistersRequest,
60    ModbusMasterWriteMultipleRegistersLowLevel,
61    ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel,
62    ModbusMasterReadDiscreteInputs,
63    ModbusSlaveAnswerReadInputRegistersRequestLowLevel,
64    ModbusMasterReadInputRegisters,
65    SetFrameReadableCallbackConfiguration,
66    GetFrameReadableCallbackConfiguration,
67    GetSpitfpErrorCount,
68    SetBootloaderMode,
69    GetBootloaderMode,
70    SetWriteFirmwarePointer,
71    WriteFirmware,
72    SetStatusLedConfig,
73    GetStatusLedConfig,
74    GetChipTemperature,
75    Reset,
76    WriteUid,
77    ReadUid,
78    GetIdentity,
79    CallbackReadLowLevel,
80    CallbackErrorCount,
81    CallbackModbusSlaveReadCoilsRequest,
82    CallbackModbusMasterReadCoilsResponseLowLevel,
83    CallbackModbusSlaveReadHoldingRegistersRequest,
84    CallbackModbusMasterReadHoldingRegistersResponseLowLevel,
85    CallbackModbusSlaveWriteSingleCoilRequest,
86    CallbackModbusMasterWriteSingleCoilResponse,
87    CallbackModbusSlaveWriteSingleRegisterRequest,
88    CallbackModbusMasterWriteSingleRegisterResponse,
89    CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel,
90    CallbackModbusMasterWriteMultipleCoilsResponse,
91    CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel,
92    CallbackModbusMasterWriteMultipleRegistersResponse,
93    CallbackModbusSlaveReadDiscreteInputsRequest,
94    CallbackModbusMasterReadDiscreteInputsResponseLowLevel,
95    CallbackModbusSlaveReadInputRegistersRequest,
96    CallbackModbusMasterReadInputRegistersResponseLowLevel,
97    CallbackFrameReadable,
98}
99impl From<Rs485BrickletFunction> for u8 {
100    fn from(fun: Rs485BrickletFunction) -> Self {
101        match fun {
102            Rs485BrickletFunction::WriteLowLevel => 1,
103            Rs485BrickletFunction::ReadLowLevel => 2,
104            Rs485BrickletFunction::EnableReadCallback => 3,
105            Rs485BrickletFunction::DisableReadCallback => 4,
106            Rs485BrickletFunction::IsReadCallbackEnabled => 5,
107            Rs485BrickletFunction::SetRs485Configuration => 6,
108            Rs485BrickletFunction::GetRs485Configuration => 7,
109            Rs485BrickletFunction::SetModbusConfiguration => 8,
110            Rs485BrickletFunction::GetModbusConfiguration => 9,
111            Rs485BrickletFunction::SetMode => 10,
112            Rs485BrickletFunction::GetMode => 11,
113            Rs485BrickletFunction::SetCommunicationLedConfig => 12,
114            Rs485BrickletFunction::GetCommunicationLedConfig => 13,
115            Rs485BrickletFunction::SetErrorLedConfig => 14,
116            Rs485BrickletFunction::GetErrorLedConfig => 15,
117            Rs485BrickletFunction::SetBufferConfig => 16,
118            Rs485BrickletFunction::GetBufferConfig => 17,
119            Rs485BrickletFunction::GetBufferStatus => 18,
120            Rs485BrickletFunction::EnableErrorCountCallback => 19,
121            Rs485BrickletFunction::DisableErrorCountCallback => 20,
122            Rs485BrickletFunction::IsErrorCountCallbackEnabled => 21,
123            Rs485BrickletFunction::GetErrorCount => 22,
124            Rs485BrickletFunction::GetModbusCommonErrorCount => 23,
125            Rs485BrickletFunction::ModbusSlaveReportException => 24,
126            Rs485BrickletFunction::ModbusSlaveAnswerReadCoilsRequestLowLevel => 25,
127            Rs485BrickletFunction::ModbusMasterReadCoils => 26,
128            Rs485BrickletFunction::ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel => 27,
129            Rs485BrickletFunction::ModbusMasterReadHoldingRegisters => 28,
130            Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleCoilRequest => 29,
131            Rs485BrickletFunction::ModbusMasterWriteSingleCoil => 30,
132            Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleRegisterRequest => 31,
133            Rs485BrickletFunction::ModbusMasterWriteSingleRegister => 32,
134            Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleCoilsRequest => 33,
135            Rs485BrickletFunction::ModbusMasterWriteMultipleCoilsLowLevel => 34,
136            Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleRegistersRequest => 35,
137            Rs485BrickletFunction::ModbusMasterWriteMultipleRegistersLowLevel => 36,
138            Rs485BrickletFunction::ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel => 37,
139            Rs485BrickletFunction::ModbusMasterReadDiscreteInputs => 38,
140            Rs485BrickletFunction::ModbusSlaveAnswerReadInputRegistersRequestLowLevel => 39,
141            Rs485BrickletFunction::ModbusMasterReadInputRegisters => 40,
142            Rs485BrickletFunction::SetFrameReadableCallbackConfiguration => 59,
143            Rs485BrickletFunction::GetFrameReadableCallbackConfiguration => 60,
144            Rs485BrickletFunction::GetSpitfpErrorCount => 234,
145            Rs485BrickletFunction::SetBootloaderMode => 235,
146            Rs485BrickletFunction::GetBootloaderMode => 236,
147            Rs485BrickletFunction::SetWriteFirmwarePointer => 237,
148            Rs485BrickletFunction::WriteFirmware => 238,
149            Rs485BrickletFunction::SetStatusLedConfig => 239,
150            Rs485BrickletFunction::GetStatusLedConfig => 240,
151            Rs485BrickletFunction::GetChipTemperature => 242,
152            Rs485BrickletFunction::Reset => 243,
153            Rs485BrickletFunction::WriteUid => 248,
154            Rs485BrickletFunction::ReadUid => 249,
155            Rs485BrickletFunction::GetIdentity => 255,
156            Rs485BrickletFunction::CallbackReadLowLevel => 41,
157            Rs485BrickletFunction::CallbackErrorCount => 42,
158            Rs485BrickletFunction::CallbackModbusSlaveReadCoilsRequest => 43,
159            Rs485BrickletFunction::CallbackModbusMasterReadCoilsResponseLowLevel => 44,
160            Rs485BrickletFunction::CallbackModbusSlaveReadHoldingRegistersRequest => 45,
161            Rs485BrickletFunction::CallbackModbusMasterReadHoldingRegistersResponseLowLevel => 46,
162            Rs485BrickletFunction::CallbackModbusSlaveWriteSingleCoilRequest => 47,
163            Rs485BrickletFunction::CallbackModbusMasterWriteSingleCoilResponse => 48,
164            Rs485BrickletFunction::CallbackModbusSlaveWriteSingleRegisterRequest => 49,
165            Rs485BrickletFunction::CallbackModbusMasterWriteSingleRegisterResponse => 50,
166            Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel => 51,
167            Rs485BrickletFunction::CallbackModbusMasterWriteMultipleCoilsResponse => 52,
168            Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel => 53,
169            Rs485BrickletFunction::CallbackModbusMasterWriteMultipleRegistersResponse => 54,
170            Rs485BrickletFunction::CallbackModbusSlaveReadDiscreteInputsRequest => 55,
171            Rs485BrickletFunction::CallbackModbusMasterReadDiscreteInputsResponseLowLevel => 56,
172            Rs485BrickletFunction::CallbackModbusSlaveReadInputRegistersRequest => 57,
173            Rs485BrickletFunction::CallbackModbusMasterReadInputRegistersResponseLowLevel => 58,
174            Rs485BrickletFunction::CallbackFrameReadable => 61,
175        }
176    }
177}
178pub const RS485_BRICKLET_PARITY_NONE: u8 = 0;
179pub const RS485_BRICKLET_PARITY_ODD: u8 = 1;
180pub const RS485_BRICKLET_PARITY_EVEN: u8 = 2;
181pub const RS485_BRICKLET_STOPBITS_1: u8 = 1;
182pub const RS485_BRICKLET_STOPBITS_2: u8 = 2;
183pub const RS485_BRICKLET_WORDLENGTH_5: u8 = 5;
184pub const RS485_BRICKLET_WORDLENGTH_6: u8 = 6;
185pub const RS485_BRICKLET_WORDLENGTH_7: u8 = 7;
186pub const RS485_BRICKLET_WORDLENGTH_8: u8 = 8;
187pub const RS485_BRICKLET_DUPLEX_HALF: u8 = 0;
188pub const RS485_BRICKLET_DUPLEX_FULL: u8 = 1;
189pub const RS485_BRICKLET_MODE_RS485: u8 = 0;
190pub const RS485_BRICKLET_MODE_MODBUS_MASTER_RTU: u8 = 1;
191pub const RS485_BRICKLET_MODE_MODBUS_SLAVE_RTU: u8 = 2;
192pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_OFF: u8 = 0;
193pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_ON: u8 = 1;
194pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
195pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION: u8 = 3;
196pub const RS485_BRICKLET_ERROR_LED_CONFIG_OFF: u8 = 0;
197pub const RS485_BRICKLET_ERROR_LED_CONFIG_ON: u8 = 1;
198pub const RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
199pub const RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR: u8 = 3;
200pub const RS485_BRICKLET_EXCEPTION_CODE_TIMEOUT: i8 = -1;
201pub const RS485_BRICKLET_EXCEPTION_CODE_SUCCESS: i8 = 0;
202pub const RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_FUNCTION: i8 = 1;
203pub const RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS: i8 = 2;
204pub const RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_VALUE: i8 = 3;
205pub const RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_FAILURE: i8 = 4;
206pub const RS485_BRICKLET_EXCEPTION_CODE_ACKNOWLEDGE: i8 = 5;
207pub const RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_BUSY: i8 = 6;
208pub const RS485_BRICKLET_EXCEPTION_CODE_MEMORY_PARITY_ERROR: i8 = 8;
209pub const RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE: i8 = 10;
210pub const RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: i8 = 11;
211pub const RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
212pub const RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
213pub const RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
214pub const RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
215pub const RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
216pub const RS485_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
217pub const RS485_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
218pub const RS485_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
219pub const RS485_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
220pub const RS485_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
221pub const RS485_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
222pub const RS485_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
223pub const RS485_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
224pub const RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
225pub const RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
226
227#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
228pub struct WriteLowLevel {
229    pub message_chunk_written: u8,
230}
231impl FromByteSlice for WriteLowLevel {
232    fn bytes_expected() -> usize {
233        1
234    }
235    fn from_le_byte_slice(bytes: &[u8]) -> WriteLowLevel {
236        WriteLowLevel { message_chunk_written: <u8>::from_le_byte_slice(&bytes[0..1]) }
237    }
238}
239
240#[derive(Clone, Copy)]
241pub struct ReadLowLevel {
242    pub message_length: u16,
243    pub message_chunk_offset: u16,
244    pub message_chunk_data: [char; 60],
245}
246impl FromByteSlice for ReadLowLevel {
247    fn bytes_expected() -> usize {
248        64
249    }
250    fn from_le_byte_slice(bytes: &[u8]) -> ReadLowLevel {
251        ReadLowLevel {
252            message_length: <u16>::from_le_byte_slice(&bytes[0..2]),
253            message_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
254            message_chunk_data: <[char; 60]>::from_le_byte_slice(&bytes[4..64]),
255        }
256    }
257}
258impl LowLevelRead<char, ReadResult> for ReadLowLevel {
259    fn ll_message_length(&self) -> usize {
260        self.message_length as usize
261    }
262
263    fn ll_message_chunk_offset(&self) -> usize {
264        self.message_chunk_offset as usize
265    }
266
267    fn ll_message_chunk_data(&self) -> &[char] {
268        &self.message_chunk_data
269    }
270
271    fn get_result(&self) -> ReadResult {
272        ReadResult {}
273    }
274}
275
276#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
277pub struct Rs485Configuration {
278    pub baudrate: u32,
279    pub parity: u8,
280    pub stopbits: u8,
281    pub wordlength: u8,
282    pub duplex: u8,
283}
284impl FromByteSlice for Rs485Configuration {
285    fn bytes_expected() -> usize {
286        8
287    }
288    fn from_le_byte_slice(bytes: &[u8]) -> Rs485Configuration {
289        Rs485Configuration {
290            baudrate: <u32>::from_le_byte_slice(&bytes[0..4]),
291            parity: <u8>::from_le_byte_slice(&bytes[4..5]),
292            stopbits: <u8>::from_le_byte_slice(&bytes[5..6]),
293            wordlength: <u8>::from_le_byte_slice(&bytes[6..7]),
294            duplex: <u8>::from_le_byte_slice(&bytes[7..8]),
295        }
296    }
297}
298
299#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
300pub struct ModbusConfiguration {
301    pub slave_address: u8,
302    pub master_request_timeout: u32,
303}
304impl FromByteSlice for ModbusConfiguration {
305    fn bytes_expected() -> usize {
306        5
307    }
308    fn from_le_byte_slice(bytes: &[u8]) -> ModbusConfiguration {
309        ModbusConfiguration {
310            slave_address: <u8>::from_le_byte_slice(&bytes[0..1]),
311            master_request_timeout: <u32>::from_le_byte_slice(&bytes[1..5]),
312        }
313    }
314}
315
316#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
317pub struct BufferConfig {
318    pub send_buffer_size: u16,
319    pub receive_buffer_size: u16,
320}
321impl FromByteSlice for BufferConfig {
322    fn bytes_expected() -> usize {
323        4
324    }
325    fn from_le_byte_slice(bytes: &[u8]) -> BufferConfig {
326        BufferConfig {
327            send_buffer_size: <u16>::from_le_byte_slice(&bytes[0..2]),
328            receive_buffer_size: <u16>::from_le_byte_slice(&bytes[2..4]),
329        }
330    }
331}
332
333#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
334pub struct BufferStatus {
335    pub send_buffer_used: u16,
336    pub receive_buffer_used: u16,
337}
338impl FromByteSlice for BufferStatus {
339    fn bytes_expected() -> usize {
340        4
341    }
342    fn from_le_byte_slice(bytes: &[u8]) -> BufferStatus {
343        BufferStatus {
344            send_buffer_used: <u16>::from_le_byte_slice(&bytes[0..2]),
345            receive_buffer_used: <u16>::from_le_byte_slice(&bytes[2..4]),
346        }
347    }
348}
349
350#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
351pub struct ErrorCount {
352    pub overrun_error_count: u32,
353    pub parity_error_count: u32,
354}
355impl FromByteSlice for ErrorCount {
356    fn bytes_expected() -> usize {
357        8
358    }
359    fn from_le_byte_slice(bytes: &[u8]) -> ErrorCount {
360        ErrorCount {
361            overrun_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
362            parity_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
363        }
364    }
365}
366
367#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
368pub struct ModbusCommonErrorCount {
369    pub timeout_error_count: u32,
370    pub checksum_error_count: u32,
371    pub frame_too_big_error_count: u32,
372    pub illegal_function_error_count: u32,
373    pub illegal_data_address_error_count: u32,
374    pub illegal_data_value_error_count: u32,
375    pub slave_device_failure_error_count: u32,
376}
377impl FromByteSlice for ModbusCommonErrorCount {
378    fn bytes_expected() -> usize {
379        28
380    }
381    fn from_le_byte_slice(bytes: &[u8]) -> ModbusCommonErrorCount {
382        ModbusCommonErrorCount {
383            timeout_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
384            checksum_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
385            frame_too_big_error_count: <u32>::from_le_byte_slice(&bytes[8..12]),
386            illegal_function_error_count: <u32>::from_le_byte_slice(&bytes[12..16]),
387            illegal_data_address_error_count: <u32>::from_le_byte_slice(&bytes[16..20]),
388            illegal_data_value_error_count: <u32>::from_le_byte_slice(&bytes[20..24]),
389            slave_device_failure_error_count: <u32>::from_le_byte_slice(&bytes[24..28]),
390        }
391    }
392}
393
394#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
395pub struct ModbusSlaveAnswerReadCoilsRequestLowLevel {}
396impl FromByteSlice for ModbusSlaveAnswerReadCoilsRequestLowLevel {
397    fn bytes_expected() -> usize {
398        0
399    }
400    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadCoilsRequestLowLevel {
401        ModbusSlaveAnswerReadCoilsRequestLowLevel {}
402    }
403}
404
405#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
406pub struct ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {}
407impl FromByteSlice for ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {
408    fn bytes_expected() -> usize {
409        0
410    }
411    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {
412        ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {}
413    }
414}
415
416#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
417pub struct ModbusMasterWriteMultipleCoilsLowLevel {
418    pub request_id: u8,
419}
420impl FromByteSlice for ModbusMasterWriteMultipleCoilsLowLevel {
421    fn bytes_expected() -> usize {
422        1
423    }
424    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleCoilsLowLevel {
425        ModbusMasterWriteMultipleCoilsLowLevel { request_id: <u8>::from_le_byte_slice(&bytes[0..1]) }
426    }
427}
428
429#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
430pub struct ModbusMasterWriteMultipleRegistersLowLevel {
431    pub request_id: u8,
432}
433impl FromByteSlice for ModbusMasterWriteMultipleRegistersLowLevel {
434    fn bytes_expected() -> usize {
435        1
436    }
437    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleRegistersLowLevel {
438        ModbusMasterWriteMultipleRegistersLowLevel { request_id: <u8>::from_le_byte_slice(&bytes[0..1]) }
439    }
440}
441
442#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
443pub struct ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {}
444impl FromByteSlice for ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {
445    fn bytes_expected() -> usize {
446        0
447    }
448    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {
449        ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {}
450    }
451}
452
453#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
454pub struct ModbusSlaveAnswerReadInputRegistersRequestLowLevel {}
455impl FromByteSlice for ModbusSlaveAnswerReadInputRegistersRequestLowLevel {
456    fn bytes_expected() -> usize {
457        0
458    }
459    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadInputRegistersRequestLowLevel {
460        ModbusSlaveAnswerReadInputRegistersRequestLowLevel {}
461    }
462}
463
464#[derive(Clone, Copy)]
465pub struct ReadLowLevelEvent {
466    pub message_length: u16,
467    pub message_chunk_offset: u16,
468    pub message_chunk_data: [char; 60],
469}
470impl FromByteSlice for ReadLowLevelEvent {
471    fn bytes_expected() -> usize {
472        64
473    }
474    fn from_le_byte_slice(bytes: &[u8]) -> ReadLowLevelEvent {
475        ReadLowLevelEvent {
476            message_length: <u16>::from_le_byte_slice(&bytes[0..2]),
477            message_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
478            message_chunk_data: <[char; 60]>::from_le_byte_slice(&bytes[4..64]),
479        }
480    }
481}
482impl LowLevelRead<char, ReadResult> for ReadLowLevelEvent {
483    fn ll_message_length(&self) -> usize {
484        self.message_length as usize
485    }
486
487    fn ll_message_chunk_offset(&self) -> usize {
488        self.message_chunk_offset as usize
489    }
490
491    fn ll_message_chunk_data(&self) -> &[char] {
492        &self.message_chunk_data
493    }
494
495    fn get_result(&self) -> ReadResult {
496        ReadResult {}
497    }
498}
499
500#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
501pub struct ErrorCountEvent {
502    pub overrun_error_count: u32,
503    pub parity_error_count: u32,
504}
505impl FromByteSlice for ErrorCountEvent {
506    fn bytes_expected() -> usize {
507        8
508    }
509    fn from_le_byte_slice(bytes: &[u8]) -> ErrorCountEvent {
510        ErrorCountEvent {
511            overrun_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
512            parity_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
513        }
514    }
515}
516
517#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
518pub struct ModbusSlaveReadCoilsRequestEvent {
519    pub request_id: u8,
520    pub starting_address: u32,
521    pub count: u16,
522}
523impl FromByteSlice for ModbusSlaveReadCoilsRequestEvent {
524    fn bytes_expected() -> usize {
525        7
526    }
527    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadCoilsRequestEvent {
528        ModbusSlaveReadCoilsRequestEvent {
529            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
530            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
531            count: <u16>::from_le_byte_slice(&bytes[5..7]),
532        }
533    }
534}
535
536#[derive(Clone, Copy)]
537pub struct ModbusMasterReadCoilsResponseLowLevelEvent {
538    pub request_id: u8,
539    pub exception_code: i8,
540    pub coils_length: u16,
541    pub coils_chunk_offset: u16,
542    pub coils_chunk_data: [bool; 464],
543}
544impl FromByteSlice for ModbusMasterReadCoilsResponseLowLevelEvent {
545    fn bytes_expected() -> usize {
546        64
547    }
548    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadCoilsResponseLowLevelEvent {
549        ModbusMasterReadCoilsResponseLowLevelEvent {
550            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
551            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
552            coils_length: <u16>::from_le_byte_slice(&bytes[2..4]),
553            coils_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
554            coils_chunk_data: <[bool; 464]>::from_le_byte_slice(&bytes[6..64]),
555        }
556    }
557}
558impl LowLevelRead<bool, ModbusMasterReadCoilsResponseResult> for ModbusMasterReadCoilsResponseLowLevelEvent {
559    fn ll_message_length(&self) -> usize {
560        self.coils_length as usize
561    }
562
563    fn ll_message_chunk_offset(&self) -> usize {
564        self.coils_chunk_offset as usize
565    }
566
567    fn ll_message_chunk_data(&self) -> &[bool] {
568        &self.coils_chunk_data
569    }
570
571    fn get_result(&self) -> ModbusMasterReadCoilsResponseResult {
572        ModbusMasterReadCoilsResponseResult { request_id: self.request_id, exception_code: self.exception_code }
573    }
574}
575
576#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
577pub struct ModbusSlaveReadHoldingRegistersRequestEvent {
578    pub request_id: u8,
579    pub starting_address: u32,
580    pub count: u16,
581}
582impl FromByteSlice for ModbusSlaveReadHoldingRegistersRequestEvent {
583    fn bytes_expected() -> usize {
584        7
585    }
586    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadHoldingRegistersRequestEvent {
587        ModbusSlaveReadHoldingRegistersRequestEvent {
588            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
589            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
590            count: <u16>::from_le_byte_slice(&bytes[5..7]),
591        }
592    }
593}
594
595#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
596pub struct ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
597    pub request_id: u8,
598    pub exception_code: i8,
599    pub holding_registers_length: u16,
600    pub holding_registers_chunk_offset: u16,
601    pub holding_registers_chunk_data: [u16; 29],
602}
603impl FromByteSlice for ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
604    fn bytes_expected() -> usize {
605        64
606    }
607    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
608        ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
609            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
610            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
611            holding_registers_length: <u16>::from_le_byte_slice(&bytes[2..4]),
612            holding_registers_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
613            holding_registers_chunk_data: <[u16; 29]>::from_le_byte_slice(&bytes[6..64]),
614        }
615    }
616}
617impl LowLevelRead<u16, ModbusMasterReadHoldingRegistersResponseResult> for ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
618    fn ll_message_length(&self) -> usize {
619        self.holding_registers_length as usize
620    }
621
622    fn ll_message_chunk_offset(&self) -> usize {
623        self.holding_registers_chunk_offset as usize
624    }
625
626    fn ll_message_chunk_data(&self) -> &[u16] {
627        &self.holding_registers_chunk_data
628    }
629
630    fn get_result(&self) -> ModbusMasterReadHoldingRegistersResponseResult {
631        ModbusMasterReadHoldingRegistersResponseResult { request_id: self.request_id, exception_code: self.exception_code }
632    }
633}
634
635#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
636pub struct ModbusSlaveWriteSingleCoilRequestEvent {
637    pub request_id: u8,
638    pub coil_address: u32,
639    pub coil_value: bool,
640}
641impl FromByteSlice for ModbusSlaveWriteSingleCoilRequestEvent {
642    fn bytes_expected() -> usize {
643        6
644    }
645    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteSingleCoilRequestEvent {
646        ModbusSlaveWriteSingleCoilRequestEvent {
647            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
648            coil_address: <u32>::from_le_byte_slice(&bytes[1..5]),
649            coil_value: <bool>::from_le_byte_slice(&bytes[5..6]),
650        }
651    }
652}
653
654#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
655pub struct ModbusMasterWriteSingleCoilResponseEvent {
656    pub request_id: u8,
657    pub exception_code: i8,
658}
659impl FromByteSlice for ModbusMasterWriteSingleCoilResponseEvent {
660    fn bytes_expected() -> usize {
661        2
662    }
663    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteSingleCoilResponseEvent {
664        ModbusMasterWriteSingleCoilResponseEvent {
665            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
666            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
667        }
668    }
669}
670
671#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
672pub struct ModbusSlaveWriteSingleRegisterRequestEvent {
673    pub request_id: u8,
674    pub register_address: u32,
675    pub register_value: u16,
676}
677impl FromByteSlice for ModbusSlaveWriteSingleRegisterRequestEvent {
678    fn bytes_expected() -> usize {
679        7
680    }
681    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteSingleRegisterRequestEvent {
682        ModbusSlaveWriteSingleRegisterRequestEvent {
683            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
684            register_address: <u32>::from_le_byte_slice(&bytes[1..5]),
685            register_value: <u16>::from_le_byte_slice(&bytes[5..7]),
686        }
687    }
688}
689
690#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
691pub struct ModbusMasterWriteSingleRegisterResponseEvent {
692    pub request_id: u8,
693    pub exception_code: i8,
694}
695impl FromByteSlice for ModbusMasterWriteSingleRegisterResponseEvent {
696    fn bytes_expected() -> usize {
697        2
698    }
699    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteSingleRegisterResponseEvent {
700        ModbusMasterWriteSingleRegisterResponseEvent {
701            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
702            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
703        }
704    }
705}
706
707#[derive(Clone, Copy)]
708pub struct ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
709    pub request_id: u8,
710    pub starting_address: u32,
711    pub coils_length: u16,
712    pub coils_chunk_offset: u16,
713    pub coils_chunk_data: [bool; 440],
714}
715impl FromByteSlice for ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
716    fn bytes_expected() -> usize {
717        64
718    }
719    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
720        ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
721            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
722            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
723            coils_length: <u16>::from_le_byte_slice(&bytes[5..7]),
724            coils_chunk_offset: <u16>::from_le_byte_slice(&bytes[7..9]),
725            coils_chunk_data: <[bool; 440]>::from_le_byte_slice(&bytes[9..64]),
726        }
727    }
728}
729impl LowLevelRead<bool, ModbusSlaveWriteMultipleCoilsRequestResult> for ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
730    fn ll_message_length(&self) -> usize {
731        self.coils_length as usize
732    }
733
734    fn ll_message_chunk_offset(&self) -> usize {
735        self.coils_chunk_offset as usize
736    }
737
738    fn ll_message_chunk_data(&self) -> &[bool] {
739        &self.coils_chunk_data
740    }
741
742    fn get_result(&self) -> ModbusSlaveWriteMultipleCoilsRequestResult {
743        ModbusSlaveWriteMultipleCoilsRequestResult { request_id: self.request_id, starting_address: self.starting_address }
744    }
745}
746
747#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
748pub struct ModbusMasterWriteMultipleCoilsResponseEvent {
749    pub request_id: u8,
750    pub exception_code: i8,
751}
752impl FromByteSlice for ModbusMasterWriteMultipleCoilsResponseEvent {
753    fn bytes_expected() -> usize {
754        2
755    }
756    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleCoilsResponseEvent {
757        ModbusMasterWriteMultipleCoilsResponseEvent {
758            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
759            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
760        }
761    }
762}
763
764#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
765pub struct ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
766    pub request_id: u8,
767    pub starting_address: u32,
768    pub registers_length: u16,
769    pub registers_chunk_offset: u16,
770    pub registers_chunk_data: [u16; 27],
771}
772impl FromByteSlice for ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
773    fn bytes_expected() -> usize {
774        63
775    }
776    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
777        ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
778            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
779            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
780            registers_length: <u16>::from_le_byte_slice(&bytes[5..7]),
781            registers_chunk_offset: <u16>::from_le_byte_slice(&bytes[7..9]),
782            registers_chunk_data: <[u16; 27]>::from_le_byte_slice(&bytes[9..63]),
783        }
784    }
785}
786impl LowLevelRead<u16, ModbusSlaveWriteMultipleRegistersRequestResult> for ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
787    fn ll_message_length(&self) -> usize {
788        self.registers_length as usize
789    }
790
791    fn ll_message_chunk_offset(&self) -> usize {
792        self.registers_chunk_offset as usize
793    }
794
795    fn ll_message_chunk_data(&self) -> &[u16] {
796        &self.registers_chunk_data
797    }
798
799    fn get_result(&self) -> ModbusSlaveWriteMultipleRegistersRequestResult {
800        ModbusSlaveWriteMultipleRegistersRequestResult { request_id: self.request_id, starting_address: self.starting_address }
801    }
802}
803
804#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
805pub struct ModbusMasterWriteMultipleRegistersResponseEvent {
806    pub request_id: u8,
807    pub exception_code: i8,
808}
809impl FromByteSlice for ModbusMasterWriteMultipleRegistersResponseEvent {
810    fn bytes_expected() -> usize {
811        2
812    }
813    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleRegistersResponseEvent {
814        ModbusMasterWriteMultipleRegistersResponseEvent {
815            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
816            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
817        }
818    }
819}
820
821#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
822pub struct ModbusSlaveReadDiscreteInputsRequestEvent {
823    pub request_id: u8,
824    pub starting_address: u32,
825    pub count: u16,
826}
827impl FromByteSlice for ModbusSlaveReadDiscreteInputsRequestEvent {
828    fn bytes_expected() -> usize {
829        7
830    }
831    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadDiscreteInputsRequestEvent {
832        ModbusSlaveReadDiscreteInputsRequestEvent {
833            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
834            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
835            count: <u16>::from_le_byte_slice(&bytes[5..7]),
836        }
837    }
838}
839
840#[derive(Clone, Copy)]
841pub struct ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
842    pub request_id: u8,
843    pub exception_code: i8,
844    pub discrete_inputs_length: u16,
845    pub discrete_inputs_chunk_offset: u16,
846    pub discrete_inputs_chunk_data: [bool; 464],
847}
848impl FromByteSlice for ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
849    fn bytes_expected() -> usize {
850        64
851    }
852    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
853        ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
854            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
855            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
856            discrete_inputs_length: <u16>::from_le_byte_slice(&bytes[2..4]),
857            discrete_inputs_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
858            discrete_inputs_chunk_data: <[bool; 464]>::from_le_byte_slice(&bytes[6..64]),
859        }
860    }
861}
862impl LowLevelRead<bool, ModbusMasterReadDiscreteInputsResponseResult> for ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
863    fn ll_message_length(&self) -> usize {
864        self.discrete_inputs_length as usize
865    }
866
867    fn ll_message_chunk_offset(&self) -> usize {
868        self.discrete_inputs_chunk_offset as usize
869    }
870
871    fn ll_message_chunk_data(&self) -> &[bool] {
872        &self.discrete_inputs_chunk_data
873    }
874
875    fn get_result(&self) -> ModbusMasterReadDiscreteInputsResponseResult {
876        ModbusMasterReadDiscreteInputsResponseResult { request_id: self.request_id, exception_code: self.exception_code }
877    }
878}
879
880#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
881pub struct ModbusSlaveReadInputRegistersRequestEvent {
882    pub request_id: u8,
883    pub starting_address: u32,
884    pub count: u16,
885}
886impl FromByteSlice for ModbusSlaveReadInputRegistersRequestEvent {
887    fn bytes_expected() -> usize {
888        7
889    }
890    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadInputRegistersRequestEvent {
891        ModbusSlaveReadInputRegistersRequestEvent {
892            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
893            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
894            count: <u16>::from_le_byte_slice(&bytes[5..7]),
895        }
896    }
897}
898
899#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
900pub struct ModbusMasterReadInputRegistersResponseLowLevelEvent {
901    pub request_id: u8,
902    pub exception_code: i8,
903    pub input_registers_length: u16,
904    pub input_registers_chunk_offset: u16,
905    pub input_registers_chunk_data: [u16; 29],
906}
907impl FromByteSlice for ModbusMasterReadInputRegistersResponseLowLevelEvent {
908    fn bytes_expected() -> usize {
909        64
910    }
911    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadInputRegistersResponseLowLevelEvent {
912        ModbusMasterReadInputRegistersResponseLowLevelEvent {
913            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
914            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
915            input_registers_length: <u16>::from_le_byte_slice(&bytes[2..4]),
916            input_registers_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
917            input_registers_chunk_data: <[u16; 29]>::from_le_byte_slice(&bytes[6..64]),
918        }
919    }
920}
921impl LowLevelRead<u16, ModbusMasterReadInputRegistersResponseResult> for ModbusMasterReadInputRegistersResponseLowLevelEvent {
922    fn ll_message_length(&self) -> usize {
923        self.input_registers_length as usize
924    }
925
926    fn ll_message_chunk_offset(&self) -> usize {
927        self.input_registers_chunk_offset as usize
928    }
929
930    fn ll_message_chunk_data(&self) -> &[u16] {
931        &self.input_registers_chunk_data
932    }
933
934    fn get_result(&self) -> ModbusMasterReadInputRegistersResponseResult {
935        ModbusMasterReadInputRegistersResponseResult { request_id: self.request_id, exception_code: self.exception_code }
936    }
937}
938
939#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
940pub struct SpitfpErrorCount {
941    pub error_count_ack_checksum: u32,
942    pub error_count_message_checksum: u32,
943    pub error_count_frame: u32,
944    pub error_count_overflow: u32,
945}
946impl FromByteSlice for SpitfpErrorCount {
947    fn bytes_expected() -> usize {
948        16
949    }
950    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
951        SpitfpErrorCount {
952            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
953            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
954            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
955            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
956        }
957    }
958}
959
960#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
961pub struct Identity {
962    pub uid: String,
963    pub connected_uid: String,
964    pub position: char,
965    pub hardware_version: [u8; 3],
966    pub firmware_version: [u8; 3],
967    pub device_identifier: u16,
968}
969impl FromByteSlice for Identity {
970    fn bytes_expected() -> usize {
971        25
972    }
973    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
974        Identity {
975            uid: <String>::from_le_byte_slice(&bytes[0..8]),
976            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
977            position: <char>::from_le_byte_slice(&bytes[16..17]),
978            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
979            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
980            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
981        }
982    }
983}
984
985#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
986pub struct WriteResult {}
987
988#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
989pub struct ReadResult {}
990
991#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
992pub struct ModbusSlaveAnswerReadCoilsRequestResult {}
993
994#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
995pub struct ModbusSlaveAnswerReadHoldingRegistersRequestResult {}
996
997#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
998pub struct ModbusMasterWriteMultipleCoilsResult {
999    pub request_id: u8,
1000}
1001
1002#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1003pub struct ModbusMasterWriteMultipleRegistersResult {
1004    pub request_id: u8,
1005}
1006
1007#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1008pub struct ModbusSlaveAnswerReadDiscreteInputsRequestResult {}
1009
1010#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1011pub struct ModbusSlaveAnswerReadInputRegistersRequestResult {}
1012
1013#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1014pub struct ModbusMasterReadCoilsResponseResult {
1015    pub request_id: u8,
1016    pub exception_code: i8,
1017}
1018
1019#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1020pub struct ModbusMasterReadHoldingRegistersResponseResult {
1021    pub request_id: u8,
1022    pub exception_code: i8,
1023}
1024
1025#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1026pub struct ModbusSlaveWriteMultipleCoilsRequestResult {
1027    pub request_id: u8,
1028    pub starting_address: u32,
1029}
1030
1031#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1032pub struct ModbusSlaveWriteMultipleRegistersRequestResult {
1033    pub request_id: u8,
1034    pub starting_address: u32,
1035}
1036
1037#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1038pub struct ModbusMasterReadDiscreteInputsResponseResult {
1039    pub request_id: u8,
1040    pub exception_code: i8,
1041}
1042
1043#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1044pub struct ModbusMasterReadInputRegistersResponseResult {
1045    pub request_id: u8,
1046    pub exception_code: i8,
1047}
1048
1049/// Communicates with RS485/Modbus devices with full- or half-duplex
1050#[derive(Clone)]
1051pub struct Rs485Bricklet {
1052    device: Device,
1053}
1054impl Rs485Bricklet {
1055    pub const DEVICE_IDENTIFIER: u16 = 277;
1056    pub const DEVICE_DISPLAY_NAME: &'static str = "RS485 Bricklet";
1057    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
1058    pub fn new(uid: Uid, connection: AsyncIpConnection) -> Rs485Bricklet {
1059        let mut result = Rs485Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
1060        result.device.response_expected[u8::from(Rs485BrickletFunction::WriteLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
1061        result.device.response_expected[u8::from(Rs485BrickletFunction::ReadLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
1062        result.device.response_expected[u8::from(Rs485BrickletFunction::EnableReadCallback) as usize] = ResponseExpectedFlag::True;
1063        result.device.response_expected[u8::from(Rs485BrickletFunction::DisableReadCallback) as usize] = ResponseExpectedFlag::True;
1064        result.device.response_expected[u8::from(Rs485BrickletFunction::IsReadCallbackEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
1065        result.device.response_expected[u8::from(Rs485BrickletFunction::SetRs485Configuration) as usize] = ResponseExpectedFlag::False;
1066        result.device.response_expected[u8::from(Rs485BrickletFunction::GetRs485Configuration) as usize] = ResponseExpectedFlag::AlwaysTrue;
1067        result.device.response_expected[u8::from(Rs485BrickletFunction::SetModbusConfiguration) as usize] = ResponseExpectedFlag::False;
1068        result.device.response_expected[u8::from(Rs485BrickletFunction::GetModbusConfiguration) as usize] =
1069            ResponseExpectedFlag::AlwaysTrue;
1070        result.device.response_expected[u8::from(Rs485BrickletFunction::SetMode) as usize] = ResponseExpectedFlag::False;
1071        result.device.response_expected[u8::from(Rs485BrickletFunction::GetMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
1072        result.device.response_expected[u8::from(Rs485BrickletFunction::SetCommunicationLedConfig) as usize] = ResponseExpectedFlag::False;
1073        result.device.response_expected[u8::from(Rs485BrickletFunction::GetCommunicationLedConfig) as usize] =
1074            ResponseExpectedFlag::AlwaysTrue;
1075        result.device.response_expected[u8::from(Rs485BrickletFunction::SetErrorLedConfig) as usize] = ResponseExpectedFlag::False;
1076        result.device.response_expected[u8::from(Rs485BrickletFunction::GetErrorLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
1077        result.device.response_expected[u8::from(Rs485BrickletFunction::SetBufferConfig) as usize] = ResponseExpectedFlag::False;
1078        result.device.response_expected[u8::from(Rs485BrickletFunction::GetBufferConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
1079        result.device.response_expected[u8::from(Rs485BrickletFunction::GetBufferStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
1080        result.device.response_expected[u8::from(Rs485BrickletFunction::EnableErrorCountCallback) as usize] = ResponseExpectedFlag::True;
1081        result.device.response_expected[u8::from(Rs485BrickletFunction::DisableErrorCountCallback) as usize] = ResponseExpectedFlag::True;
1082        result.device.response_expected[u8::from(Rs485BrickletFunction::IsErrorCountCallbackEnabled) as usize] =
1083            ResponseExpectedFlag::AlwaysTrue;
1084        result.device.response_expected[u8::from(Rs485BrickletFunction::GetErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
1085        result.device.response_expected[u8::from(Rs485BrickletFunction::GetModbusCommonErrorCount) as usize] =
1086            ResponseExpectedFlag::AlwaysTrue;
1087        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveReportException) as usize] = ResponseExpectedFlag::False;
1088        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadCoilsRequestLowLevel) as usize] =
1089            ResponseExpectedFlag::True;
1090        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadCoils) as usize] = ResponseExpectedFlag::AlwaysTrue;
1091        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel) as usize] =
1092            ResponseExpectedFlag::True;
1093        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadHoldingRegisters) as usize] =
1094            ResponseExpectedFlag::AlwaysTrue;
1095        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleCoilRequest) as usize] =
1096            ResponseExpectedFlag::False;
1097        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleCoil) as usize] =
1098            ResponseExpectedFlag::AlwaysTrue;
1099        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleRegisterRequest) as usize] =
1100            ResponseExpectedFlag::False;
1101        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleRegister) as usize] =
1102            ResponseExpectedFlag::AlwaysTrue;
1103        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleCoilsRequest) as usize] =
1104            ResponseExpectedFlag::False;
1105        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleCoilsLowLevel) as usize] =
1106            ResponseExpectedFlag::AlwaysTrue;
1107        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleRegistersRequest) as usize] =
1108            ResponseExpectedFlag::False;
1109        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleRegistersLowLevel) as usize] =
1110            ResponseExpectedFlag::AlwaysTrue;
1111        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel) as usize] =
1112            ResponseExpectedFlag::True;
1113        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadDiscreteInputs) as usize] =
1114            ResponseExpectedFlag::AlwaysTrue;
1115        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadInputRegistersRequestLowLevel) as usize] =
1116            ResponseExpectedFlag::True;
1117        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadInputRegisters) as usize] =
1118            ResponseExpectedFlag::AlwaysTrue;
1119        result.device.response_expected[u8::from(Rs485BrickletFunction::SetFrameReadableCallbackConfiguration) as usize] =
1120            ResponseExpectedFlag::True;
1121        result.device.response_expected[u8::from(Rs485BrickletFunction::GetFrameReadableCallbackConfiguration) as usize] =
1122            ResponseExpectedFlag::AlwaysTrue;
1123        result.device.response_expected[u8::from(Rs485BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
1124        result.device.response_expected[u8::from(Rs485BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
1125        result.device.response_expected[u8::from(Rs485BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
1126        result.device.response_expected[u8::from(Rs485BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
1127        result.device.response_expected[u8::from(Rs485BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
1128        result.device.response_expected[u8::from(Rs485BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
1129        result.device.response_expected[u8::from(Rs485BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
1130        result.device.response_expected[u8::from(Rs485BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
1131        result.device.response_expected[u8::from(Rs485BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
1132        result.device.response_expected[u8::from(Rs485BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
1133        result.device.response_expected[u8::from(Rs485BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
1134        result.device.response_expected[u8::from(Rs485BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
1135        result
1136    }
1137
1138    /// Returns the response expected flag for the function specified by the function ID parameter.
1139    /// It is true if the function is expected to send a response, false otherwise.
1140    ///
1141    /// For getter functions this is enabled by default and cannot be disabled, because those
1142    /// functions will always send a response. For callback configuration functions it is enabled
1143    /// by default too, but can be disabled by [`set_response_expected`](crate::rs485_bricklet::Rs485Bricklet::set_response_expected).
1144    /// For setter functions it is disabled by default and can be enabled.
1145    ///
1146    /// Enabling the response expected flag for a setter function allows to detect timeouts
1147    /// and other error conditions calls of this setter as well. The device will then send a response
1148    /// for this purpose. If this flag is disabled for a setter function then no response is sent
1149    /// and errors are silently ignored, because they cannot be detected.
1150    ///
1151    /// See [`set_response_expected`](crate::rs485_bricklet::Rs485Bricklet::set_response_expected) for the list of function ID constants available for this function.
1152    pub fn get_response_expected(&mut self, fun: Rs485BrickletFunction) -> Result<bool, GetResponseExpectedError> {
1153        self.device.get_response_expected(u8::from(fun))
1154    }
1155
1156    /// Changes the response expected flag of the function specified by the function ID parameter.
1157    /// This flag can only be changed for setter (default value: false) and callback configuration
1158    /// functions (default value: true). For getter functions it is always enabled.
1159    ///
1160    /// Enabling the response expected flag for a setter function allows to detect timeouts and
1161    /// other error conditions calls of this setter as well. The device will then send a response
1162    /// for this purpose. If this flag is disabled for a setter function then no response is sent
1163    /// and errors are silently ignored, because they cannot be detected.
1164    pub fn set_response_expected(&mut self, fun: Rs485BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
1165        self.device.set_response_expected(u8::from(fun), response_expected)
1166    }
1167
1168    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
1169    pub fn set_response_expected_all(&mut self, response_expected: bool) {
1170        self.device.set_response_expected_all(response_expected)
1171    }
1172
1173    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
1174    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
1175    pub fn get_api_version(&self) -> [u8; 3] {
1176        self.device.api_version
1177    }
1178
1179    /// See [`get_read_callback_receiver`](crate::rs485::RS485::get_read_callback_receiver)
1180    pub async fn get_read_low_level_callback_receiver(&mut self) -> impl Stream<Item = ReadLowLevelEvent> {
1181        self.device
1182            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackReadLowLevel))
1183            .await
1184            .map(|p| ReadLowLevelEvent::from_le_byte_slice(p.body()))
1185    }
1186
1187    /// This receiver is called if a new error occurs. It returns
1188    /// the current overrun and parity error count.
1189    pub async fn get_error_count_callback_receiver(&mut self) -> impl Stream<Item = ErrorCountEvent> {
1190        self.device
1191            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackErrorCount))
1192            .await
1193            .map(|p| ErrorCountEvent::from_le_byte_slice(p.body()))
1194    }
1195
1196    /// This receiver is called only in Modbus slave mode when the slave receives a
1197    /// valid request from a Modbus master to read coils. The parameters are
1198    /// request ID of the request, the number of the first coil to be read and the number of coils to
1199    /// be read as received by the request. The number of the first coil is called starting address for backwards compatibility reasons.
1200    /// It is not an address, but instead a coil number in the range of 1 to 65536.
1201    ///
1202    /// To send a response of this request use [`modbus_slave_answer_read_coils_request`].
1203    pub async fn get_modbus_slave_read_coils_request_callback_receiver(&mut self) -> impl Stream<Item = ModbusSlaveReadCoilsRequestEvent> {
1204        self.device
1205            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadCoilsRequest))
1206            .await
1207            .map(|p| ModbusSlaveReadCoilsRequestEvent::from_le_byte_slice(p.body()))
1208    }
1209
1210    /// See [`get_modbus_master_read_coils_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_coils_response_callback_receiver)
1211    pub async fn get_modbus_master_read_coils_response_low_level_callback_receiver(
1212        &mut self,
1213    ) -> impl Stream<Item = ModbusMasterReadCoilsResponseLowLevelEvent> {
1214        self.device
1215            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadCoilsResponseLowLevel))
1216            .await
1217            .map(|p| ModbusMasterReadCoilsResponseLowLevelEvent::from_le_byte_slice(p.body()))
1218    }
1219
1220    /// This receiver is called only in Modbus slave mode when the slave receives a
1221    /// valid request from a Modbus master to read holding registers. The parameters
1222    /// are request ID of the request, the number of the first holding register to be read and the number of holding
1223    /// registers to be read as received by the request. The number of the first holding register is called starting address for backwards compatibility reasons.
1224    /// It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is omitted.
1225    ///
1226    /// To send a response of this request use [`modbus_slave_answer_read_holding_registers_request`].
1227    pub async fn get_modbus_slave_read_holding_registers_request_callback_receiver(
1228        &mut self,
1229    ) -> impl Stream<Item = ModbusSlaveReadHoldingRegistersRequestEvent> {
1230        self.device
1231            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadHoldingRegistersRequest))
1232            .await
1233            .map(|p| ModbusSlaveReadHoldingRegistersRequestEvent::from_le_byte_slice(p.body()))
1234    }
1235
1236    /// See [`get_modbus_master_read_holding_registers_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_holding_registers_response_callback_receiver)
1237    pub async fn get_modbus_master_read_holding_registers_response_low_level_callback_receiver(
1238        &mut self,
1239    ) -> impl Stream<Item = ModbusMasterReadHoldingRegistersResponseLowLevelEvent> {
1240        self.device
1241            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadHoldingRegistersResponseLowLevel))
1242            .await
1243            .map(|p| ModbusMasterReadHoldingRegistersResponseLowLevelEvent::from_le_byte_slice(p.body()))
1244    }
1245
1246    /// This receiver is called only in Modbus slave mode when the slave receives a
1247    /// valid request from a Modbus master to write a single coil. The parameters
1248    /// are request ID of the request, the number of the coil and the value of coil to be
1249    /// written as received by the request. The number of the coil is called coil address for backwards compatibility reasons.
1250    /// It is not an address, but instead a coil number in the range of 1 to 65536.
1251    ///
1252    /// To send a response of this request use [`modbus_slave_answer_write_single_coil_request`].
1253    pub async fn get_modbus_slave_write_single_coil_request_callback_receiver(
1254        &mut self,
1255    ) -> impl Stream<Item = ModbusSlaveWriteSingleCoilRequestEvent> {
1256        self.device
1257            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteSingleCoilRequest))
1258            .await
1259            .map(|p| ModbusSlaveWriteSingleCoilRequestEvent::from_le_byte_slice(p.body()))
1260    }
1261
1262    /// This receiver is called only in Modbus master mode when the master receives a
1263    /// valid response of a request to write a single coil.
1264    ///
1265    /// The parameters are
1266    /// request ID of the request and exception code of the response.
1267    ///
1268    /// Any non-zero exception code indicates a problem.
1269    /// If the exception code is greater than 0 then the number represents a Modbus
1270    /// exception code. If it is less than 0 then it represents other errors. For
1271    /// example, -1 indicates that the request timed out or that the master did not receive
1272    /// any valid response of the request within the master request timeout period as set
1273    /// by [`set_modbus_configuration`].
1274    pub async fn get_modbus_master_write_single_coil_response_callback_receiver(
1275        &mut self,
1276    ) -> impl Stream<Item = ModbusMasterWriteSingleCoilResponseEvent> {
1277        self.device
1278            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteSingleCoilResponse))
1279            .await
1280            .map(|p| ModbusMasterWriteSingleCoilResponseEvent::from_le_byte_slice(p.body()))
1281    }
1282
1283    /// This receiver is called only in Modbus slave mode when the slave receives a
1284    /// valid request from a Modbus master to write a single holding register. The parameters
1285    /// are request ID of the request, the number of the holding register and the register value to
1286    /// be written as received by the request. The number of the holding register is called starting address for backwards compatibility reasons.
1287    /// It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is omitted.
1288    ///
1289    /// To send a response of this request use [`modbus_slave_answer_write_single_register_request`].
1290    pub async fn get_modbus_slave_write_single_register_request_callback_receiver(
1291        &mut self,
1292    ) -> impl Stream<Item = ModbusSlaveWriteSingleRegisterRequestEvent> {
1293        self.device
1294            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteSingleRegisterRequest))
1295            .await
1296            .map(|p| ModbusSlaveWriteSingleRegisterRequestEvent::from_le_byte_slice(p.body()))
1297    }
1298
1299    /// This receiver is called only in Modbus master mode when the master receives a
1300    /// valid response of a request to write a single register.
1301    ///
1302    /// The parameters are
1303    /// request ID of the request and exception code of the response.
1304    ///
1305    /// Any non-zero exception code
1306    /// indicates a problem. If the exception code is greater than 0 then the number
1307    /// represents a Modbus exception code. If it is less than 0 then it represents
1308    /// other errors. For example, -1 indicates that the request timed out or that the
1309    /// master did not receive any valid response of the request within the master request
1310    /// timeout period as set by [`set_modbus_configuration`].
1311    pub async fn get_modbus_master_write_single_register_response_callback_receiver(
1312        &mut self,
1313    ) -> impl Stream<Item = ModbusMasterWriteSingleRegisterResponseEvent> {
1314        self.device
1315            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteSingleRegisterResponse))
1316            .await
1317            .map(|p| ModbusMasterWriteSingleRegisterResponseEvent::from_le_byte_slice(p.body()))
1318    }
1319
1320    /// See [`get_modbus_slave_write_multiple_coils_request_callback_receiver`](crate::rs485::RS485::get_modbus_slave_write_multiple_coils_request_callback_receiver)
1321    pub async fn get_modbus_slave_write_multiple_coils_request_low_level_callback_receiver(
1322        &mut self,
1323    ) -> impl Stream<Item = ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent> {
1324        self.device
1325            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel))
1326            .await
1327            .map(|p| ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent::from_le_byte_slice(p.body()))
1328    }
1329
1330    /// This receiver is called only in Modbus master mode when the master receives a
1331    /// valid response of a request to read coils.
1332    ///
1333    /// The parameters are
1334    /// request ID of the request and exception code of the response.
1335    ///
1336    /// Any non-zero exception code
1337    /// indicates a problem. If the exception code is greater than 0 then the number
1338    /// represents a Modbus exception code. If it is less than 0 then it represents
1339    /// other errors. For example, -1 indicates that the request timedout or that the
1340    /// master did not receive any valid response of the request within the master request
1341    /// timeout period as set by [`set_modbus_configuration`].
1342    pub async fn get_modbus_master_write_multiple_coils_response_callback_receiver(
1343        &mut self,
1344    ) -> impl Stream<Item = ModbusMasterWriteMultipleCoilsResponseEvent> {
1345        self.device
1346            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteMultipleCoilsResponse))
1347            .await
1348            .map(|p| ModbusMasterWriteMultipleCoilsResponseEvent::from_le_byte_slice(p.body()))
1349    }
1350
1351    /// See [`get_modbus_slave_write_multiple_registers_request_callback_receiver`](crate::rs485::RS485::get_modbus_slave_write_multiple_registers_request_callback_receiver)
1352    pub async fn get_modbus_slave_write_multiple_registers_request_low_level_callback_receiver(
1353        &mut self,
1354    ) -> impl Stream<Item = ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent> {
1355        self.device
1356            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel))
1357            .await
1358            .map(|p| ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent::from_le_byte_slice(p.body()))
1359    }
1360
1361    /// This receiver is called only in Modbus master mode when the master receives a
1362    /// valid response of a request to write multiple registers.
1363    ///
1364    /// The parameters
1365    /// are request ID of the request and exception code of the response.
1366    ///
1367    /// Any non-zero
1368    /// exception code indicates a problem. If the exception code is greater than 0 then
1369    /// the number represents a Modbus exception code. If it is less than 0 then it
1370    /// represents other errors. For example, -1 indicates that the request timedout or
1371    /// that the master did not receive any valid response of the request within the master
1372    /// request timeout period as set by [`set_modbus_configuration`].
1373    pub async fn get_modbus_master_write_multiple_registers_response_callback_receiver(
1374        &mut self,
1375    ) -> impl Stream<Item = ModbusMasterWriteMultipleRegistersResponseEvent> {
1376        self.device
1377            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteMultipleRegistersResponse))
1378            .await
1379            .map(|p| ModbusMasterWriteMultipleRegistersResponseEvent::from_le_byte_slice(p.body()))
1380    }
1381
1382    /// This receiver is called only in Modbus slave mode when the slave receives a
1383    /// valid request from a Modbus master to read discrete inputs. The parameters
1384    /// are request ID of the request, the number of the first discrete input and the number of discrete
1385    /// inputs to be read as received by the request. The number of the first discrete input is called starting address for backwards compatibility reasons.
1386    /// It is not an address, but instead a discrete input number in the range of 1 to 65536. The prefix digit 1 (for discrete input) is omitted.
1387    ///
1388    /// To send a response of this request use [`modbus_slave_answer_read_discrete_inputs_request`].
1389    pub async fn get_modbus_slave_read_discrete_inputs_request_callback_receiver(
1390        &mut self,
1391    ) -> impl Stream<Item = ModbusSlaveReadDiscreteInputsRequestEvent> {
1392        self.device
1393            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadDiscreteInputsRequest))
1394            .await
1395            .map(|p| ModbusSlaveReadDiscreteInputsRequestEvent::from_le_byte_slice(p.body()))
1396    }
1397
1398    /// See [`get_modbus_master_read_discrete_inputs_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_discrete_inputs_response_callback_receiver)
1399    pub async fn get_modbus_master_read_discrete_inputs_response_low_level_callback_receiver(
1400        &mut self,
1401    ) -> impl Stream<Item = ModbusMasterReadDiscreteInputsResponseLowLevelEvent> {
1402        self.device
1403            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadDiscreteInputsResponseLowLevel))
1404            .await
1405            .map(|p| ModbusMasterReadDiscreteInputsResponseLowLevelEvent::from_le_byte_slice(p.body()))
1406    }
1407
1408    /// This receiver is called only in Modbus slave mode when the slave receives a
1409    /// valid request from a Modbus master to read input registers. The parameters
1410    /// are request ID of the request, the number of the first input register and the number of input
1411    /// registers to be read as received by the request. The number of the first input register is called starting address for backwards compatibility reasons.
1412    /// It is not an address, but instead a input register number in the range of 1 to 65536. The prefix digit 3 (for input register) is omitted.
1413    ///
1414    /// To send a response of this request use [`modbus_slave_answer_read_input_registers_request`].
1415    pub async fn get_modbus_slave_read_input_registers_request_callback_receiver(
1416        &mut self,
1417    ) -> impl Stream<Item = ModbusSlaveReadInputRegistersRequestEvent> {
1418        self.device
1419            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadInputRegistersRequest))
1420            .await
1421            .map(|p| ModbusSlaveReadInputRegistersRequestEvent::from_le_byte_slice(p.body()))
1422    }
1423
1424    /// See [`get_modbus_master_read_input_registers_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_input_registers_response_callback_receiver)
1425    pub async fn get_modbus_master_read_input_registers_response_low_level_callback_receiver(
1426        &mut self,
1427    ) -> impl Stream<Item = ModbusMasterReadInputRegistersResponseLowLevelEvent> {
1428        self.device
1429            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadInputRegistersResponseLowLevel))
1430            .await
1431            .map(|p| ModbusMasterReadInputRegistersResponseLowLevelEvent::from_le_byte_slice(p.body()))
1432    }
1433
1434    /// This receiver is called if at least one frame of data is readable. The frame size is configured with [`set_frame_readable_callback_configuration`].
1435    /// The frame count parameter is the number of frames that can be read.
1436    /// This receiver is triggered only once until [`read`] is called. This means, that if you have configured a frame size of X bytes,
1437    /// you can read exactly X bytes using the [`read`] function, every time the receiver triggers without checking the frame count parameter.
1438    ///
1439    ///
1440    /// .. versionadded:: 2.0.5$nbsp;(Plugin)
1441    pub async fn get_frame_readable_callback_receiver(&mut self) -> impl Stream<Item = u16> {
1442        self.device
1443            .get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackFrameReadable))
1444            .await
1445            .map(|p| u16::from_le_byte_slice(p.body()))
1446    }
1447
1448    /// Writes characters to the RS485 interface. The characters can be binary data,
1449    /// ASCII or similar is not necessary.
1450    ///
1451    /// The return value is the number of characters that were written.
1452    ///
1453    /// See [`set_rs485_configuration`] for configuration possibilities
1454    /// regarding baudrate, parity and so on.
1455    pub async fn write_low_level(
1456        &mut self,
1457        message_length: u16,
1458        message_chunk_offset: u16,
1459        message_chunk_data: &[char; 60],
1460    ) -> Result<WriteLowLevel, TinkerforgeError> {
1461        let mut payload = [0; 64];
1462        message_length.write_to_slice(&mut payload[0..2]);
1463        message_chunk_offset.write_to_slice(&mut payload[2..4]);
1464        message_chunk_data.write_to_slice(&mut payload[4..64]);
1465
1466        #[allow(unused_variables)]
1467        let result = self.device.get(u8::from(Rs485BrickletFunction::WriteLowLevel), &payload).await?;
1468        Ok(WriteLowLevel::from_le_byte_slice(result.body()))
1469    }
1470
1471    /// Returns up to *length* characters from receive buffer.
1472    ///
1473    /// Instead of polling with this function, you can also use
1474    /// callbacks. But note that this function will return available
1475    /// data only when the read receiver is disabled.
1476    /// See [`enable_read_callback`] and [`get_read_callback_receiver`] receiver.
1477    pub async fn read_low_level(&mut self, length: u16) -> Result<ReadLowLevel, TinkerforgeError> {
1478        let mut payload = [0; 2];
1479        length.write_to_slice(&mut payload[0..2]);
1480
1481        #[allow(unused_variables)]
1482        let result = self.device.get(u8::from(Rs485BrickletFunction::ReadLowLevel), &payload).await?;
1483        Ok(ReadLowLevel::from_le_byte_slice(result.body()))
1484    }
1485
1486    /// Enables the [`get_read_callback_receiver`] receiver. This will disable the [`get_frame_readable_callback_receiver`] receiver.
1487    ///
1488    /// By default the receiver is disabled.
1489    pub async fn enable_read_callback(&mut self) -> Result<(), TinkerforgeError> {
1490        let payload = [0; 0];
1491
1492        #[allow(unused_variables)]
1493        let result = self.device.set(u8::from(Rs485BrickletFunction::EnableReadCallback), &payload).await?;
1494        Ok(())
1495    }
1496
1497    /// Disables the [`get_read_callback_receiver`] receiver.
1498    ///
1499    /// By default the receiver is disabled.
1500    pub async fn disable_read_callback(&mut self) -> Result<(), TinkerforgeError> {
1501        let payload = [0; 0];
1502
1503        #[allow(unused_variables)]
1504        let result = self.device.set(u8::from(Rs485BrickletFunction::DisableReadCallback), &payload).await?;
1505        Ok(())
1506    }
1507
1508    /// Returns *true* if the [`get_read_callback_receiver`] receiver is enabled,
1509    /// *false* otherwise.
1510    pub async fn is_read_callback_enabled(&mut self) -> Result<bool, TinkerforgeError> {
1511        let payload = [0; 0];
1512
1513        #[allow(unused_variables)]
1514        let result = self.device.get(u8::from(Rs485BrickletFunction::IsReadCallbackEnabled), &payload).await?;
1515        Ok(bool::from_le_byte_slice(result.body()))
1516    }
1517
1518    /// Sets the configuration for the RS485 communication.
1519    ///
1520    /// Associated constants:
1521    /// * RS485_BRICKLET_PARITY_NONE
1522    ///	* RS485_BRICKLET_PARITY_ODD
1523    ///	* RS485_BRICKLET_PARITY_EVEN
1524    ///	* RS485_BRICKLET_STOPBITS_1
1525    ///	* RS485_BRICKLET_STOPBITS_2
1526    ///	* RS485_BRICKLET_WORDLENGTH_5
1527    ///	* RS485_BRICKLET_WORDLENGTH_6
1528    ///	* RS485_BRICKLET_WORDLENGTH_7
1529    ///	* RS485_BRICKLET_WORDLENGTH_8
1530    ///	* RS485_BRICKLET_DUPLEX_HALF
1531    ///	* RS485_BRICKLET_DUPLEX_FULL
1532    pub async fn set_rs485_configuration(
1533        &mut self,
1534        baudrate: u32,
1535        parity: u8,
1536        stopbits: u8,
1537        wordlength: u8,
1538        duplex: u8,
1539    ) -> Result<(), TinkerforgeError> {
1540        let mut payload = [0; 8];
1541        baudrate.write_to_slice(&mut payload[0..4]);
1542        parity.write_to_slice(&mut payload[4..5]);
1543        stopbits.write_to_slice(&mut payload[5..6]);
1544        wordlength.write_to_slice(&mut payload[6..7]);
1545        duplex.write_to_slice(&mut payload[7..8]);
1546
1547        #[allow(unused_variables)]
1548        let result = self.device.set(u8::from(Rs485BrickletFunction::SetRs485Configuration), &payload).await?;
1549        Ok(())
1550    }
1551
1552    /// Returns the configuration as set by [`set_rs485_configuration`].
1553    ///
1554    /// Associated constants:
1555    /// * RS485_BRICKLET_PARITY_NONE
1556    ///	* RS485_BRICKLET_PARITY_ODD
1557    ///	* RS485_BRICKLET_PARITY_EVEN
1558    ///	* RS485_BRICKLET_STOPBITS_1
1559    ///	* RS485_BRICKLET_STOPBITS_2
1560    ///	* RS485_BRICKLET_WORDLENGTH_5
1561    ///	* RS485_BRICKLET_WORDLENGTH_6
1562    ///	* RS485_BRICKLET_WORDLENGTH_7
1563    ///	* RS485_BRICKLET_WORDLENGTH_8
1564    ///	* RS485_BRICKLET_DUPLEX_HALF
1565    ///	* RS485_BRICKLET_DUPLEX_FULL
1566    pub async fn get_rs485_configuration(&mut self) -> Result<Rs485Configuration, TinkerforgeError> {
1567        let payload = [0; 0];
1568
1569        #[allow(unused_variables)]
1570        let result = self.device.get(u8::from(Rs485BrickletFunction::GetRs485Configuration), &payload).await?;
1571        Ok(Rs485Configuration::from_le_byte_slice(result.body()))
1572    }
1573
1574    /// Sets the configuration for the RS485 Modbus communication. Available options:
1575    ///
1576    /// * Slave Address: Address to be used as the Modbus slave address in Modbus slave mode. Valid Modbus slave address range is 1 to 247.
1577    /// * Master Request Timeout: Specifies how long the master should wait for a response from a slave when in Modbus master mode.
1578    pub async fn set_modbus_configuration(&mut self, slave_address: u8, master_request_timeout: u32) -> Result<(), TinkerforgeError> {
1579        let mut payload = [0; 5];
1580        slave_address.write_to_slice(&mut payload[0..1]);
1581        master_request_timeout.write_to_slice(&mut payload[1..5]);
1582
1583        #[allow(unused_variables)]
1584        let result = self.device.set(u8::from(Rs485BrickletFunction::SetModbusConfiguration), &payload).await?;
1585        Ok(())
1586    }
1587
1588    /// Returns the configuration as set by [`set_modbus_configuration`].
1589    pub async fn get_modbus_configuration(&mut self) -> Result<ModbusConfiguration, TinkerforgeError> {
1590        let payload = [0; 0];
1591
1592        #[allow(unused_variables)]
1593        let result = self.device.get(u8::from(Rs485BrickletFunction::GetModbusConfiguration), &payload).await?;
1594        Ok(ModbusConfiguration::from_le_byte_slice(result.body()))
1595    }
1596
1597    /// Sets the mode of the Bricklet in which it operates. Available options are
1598    ///
1599    /// * RS485,
1600    /// * Modbus Master RTU and
1601    /// * Modbus Slave RTU.
1602    ///
1603    /// Associated constants:
1604    /// * RS485_BRICKLET_MODE_RS485
1605    ///	* RS485_BRICKLET_MODE_MODBUS_MASTER_RTU
1606    ///	* RS485_BRICKLET_MODE_MODBUS_SLAVE_RTU
1607    pub async fn set_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
1608        let mut payload = [0; 1];
1609        mode.write_to_slice(&mut payload[0..1]);
1610
1611        #[allow(unused_variables)]
1612        let result = self.device.set(u8::from(Rs485BrickletFunction::SetMode), &payload).await?;
1613        Ok(())
1614    }
1615
1616    /// Returns the configuration as set by [`set_mode`].
1617    ///
1618    /// Associated constants:
1619    /// * RS485_BRICKLET_MODE_RS485
1620    ///	* RS485_BRICKLET_MODE_MODBUS_MASTER_RTU
1621    ///	* RS485_BRICKLET_MODE_MODBUS_SLAVE_RTU
1622    pub async fn get_mode(&mut self) -> Result<u8, TinkerforgeError> {
1623        let payload = [0; 0];
1624
1625        #[allow(unused_variables)]
1626        let result = self.device.get(u8::from(Rs485BrickletFunction::GetMode), &payload).await?;
1627        Ok(u8::from_le_byte_slice(result.body()))
1628    }
1629
1630    /// Sets the communication LED configuration. By default the LED shows RS485
1631    /// communication traffic by flickering.
1632    ///
1633    /// You can also turn the LED permanently on/off or show a heartbeat.
1634    ///
1635    /// If the Bricklet is in bootloader mode, the LED is off.
1636    ///
1637    /// Associated constants:
1638    /// * RS485_BRICKLET_COMMUNICATION_LED_CONFIG_OFF
1639    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_ON
1640    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT
1641    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION
1642    pub async fn set_communication_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
1643        let mut payload = [0; 1];
1644        config.write_to_slice(&mut payload[0..1]);
1645
1646        #[allow(unused_variables)]
1647        let result = self.device.set(u8::from(Rs485BrickletFunction::SetCommunicationLedConfig), &payload).await?;
1648        Ok(())
1649    }
1650
1651    /// Returns the configuration as set by [`set_communication_led_config`]
1652    ///
1653    /// Associated constants:
1654    /// * RS485_BRICKLET_COMMUNICATION_LED_CONFIG_OFF
1655    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_ON
1656    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT
1657    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION
1658    pub async fn get_communication_led_config(&mut self) -> Result<u8, TinkerforgeError> {
1659        let payload = [0; 0];
1660
1661        #[allow(unused_variables)]
1662        let result = self.device.get(u8::from(Rs485BrickletFunction::GetCommunicationLedConfig), &payload).await?;
1663        Ok(u8::from_le_byte_slice(result.body()))
1664    }
1665
1666    /// Sets the error LED configuration.
1667    ///
1668    /// By default the error LED turns on if there is any error (see [`get_error_count_callback_receiver`]
1669    /// callback). If you call this function with the SHOW ERROR option again, the LED
1670    /// will turn off until the next error occurs.
1671    ///
1672    /// You can also turn the LED permanently on/off or show a heartbeat.
1673    ///
1674    /// If the Bricklet is in bootloader mode, the LED is off.
1675    ///
1676    /// Associated constants:
1677    /// * RS485_BRICKLET_ERROR_LED_CONFIG_OFF
1678    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_ON
1679    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT
1680    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR
1681    pub async fn set_error_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
1682        let mut payload = [0; 1];
1683        config.write_to_slice(&mut payload[0..1]);
1684
1685        #[allow(unused_variables)]
1686        let result = self.device.set(u8::from(Rs485BrickletFunction::SetErrorLedConfig), &payload).await?;
1687        Ok(())
1688    }
1689
1690    /// Returns the configuration as set by [`set_error_led_config`].
1691    ///
1692    /// Associated constants:
1693    /// * RS485_BRICKLET_ERROR_LED_CONFIG_OFF
1694    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_ON
1695    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT
1696    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR
1697    pub async fn get_error_led_config(&mut self) -> Result<u8, TinkerforgeError> {
1698        let payload = [0; 0];
1699
1700        #[allow(unused_variables)]
1701        let result = self.device.get(u8::from(Rs485BrickletFunction::GetErrorLedConfig), &payload).await?;
1702        Ok(u8::from_le_byte_slice(result.body()))
1703    }
1704
1705    /// Sets the send and receive buffer size in byte. In sum there is
1706    /// 10240 byte (10KiB) buffer available and the minimum buffer size
1707    /// is 1024 byte (1KiB) for both.
1708    ///
1709    /// The current buffer content is lost if this function is called.
1710    ///
1711    /// The send buffer holds data that was given by [`write`] and
1712    /// could not be written yet. The receive buffer holds data that is
1713    /// received through RS485 but could not yet be send to the
1714    /// user, either by [`read`] or through [`get_read_callback_receiver`] receiver.
1715    pub async fn set_buffer_config(&mut self, send_buffer_size: u16, receive_buffer_size: u16) -> Result<(), TinkerforgeError> {
1716        let mut payload = [0; 4];
1717        send_buffer_size.write_to_slice(&mut payload[0..2]);
1718        receive_buffer_size.write_to_slice(&mut payload[2..4]);
1719
1720        #[allow(unused_variables)]
1721        let result = self.device.set(u8::from(Rs485BrickletFunction::SetBufferConfig), &payload).await?;
1722        Ok(())
1723    }
1724
1725    /// Returns the buffer configuration as set by [`set_buffer_config`].
1726    pub async fn get_buffer_config(&mut self) -> Result<BufferConfig, TinkerforgeError> {
1727        let payload = [0; 0];
1728
1729        #[allow(unused_variables)]
1730        let result = self.device.get(u8::from(Rs485BrickletFunction::GetBufferConfig), &payload).await?;
1731        Ok(BufferConfig::from_le_byte_slice(result.body()))
1732    }
1733
1734    /// Returns the currently used bytes for the send and received buffer.
1735    ///
1736    /// See [`set_buffer_config`] for buffer size configuration.
1737    pub async fn get_buffer_status(&mut self) -> Result<BufferStatus, TinkerforgeError> {
1738        let payload = [0; 0];
1739
1740        #[allow(unused_variables)]
1741        let result = self.device.get(u8::from(Rs485BrickletFunction::GetBufferStatus), &payload).await?;
1742        Ok(BufferStatus::from_le_byte_slice(result.body()))
1743    }
1744
1745    /// Enables the [`get_error_count_callback_receiver`] receiver.
1746    ///
1747    /// By default the receiver is disabled.
1748    pub async fn enable_error_count_callback(&mut self) -> Result<(), TinkerforgeError> {
1749        let payload = [0; 0];
1750
1751        #[allow(unused_variables)]
1752        let result = self.device.set(u8::from(Rs485BrickletFunction::EnableErrorCountCallback), &payload).await?;
1753        Ok(())
1754    }
1755
1756    /// Disables the [`get_error_count_callback_receiver`] receiver.
1757    ///
1758    /// By default the receiver is disabled.
1759    pub async fn disable_error_count_callback(&mut self) -> Result<(), TinkerforgeError> {
1760        let payload = [0; 0];
1761
1762        #[allow(unused_variables)]
1763        let result = self.device.set(u8::from(Rs485BrickletFunction::DisableErrorCountCallback), &payload).await?;
1764        Ok(())
1765    }
1766
1767    /// Returns *true* if the [`get_error_count_callback_receiver`] receiver is enabled,
1768    /// *false* otherwise.
1769    pub async fn is_error_count_callback_enabled(&mut self) -> Result<bool, TinkerforgeError> {
1770        let payload = [0; 0];
1771
1772        #[allow(unused_variables)]
1773        let result = self.device.get(u8::from(Rs485BrickletFunction::IsErrorCountCallbackEnabled), &payload).await?;
1774        Ok(bool::from_le_byte_slice(result.body()))
1775    }
1776
1777    /// Returns the current number of overrun and parity errors.
1778    pub async fn get_error_count(&mut self) -> Result<ErrorCount, TinkerforgeError> {
1779        let payload = [0; 0];
1780
1781        #[allow(unused_variables)]
1782        let result = self.device.get(u8::from(Rs485BrickletFunction::GetErrorCount), &payload).await?;
1783        Ok(ErrorCount::from_le_byte_slice(result.body()))
1784    }
1785
1786    /// Returns the current number of errors occurred in Modbus mode.
1787    ///
1788    /// * Timeout Error Count: Number of timeouts occurred.
1789    /// * Checksum Error Count: Number of failures due to Modbus frame CRC16 checksum mismatch.
1790    /// * Frame Too Big Error Count: Number of times frames were rejected because they exceeded maximum Modbus frame size which is 256 bytes.
1791    /// * Illegal Function Error Count: Number of errors when an unimplemented or illegal function is requested. This corresponds to Modbus exception code 1.
1792    /// * Illegal Data Address Error Count: Number of errors due to invalid data address. This corresponds to Modbus exception code 2.
1793    /// * Illegal Data Value Error Count: Number of errors due to invalid data value. This corresponds to Modbus exception code 3.
1794    /// * Slave Device Failure Error Count: Number of errors occurred on the slave device which were unrecoverable. This corresponds to Modbus exception code 4.
1795    pub async fn get_modbus_common_error_count(&mut self) -> Result<ModbusCommonErrorCount, TinkerforgeError> {
1796        let payload = [0; 0];
1797
1798        #[allow(unused_variables)]
1799        let result = self.device.get(u8::from(Rs485BrickletFunction::GetModbusCommonErrorCount), &payload).await?;
1800        Ok(ModbusCommonErrorCount::from_le_byte_slice(result.body()))
1801    }
1802
1803    /// In Modbus slave mode this function can be used to report a Modbus exception for
1804    /// a Modbus master request.
1805    ///
1806    /// * Request ID: Request ID of the request received by the slave.
1807    /// * Exception Code: Modbus exception code to report to the Modbus master.
1808    ///
1809    /// Associated constants:
1810    /// * RS485_BRICKLET_EXCEPTION_CODE_TIMEOUT
1811    ///	* RS485_BRICKLET_EXCEPTION_CODE_SUCCESS
1812    ///	* RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_FUNCTION
1813    ///	* RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS
1814    ///	* RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_VALUE
1815    ///	* RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_FAILURE
1816    ///	* RS485_BRICKLET_EXCEPTION_CODE_ACKNOWLEDGE
1817    ///	* RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_BUSY
1818    ///	* RS485_BRICKLET_EXCEPTION_CODE_MEMORY_PARITY_ERROR
1819    ///	* RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE
1820    ///	* RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
1821    pub async fn modbus_slave_report_exception(&mut self, request_id: u8, exception_code: i8) -> Result<(), TinkerforgeError> {
1822        let mut payload = [0; 2];
1823        request_id.write_to_slice(&mut payload[0..1]);
1824        exception_code.write_to_slice(&mut payload[1..2]);
1825
1826        #[allow(unused_variables)]
1827        let result = self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveReportException), &payload).await?;
1828        Ok(())
1829    }
1830
1831    /// In Modbus slave mode this function can be used to answer a master request to
1832    /// read coils.
1833    ///
1834    /// * Request ID: Request ID of the corresponding request that is being answered.
1835    /// * Coils: Data that is to be sent to the Modbus master for the corresponding request.
1836    ///
1837    /// This function must be called from the [`get_modbus_slave_read_coils_request_callback_receiver`] receiver
1838    /// with the Request ID as provided by the argument of the receiver.
1839    pub async fn modbus_slave_answer_read_coils_request_low_level(
1840        &mut self,
1841        request_id: u8,
1842        coils_length: u16,
1843        coils_chunk_offset: u16,
1844        coils_chunk_data: &[bool; 472],
1845    ) -> Result<ModbusSlaveAnswerReadCoilsRequestLowLevel, TinkerforgeError> {
1846        let mut payload = [0; 64];
1847        request_id.write_to_slice(&mut payload[0..1]);
1848        coils_length.write_to_slice(&mut payload[1..3]);
1849        coils_chunk_offset.write_to_slice(&mut payload[3..5]);
1850        coils_chunk_data.write_to_slice(&mut payload[5..64]);
1851
1852        #[allow(unused_variables)]
1853        let result = self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadCoilsRequestLowLevel), &payload).await?.unwrap();
1854        Ok(ModbusSlaveAnswerReadCoilsRequestLowLevel::from_le_byte_slice(result.body()))
1855    }
1856
1857    /// In Modbus master mode this function can be used to read coils from a slave. This
1858    /// function creates a Modbus function code 1 request.
1859    ///
1860    /// * Slave Address: Address of the target Modbus slave.
1861    /// * Starting Address: Number of the first coil to read. For backwards compatibility reasons this parameter is called Starting Address. It is not an address, but instead a coil number in the range of 1 to 65536.
1862    /// * Count: Number of coils to read.
1863    ///
1864    /// Upon success the function will return a non-zero request ID which will represent
1865    /// the current request initiated by the Modbus master. In case of failure the returned
1866    /// request ID will be 0.
1867    ///
1868    /// When successful this function will also invoke the [`get_modbus_master_read_coils_response_callback_receiver`]
1869    /// callback. In this receiver the Request ID provided by the receiver argument must be
1870    /// matched with the Request ID returned from this function to verify that the receiver
1871    /// is indeed for a particular request.
1872    pub async fn modbus_master_read_coils(&mut self, slave_address: u8, starting_address: u32, count: u16) -> Result<u8, TinkerforgeError> {
1873        let mut payload = [0; 7];
1874        slave_address.write_to_slice(&mut payload[0..1]);
1875        starting_address.write_to_slice(&mut payload[1..5]);
1876        count.write_to_slice(&mut payload[5..7]);
1877
1878        #[allow(unused_variables)]
1879        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadCoils), &payload).await?;
1880        Ok(u8::from_le_byte_slice(result.body()))
1881    }
1882
1883    /// In Modbus slave mode this function can be used to answer a master request to
1884    /// read holding registers.
1885    ///
1886    /// * Request ID: Request ID of the corresponding request that is being answered.
1887    /// * Holding Registers: Data that is to be sent to the Modbus master for the corresponding request.
1888    ///
1889    /// This function must be called from the [`get_modbus_slave_read_holding_registers_request_callback_receiver`]
1890    /// receiver with the Request ID as provided by the argument of the receiver.
1891    pub async fn modbus_slave_answer_read_holding_registers_request_low_level(
1892        &mut self,
1893        request_id: u8,
1894        holding_registers_length: u16,
1895        holding_registers_chunk_offset: u16,
1896        holding_registers_chunk_data: &[u16; 29],
1897    ) -> Result<ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel, TinkerforgeError> {
1898        let mut payload = [0; 63];
1899        request_id.write_to_slice(&mut payload[0..1]);
1900        holding_registers_length.write_to_slice(&mut payload[1..3]);
1901        holding_registers_chunk_offset.write_to_slice(&mut payload[3..5]);
1902        holding_registers_chunk_data.write_to_slice(&mut payload[5..63]);
1903
1904        #[allow(unused_variables)]
1905        let result = self
1906            .device
1907            .set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel), &payload)
1908            .await?
1909            .unwrap();
1910        Ok(ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel::from_le_byte_slice(result.body()))
1911    }
1912
1913    /// In Modbus master mode this function can be used to read holding registers from a slave.
1914    /// This function creates a Modbus function code 3 request.
1915    ///
1916    /// * Slave Address: Address of the target Modbus slave.
1917    /// * Starting Address: Number of the first holding register to read. For backwards compatibility reasons this parameter is called Starting Address. It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is implicit and must be omitted.
1918    /// * Count: Number of holding registers to read.
1919    ///
1920    /// Upon success the function will return a non-zero request ID which will represent
1921    /// the current request initiated by the Modbus master. In case of failure the returned
1922    /// request ID will be 0.
1923    ///
1924    /// When successful this function will also invoke the [`get_modbus_master_read_holding_registers_response_callback_receiver`]
1925    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
1926    /// with the Request ID returned from this function to verify that the receiver is indeed for a
1927    /// particular request.
1928    pub async fn modbus_master_read_holding_registers(
1929        &mut self,
1930        slave_address: u8,
1931        starting_address: u32,
1932        count: u16,
1933    ) -> Result<u8, TinkerforgeError> {
1934        let mut payload = [0; 7];
1935        slave_address.write_to_slice(&mut payload[0..1]);
1936        starting_address.write_to_slice(&mut payload[1..5]);
1937        count.write_to_slice(&mut payload[5..7]);
1938
1939        #[allow(unused_variables)]
1940        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadHoldingRegisters), &payload).await?;
1941        Ok(u8::from_le_byte_slice(result.body()))
1942    }
1943
1944    /// In Modbus slave mode this function can be used to answer a master request to
1945    /// write a single coil.
1946    ///
1947    /// * Request ID: Request ID of the corresponding request that is being answered.
1948    ///
1949    /// This function must be called from the [`get_modbus_slave_write_single_coil_request_callback_receiver`]
1950    /// receiver with the Request ID as provided by the arguments of the receiver.
1951    pub async fn modbus_slave_answer_write_single_coil_request(&mut self, request_id: u8) -> Result<(), TinkerforgeError> {
1952        let mut payload = [0; 1];
1953        request_id.write_to_slice(&mut payload[0..1]);
1954
1955        #[allow(unused_variables)]
1956        let result = self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleCoilRequest), &payload).await?;
1957        Ok(())
1958    }
1959
1960    /// In Modbus master mode this function can be used to write a single coil of a slave.
1961    /// This function creates a Modbus function code 5 request.
1962    ///
1963    /// * Slave Address: Address of the target Modbus slave.
1964    /// * Coil Address: Number of the coil to be written. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a coil number in the range of 1 to 65536.
1965    /// * Coil Value: Value to be written.
1966    ///
1967    /// Upon success the function will return a non-zero request ID which will represent
1968    /// the current request initiated by the Modbus master. In case of failure the returned
1969    /// request ID will be 0.
1970    ///
1971    /// When successful this function will also invoke the [`get_modbus_master_write_single_coil_response_callback_receiver`]
1972    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
1973    /// with the Request ID returned from this function to verify that the receiver is indeed for a
1974    /// particular request.
1975    pub async fn modbus_master_write_single_coil(
1976        &mut self,
1977        slave_address: u8,
1978        coil_address: u32,
1979        coil_value: bool,
1980    ) -> Result<u8, TinkerforgeError> {
1981        let mut payload = [0; 6];
1982        slave_address.write_to_slice(&mut payload[0..1]);
1983        coil_address.write_to_slice(&mut payload[1..5]);
1984        coil_value.write_to_slice(&mut payload[5..6]);
1985
1986        #[allow(unused_variables)]
1987        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleCoil), &payload).await?;
1988        Ok(u8::from_le_byte_slice(result.body()))
1989    }
1990
1991    /// In Modbus slave mode this function can be used to answer a master request to
1992    /// write a single register.
1993    ///
1994    /// * Request ID: Request ID of the corresponding request that is being answered.
1995    ///
1996    /// This function must be called from the [`get_modbus_slave_write_single_register_request_callback_receiver`]
1997    /// receiver with the Request ID, Register Address and Register Value as provided by
1998    /// the arguments of the receiver.
1999    pub async fn modbus_slave_answer_write_single_register_request(&mut self, request_id: u8) -> Result<(), TinkerforgeError> {
2000        let mut payload = [0; 1];
2001        request_id.write_to_slice(&mut payload[0..1]);
2002
2003        #[allow(unused_variables)]
2004        let result = self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleRegisterRequest), &payload).await?;
2005        Ok(())
2006    }
2007
2008    /// In Modbus master mode this function can be used to write a single holding register of a
2009    /// slave. This function creates a Modbus function code 6 request.
2010    ///
2011    /// * Slave Address: Address of the target Modbus slave.
2012    /// * Register Address: Number of the holding register to be written. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is implicit and must be omitted.
2013    /// * Register Value: Value to be written.
2014    ///
2015    /// Upon success the function will return a non-zero request ID which will represent
2016    /// the current request initiated by the Modbus master. In case of failure the returned
2017    /// request ID will be 0.
2018    ///
2019    /// When successful this function will also invoke the [`get_modbus_master_write_single_register_response_callback_receiver`]
2020    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
2021    /// with the Request ID returned from this function to verify that the receiver is indeed for a
2022    /// particular request.
2023    pub async fn modbus_master_write_single_register(
2024        &mut self,
2025        slave_address: u8,
2026        register_address: u32,
2027        register_value: u16,
2028    ) -> Result<u8, TinkerforgeError> {
2029        let mut payload = [0; 7];
2030        slave_address.write_to_slice(&mut payload[0..1]);
2031        register_address.write_to_slice(&mut payload[1..5]);
2032        register_value.write_to_slice(&mut payload[5..7]);
2033
2034        #[allow(unused_variables)]
2035        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleRegister), &payload).await?;
2036        Ok(u8::from_le_byte_slice(result.body()))
2037    }
2038
2039    /// In Modbus slave mode this function can be used to answer a master request to
2040    /// write multiple coils.
2041    ///
2042    /// * Request ID: Request ID of the corresponding request that is being answered.
2043    ///
2044    /// This function must be called from the [`get_modbus_slave_write_multiple_coils_request_callback_receiver`]
2045    /// receiver with the Request ID of the receiver.
2046    pub async fn modbus_slave_answer_write_multiple_coils_request(&mut self, request_id: u8) -> Result<(), TinkerforgeError> {
2047        let mut payload = [0; 1];
2048        request_id.write_to_slice(&mut payload[0..1]);
2049
2050        #[allow(unused_variables)]
2051        let result = self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleCoilsRequest), &payload).await?;
2052        Ok(())
2053    }
2054
2055    /// In Modbus master mode this function can be used to write multiple coils of a slave.
2056    /// This function creates a Modbus function code 15 request.
2057    ///
2058    /// * Slave Address: Address of the target Modbus slave.
2059    /// * Starting Address: Number of the first coil to write. For backwards compatibility reasons, this parameter is called Starting Address.It is not an address, but instead a coil number in the range of 1 to 65536.
2060    ///
2061    /// Upon success the function will return a non-zero request ID which will represent
2062    /// the current request initiated by the Modbus master. In case of failure the returned
2063    /// request ID will be 0.
2064    ///
2065    /// When successful this function will also invoke the [`get_modbus_master_write_multiple_coils_response_callback_receiver`]
2066    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
2067    /// with the Request ID returned from this function to verify that the receiver is indeed for a
2068    /// particular request.
2069    pub async fn modbus_master_write_multiple_coils_low_level(
2070        &mut self,
2071        slave_address: u8,
2072        starting_address: u32,
2073        coils_length: u16,
2074        coils_chunk_offset: u16,
2075        coils_chunk_data: &[bool; 440],
2076    ) -> Result<ModbusMasterWriteMultipleCoilsLowLevel, TinkerforgeError> {
2077        let mut payload = [0; 64];
2078        slave_address.write_to_slice(&mut payload[0..1]);
2079        starting_address.write_to_slice(&mut payload[1..5]);
2080        coils_length.write_to_slice(&mut payload[5..7]);
2081        coils_chunk_offset.write_to_slice(&mut payload[7..9]);
2082        coils_chunk_data.write_to_slice(&mut payload[9..64]);
2083
2084        #[allow(unused_variables)]
2085        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleCoilsLowLevel), &payload).await?;
2086        Ok(ModbusMasterWriteMultipleCoilsLowLevel::from_le_byte_slice(result.body()))
2087    }
2088
2089    /// In Modbus slave mode this function can be used to answer a master request to
2090    /// write multiple registers.
2091    ///
2092    /// * Request ID: Request ID of the corresponding request that is being answered.
2093    ///
2094    /// This function must be called from the [`get_modbus_slave_write_multiple_registers_request_callback_receiver`]
2095    /// receiver with the Request ID of the receiver.
2096    pub async fn modbus_slave_answer_write_multiple_registers_request(&mut self, request_id: u8) -> Result<(), TinkerforgeError> {
2097        let mut payload = [0; 1];
2098        request_id.write_to_slice(&mut payload[0..1]);
2099
2100        #[allow(unused_variables)]
2101        let result = self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleRegistersRequest), &payload).await?;
2102        Ok(())
2103    }
2104
2105    /// In Modbus master mode this function can be used to write multiple registers of a slave.
2106    /// This function creates a Modbus function code 16 request.
2107    ///
2108    /// * Slave Address: Address of the target Modbus slave.
2109    /// * Starting Address: Number of the first holding register to write. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a holding register number in the range of 1 to 65536. The prefix digit 4 (for holding register) is implicit and must be omitted.
2110    ///
2111    /// Upon success the function will return a non-zero request ID which will represent
2112    /// the current request initiated by the Modbus master. In case of failure the returned
2113    /// request ID will be 0.
2114    ///
2115    /// When successful this function will also invoke the [`get_modbus_master_write_multiple_registers_response_callback_receiver`]
2116    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
2117    /// with the Request ID returned from this function to verify that the receiver is indeed for a
2118    /// particular request.
2119    pub async fn modbus_master_write_multiple_registers_low_level(
2120        &mut self,
2121        slave_address: u8,
2122        starting_address: u32,
2123        registers_length: u16,
2124        registers_chunk_offset: u16,
2125        registers_chunk_data: &[u16; 27],
2126    ) -> Result<ModbusMasterWriteMultipleRegistersLowLevel, TinkerforgeError> {
2127        let mut payload = [0; 63];
2128        slave_address.write_to_slice(&mut payload[0..1]);
2129        starting_address.write_to_slice(&mut payload[1..5]);
2130        registers_length.write_to_slice(&mut payload[5..7]);
2131        registers_chunk_offset.write_to_slice(&mut payload[7..9]);
2132        registers_chunk_data.write_to_slice(&mut payload[9..63]);
2133
2134        #[allow(unused_variables)]
2135        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleRegistersLowLevel), &payload).await?;
2136        Ok(ModbusMasterWriteMultipleRegistersLowLevel::from_le_byte_slice(result.body()))
2137    }
2138
2139    /// In Modbus slave mode this function can be used to answer a master request to
2140    /// read discrete inputs.
2141    ///
2142    /// * Request ID: Request ID of the corresponding request that is being answered.
2143    /// * Discrete Inputs: Data that is to be sent to the Modbus master for the corresponding request.
2144    ///
2145    /// This function must be called from the [`get_modbus_slave_read_discrete_inputs_request_callback_receiver`]
2146    /// receiver with the Request ID as provided by the argument of the receiver.
2147    pub async fn modbus_slave_answer_read_discrete_inputs_request_low_level(
2148        &mut self,
2149        request_id: u8,
2150        discrete_inputs_length: u16,
2151        discrete_inputs_chunk_offset: u16,
2152        discrete_inputs_chunk_data: &[bool; 472],
2153    ) -> Result<ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel, TinkerforgeError> {
2154        let mut payload = [0; 64];
2155        request_id.write_to_slice(&mut payload[0..1]);
2156        discrete_inputs_length.write_to_slice(&mut payload[1..3]);
2157        discrete_inputs_chunk_offset.write_to_slice(&mut payload[3..5]);
2158        discrete_inputs_chunk_data.write_to_slice(&mut payload[5..64]);
2159
2160        #[allow(unused_variables)]
2161        let result =
2162            self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel), &payload).await?.unwrap();
2163        Ok(ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel::from_le_byte_slice(result.body()))
2164    }
2165
2166    /// In Modbus master mode this function can be used to read discrete inputs from a slave.
2167    /// This function creates a Modbus function code 2 request.
2168    ///
2169    /// * Slave Address: Address of the target Modbus slave.
2170    /// * Starting Address: Number of the first discrete input to read. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead a discrete input number in the range of 1 to 65536. The prefix digit 1 (for discrete input) is implicit and must be omitted.
2171    /// * Count: Number of discrete inputs to read.
2172    ///
2173    /// Upon success the function will return a non-zero request ID which will represent
2174    /// the current request initiated by the Modbus master. In case of failure the returned
2175    /// request ID will be 0.
2176    ///
2177    /// When successful this function will also invoke the [`get_modbus_master_read_discrete_inputs_response_callback_receiver`]
2178    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
2179    /// with the Request ID returned from this function to verify that the receiver is indeed for a
2180    /// particular request.
2181    pub async fn modbus_master_read_discrete_inputs(
2182        &mut self,
2183        slave_address: u8,
2184        starting_address: u32,
2185        count: u16,
2186    ) -> Result<u8, TinkerforgeError> {
2187        let mut payload = [0; 7];
2188        slave_address.write_to_slice(&mut payload[0..1]);
2189        starting_address.write_to_slice(&mut payload[1..5]);
2190        count.write_to_slice(&mut payload[5..7]);
2191
2192        #[allow(unused_variables)]
2193        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadDiscreteInputs), &payload).await?;
2194        Ok(u8::from_le_byte_slice(result.body()))
2195    }
2196
2197    /// In Modbus slave mode this function can be used to answer a master request to
2198    /// read input registers.
2199    ///
2200    /// * Request ID: Request ID of the corresponding request that is being answered.
2201    /// * Input Registers: Data that is to be sent to the Modbus master for the corresponding request.
2202    ///
2203    /// This function must be called from the [`get_modbus_slave_read_input_registers_request_callback_receiver`] receiver
2204    /// with the Request ID as provided by the argument of the receiver.
2205    pub async fn modbus_slave_answer_read_input_registers_request_low_level(
2206        &mut self,
2207        request_id: u8,
2208        input_registers_length: u16,
2209        input_registers_chunk_offset: u16,
2210        input_registers_chunk_data: &[u16; 29],
2211    ) -> Result<ModbusSlaveAnswerReadInputRegistersRequestLowLevel, TinkerforgeError> {
2212        let mut payload = [0; 63];
2213        request_id.write_to_slice(&mut payload[0..1]);
2214        input_registers_length.write_to_slice(&mut payload[1..3]);
2215        input_registers_chunk_offset.write_to_slice(&mut payload[3..5]);
2216        input_registers_chunk_data.write_to_slice(&mut payload[5..63]);
2217
2218        #[allow(unused_variables)]
2219        let result =
2220            self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadInputRegistersRequestLowLevel), &payload).await?.unwrap();
2221        Ok(ModbusSlaveAnswerReadInputRegistersRequestLowLevel::from_le_byte_slice(result.body()))
2222    }
2223
2224    /// In Modbus master mode this function can be used to read input registers from a slave.
2225    /// This function creates a Modbus function code 4 request.
2226    ///
2227    /// * Slave Address: Address of the target Modbus slave.
2228    /// * Starting Address: Number of the first input register to read. For backwards compatibility reasons, this parameter is called Starting Address. It is not an address, but instead an input register number in the range of 1 to 65536. The prefix digit 3 (for input register) is implicit and must be omitted.
2229    /// * Count: Number of input registers to read.
2230    ///
2231    /// Upon success the function will return a non-zero request ID which will represent
2232    /// the current request initiated by the Modbus master. In case of failure the returned
2233    /// request ID will be 0.
2234    ///
2235    /// When successful this function will also invoke the [`get_modbus_master_read_input_registers_response_callback_receiver`]
2236    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
2237    /// with the Request ID returned from this function to verify that the receiver is indeed for a
2238    /// particular request.
2239    pub async fn modbus_master_read_input_registers(
2240        &mut self,
2241        slave_address: u8,
2242        starting_address: u32,
2243        count: u16,
2244    ) -> Result<u8, TinkerforgeError> {
2245        let mut payload = [0; 7];
2246        slave_address.write_to_slice(&mut payload[0..1]);
2247        starting_address.write_to_slice(&mut payload[1..5]);
2248        count.write_to_slice(&mut payload[5..7]);
2249
2250        #[allow(unused_variables)]
2251        let result = self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadInputRegisters), &payload).await?;
2252        Ok(u8::from_le_byte_slice(result.body()))
2253    }
2254
2255    /// 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.
2256    /// 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.
2257    ///
2258    /// By default the receiver is disabled.
2259    ///
2260    ///
2261    /// .. versionadded:: 2.0.5$nbsp;(Plugin)
2262    pub async fn set_frame_readable_callback_configuration(&mut self, frame_size: u16) -> Result<(), TinkerforgeError> {
2263        let mut payload = [0; 2];
2264        frame_size.write_to_slice(&mut payload[0..2]);
2265
2266        #[allow(unused_variables)]
2267        let result = self.device.set(u8::from(Rs485BrickletFunction::SetFrameReadableCallbackConfiguration), &payload).await?;
2268        Ok(())
2269    }
2270
2271    /// Returns the receiver configuration as set by [`set_frame_readable_callback_configuration`].
2272    ///
2273    ///
2274    /// .. versionadded:: 2.0.5$nbsp;(Plugin)
2275    pub async fn get_frame_readable_callback_configuration(&mut self) -> Result<u16, TinkerforgeError> {
2276        let payload = [0; 0];
2277
2278        #[allow(unused_variables)]
2279        let result = self.device.get(u8::from(Rs485BrickletFunction::GetFrameReadableCallbackConfiguration), &payload).await?;
2280        Ok(u16::from_le_byte_slice(result.body()))
2281    }
2282
2283    /// Returns the error count for the communication between Brick and Bricklet.
2284    ///
2285    /// The errors are divided into
2286    ///
2287    /// * ACK checksum errors,
2288    /// * message checksum errors,
2289    /// * framing errors and
2290    /// * overflow errors.
2291    ///
2292    /// The errors counts are for errors that occur on the Bricklet side. All
2293    /// Bricks have a similar function that returns the errors on the Brick side.
2294    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
2295        let payload = [0; 0];
2296
2297        #[allow(unused_variables)]
2298        let result = self.device.get(u8::from(Rs485BrickletFunction::GetSpitfpErrorCount), &payload).await?;
2299        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
2300    }
2301
2302    /// Sets the bootloader mode and returns the status after the requested
2303    /// mode change was instigated.
2304    ///
2305    /// You can change from bootloader mode to firmware mode and vice versa. A change
2306    /// from bootloader mode to firmware mode will only take place if the entry function,
2307    /// device identifier and CRC are present and correct.
2308    ///
2309    /// This function is used by Brick Viewer during flashing. It should not be
2310    /// necessary to call it in a normal user program.
2311    ///
2312    /// Associated constants:
2313    /// * RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
2314    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE
2315    ///	* RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
2316    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
2317    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
2318    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_OK
2319    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
2320    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
2321    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
2322    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
2323    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
2324    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
2325        let mut payload = [0; 1];
2326        mode.write_to_slice(&mut payload[0..1]);
2327
2328        #[allow(unused_variables)]
2329        let result = self.device.get(u8::from(Rs485BrickletFunction::SetBootloaderMode), &payload).await?;
2330        Ok(u8::from_le_byte_slice(result.body()))
2331    }
2332
2333    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
2334    ///
2335    /// Associated constants:
2336    /// * RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
2337    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE
2338    ///	* RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
2339    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
2340    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
2341    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
2342        let payload = [0; 0];
2343
2344        #[allow(unused_variables)]
2345        let result = self.device.get(u8::from(Rs485BrickletFunction::GetBootloaderMode), &payload).await?;
2346        Ok(u8::from_le_byte_slice(result.body()))
2347    }
2348
2349    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
2350    /// to be increased by chunks of size 64. The data is written to flash
2351    /// every 4 chunks (which equals to one page of size 256).
2352    ///
2353    /// This function is used by Brick Viewer during flashing. It should not be
2354    /// necessary to call it in a normal user program.
2355    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
2356        let mut payload = [0; 4];
2357        pointer.write_to_slice(&mut payload[0..4]);
2358
2359        #[allow(unused_variables)]
2360        let result = self.device.set(u8::from(Rs485BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
2361        Ok(())
2362    }
2363
2364    /// Writes 64 Bytes of firmware at the position as written by
2365    /// [`set_write_firmware_pointer`] before. The firmware is written
2366    /// to flash every 4 chunks.
2367    ///
2368    /// You can only write firmware in bootloader mode.
2369    ///
2370    /// This function is used by Brick Viewer during flashing. It should not be
2371    /// necessary to call it in a normal user program.
2372    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
2373        let mut payload = [0; 64];
2374        data.write_to_slice(&mut payload[0..64]);
2375
2376        #[allow(unused_variables)]
2377        let result = self.device.get(u8::from(Rs485BrickletFunction::WriteFirmware), &payload).await?;
2378        Ok(u8::from_le_byte_slice(result.body()))
2379    }
2380
2381    /// Sets the status LED configuration. By default the LED shows
2382    /// communication traffic between Brick and Bricklet, it flickers once
2383    /// for every 10 received data packets.
2384    ///
2385    /// You can also turn the LED permanently on/off or show a heartbeat.
2386    ///
2387    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
2388    ///
2389    /// Associated constants:
2390    /// * RS485_BRICKLET_STATUS_LED_CONFIG_OFF
2391    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_ON
2392    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
2393    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
2394    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
2395        let mut payload = [0; 1];
2396        config.write_to_slice(&mut payload[0..1]);
2397
2398        #[allow(unused_variables)]
2399        let result = self.device.set(u8::from(Rs485BrickletFunction::SetStatusLedConfig), &payload).await?;
2400        Ok(())
2401    }
2402
2403    /// Returns the configuration as set by [`set_status_led_config`]
2404    ///
2405    /// Associated constants:
2406    /// * RS485_BRICKLET_STATUS_LED_CONFIG_OFF
2407    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_ON
2408    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
2409    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
2410    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
2411        let payload = [0; 0];
2412
2413        #[allow(unused_variables)]
2414        let result = self.device.get(u8::from(Rs485BrickletFunction::GetStatusLedConfig), &payload).await?;
2415        Ok(u8::from_le_byte_slice(result.body()))
2416    }
2417
2418    /// Returns the temperature as measured inside the microcontroller. The
2419    /// value returned is not the ambient temperature!
2420    ///
2421    /// The temperature is only proportional to the real temperature and it has bad
2422    /// accuracy. Practically it is only useful as an indicator for
2423    /// temperature changes.
2424    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
2425        let payload = [0; 0];
2426
2427        #[allow(unused_variables)]
2428        let result = self.device.get(u8::from(Rs485BrickletFunction::GetChipTemperature), &payload).await?;
2429        Ok(i16::from_le_byte_slice(result.body()))
2430    }
2431
2432    /// Calling this function will reset the Bricklet. All configurations
2433    /// will be lost.
2434    ///
2435    /// After a reset you have to create new device objects,
2436    /// calling functions on the existing ones will result in
2437    /// undefined behavior!
2438    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
2439        let payload = [0; 0];
2440
2441        #[allow(unused_variables)]
2442        let result = self.device.set(u8::from(Rs485BrickletFunction::Reset), &payload).await?;
2443        Ok(())
2444    }
2445
2446    /// Writes a new UID into flash. If you want to set a new UID
2447    /// you have to decode the Base58 encoded UID string into an
2448    /// integer first.
2449    ///
2450    /// We recommend that you use Brick Viewer to change the UID.
2451    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
2452        let mut payload = [0; 4];
2453        uid.write_to_slice(&mut payload[0..4]);
2454
2455        #[allow(unused_variables)]
2456        let result = self.device.set(u8::from(Rs485BrickletFunction::WriteUid), &payload).await?;
2457        Ok(())
2458    }
2459
2460    /// Returns the current UID as an integer. Encode as
2461    /// Base58 to get the usual string version.
2462    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
2463        let payload = [0; 0];
2464
2465        #[allow(unused_variables)]
2466        let result = self.device.get(u8::from(Rs485BrickletFunction::ReadUid), &payload).await?;
2467        Ok(u32::from_le_byte_slice(result.body()))
2468    }
2469
2470    /// Returns the UID, the UID where the Bricklet is connected to,
2471    /// the position, the hardware and firmware version as well as the
2472    /// device identifier.
2473    ///
2474    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
2475    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
2476    /// position 'z'.
2477    ///
2478    /// The device identifier numbers can be found [here](device_identifier).
2479    /// |device_identifier_constant|
2480    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
2481        let payload = [0; 0];
2482
2483        #[allow(unused_variables)]
2484        let result = self.device.get(u8::from(Rs485BrickletFunction::GetIdentity), &payload).await?;
2485        Ok(Identity::from_le_byte_slice(result.body()))
2486    }
2487}