1#[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 Rs232V2BrickletFunction {
25 WriteLowLevel,
26 ReadLowLevel,
27 EnableReadCallback,
28 DisableReadCallback,
29 IsReadCallbackEnabled,
30 SetConfiguration,
31 GetConfiguration,
32 SetBufferConfig,
33 GetBufferConfig,
34 GetBufferStatus,
35 GetErrorCount,
36 SetFrameReadableCallbackConfiguration,
37 GetFrameReadableCallbackConfiguration,
38 GetSpitfpErrorCount,
39 SetBootloaderMode,
40 GetBootloaderMode,
41 SetWriteFirmwarePointer,
42 WriteFirmware,
43 SetStatusLedConfig,
44 GetStatusLedConfig,
45 GetChipTemperature,
46 Reset,
47 WriteUid,
48 ReadUid,
49 GetIdentity,
50 CallbackReadLowLevel,
51 CallbackErrorCount,
52 CallbackFrameReadable,
53}
54impl From<Rs232V2BrickletFunction> for u8 {
55 fn from(fun: Rs232V2BrickletFunction) -> Self {
56 match fun {
57 Rs232V2BrickletFunction::WriteLowLevel => 1,
58 Rs232V2BrickletFunction::ReadLowLevel => 2,
59 Rs232V2BrickletFunction::EnableReadCallback => 3,
60 Rs232V2BrickletFunction::DisableReadCallback => 4,
61 Rs232V2BrickletFunction::IsReadCallbackEnabled => 5,
62 Rs232V2BrickletFunction::SetConfiguration => 6,
63 Rs232V2BrickletFunction::GetConfiguration => 7,
64 Rs232V2BrickletFunction::SetBufferConfig => 8,
65 Rs232V2BrickletFunction::GetBufferConfig => 9,
66 Rs232V2BrickletFunction::GetBufferStatus => 10,
67 Rs232V2BrickletFunction::GetErrorCount => 11,
68 Rs232V2BrickletFunction::SetFrameReadableCallbackConfiguration => 14,
69 Rs232V2BrickletFunction::GetFrameReadableCallbackConfiguration => 15,
70 Rs232V2BrickletFunction::GetSpitfpErrorCount => 234,
71 Rs232V2BrickletFunction::SetBootloaderMode => 235,
72 Rs232V2BrickletFunction::GetBootloaderMode => 236,
73 Rs232V2BrickletFunction::SetWriteFirmwarePointer => 237,
74 Rs232V2BrickletFunction::WriteFirmware => 238,
75 Rs232V2BrickletFunction::SetStatusLedConfig => 239,
76 Rs232V2BrickletFunction::GetStatusLedConfig => 240,
77 Rs232V2BrickletFunction::GetChipTemperature => 242,
78 Rs232V2BrickletFunction::Reset => 243,
79 Rs232V2BrickletFunction::WriteUid => 248,
80 Rs232V2BrickletFunction::ReadUid => 249,
81 Rs232V2BrickletFunction::GetIdentity => 255,
82 Rs232V2BrickletFunction::CallbackReadLowLevel => 12,
83 Rs232V2BrickletFunction::CallbackErrorCount => 13,
84 Rs232V2BrickletFunction::CallbackFrameReadable => 16,
85 }
86 }
87}
88pub const RS232_V2_BRICKLET_PARITY_NONE: u8 = 0;
89pub const RS232_V2_BRICKLET_PARITY_ODD: u8 = 1;
90pub const RS232_V2_BRICKLET_PARITY_EVEN: u8 = 2;
91pub const RS232_V2_BRICKLET_STOPBITS_1: u8 = 1;
92pub const RS232_V2_BRICKLET_STOPBITS_2: u8 = 2;
93pub const RS232_V2_BRICKLET_WORDLENGTH_5: u8 = 5;
94pub const RS232_V2_BRICKLET_WORDLENGTH_6: u8 = 6;
95pub const RS232_V2_BRICKLET_WORDLENGTH_7: u8 = 7;
96pub const RS232_V2_BRICKLET_WORDLENGTH_8: u8 = 8;
97pub const RS232_V2_BRICKLET_FLOWCONTROL_OFF: u8 = 0;
98pub const RS232_V2_BRICKLET_FLOWCONTROL_SOFTWARE: u8 = 1;
99pub const RS232_V2_BRICKLET_FLOWCONTROL_HARDWARE: u8 = 2;
100pub const RS232_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
101pub const RS232_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
102pub const RS232_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
103pub const RS232_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
104pub const RS232_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
105pub const RS232_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
106pub const RS232_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
107pub const RS232_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
108pub const RS232_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
109pub const RS232_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
110pub const RS232_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
111pub const RS232_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
112pub const RS232_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
113pub const RS232_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
114pub const RS232_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
115
116#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
117pub struct WriteLowLevel {
118 pub message_chunk_written: u8,
119}
120impl FromByteSlice for WriteLowLevel {
121 fn bytes_expected() -> usize {
122 1
123 }
124 fn from_le_byte_slice(bytes: &[u8]) -> WriteLowLevel {
125 WriteLowLevel { message_chunk_written: <u8>::from_le_byte_slice(&bytes[0..1]) }
126 }
127}
128
129#[derive(Clone, Copy)]
130pub struct ReadLowLevel {
131 pub message_length: u16,
132 pub message_chunk_offset: u16,
133 pub message_chunk_data: [char; 60],
134}
135impl FromByteSlice for ReadLowLevel {
136 fn bytes_expected() -> usize {
137 64
138 }
139 fn from_le_byte_slice(bytes: &[u8]) -> ReadLowLevel {
140 ReadLowLevel {
141 message_length: <u16>::from_le_byte_slice(&bytes[0..2]),
142 message_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
143 message_chunk_data: <[char; 60]>::from_le_byte_slice(&bytes[4..64]),
144 }
145 }
146}
147impl LowLevelRead<char, ReadResult> for ReadLowLevel {
148 fn ll_message_length(&self) -> usize {
149 self.message_length as usize
150 }
151
152 fn ll_message_chunk_offset(&self) -> usize {
153 self.message_chunk_offset as usize
154 }
155
156 fn ll_message_chunk_data(&self) -> &[char] {
157 &self.message_chunk_data
158 }
159
160 fn get_result(&self) -> ReadResult {
161 ReadResult {}
162 }
163}
164
165#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
166pub struct Configuration {
167 pub baudrate: u32,
168 pub parity: u8,
169 pub stopbits: u8,
170 pub wordlength: u8,
171 pub flowcontrol: u8,
172}
173impl FromByteSlice for Configuration {
174 fn bytes_expected() -> usize {
175 8
176 }
177 fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
178 Configuration {
179 baudrate: <u32>::from_le_byte_slice(&bytes[0..4]),
180 parity: <u8>::from_le_byte_slice(&bytes[4..5]),
181 stopbits: <u8>::from_le_byte_slice(&bytes[5..6]),
182 wordlength: <u8>::from_le_byte_slice(&bytes[6..7]),
183 flowcontrol: <u8>::from_le_byte_slice(&bytes[7..8]),
184 }
185 }
186}
187
188#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
189pub struct BufferConfig {
190 pub send_buffer_size: u16,
191 pub receive_buffer_size: u16,
192}
193impl FromByteSlice for BufferConfig {
194 fn bytes_expected() -> usize {
195 4
196 }
197 fn from_le_byte_slice(bytes: &[u8]) -> BufferConfig {
198 BufferConfig {
199 send_buffer_size: <u16>::from_le_byte_slice(&bytes[0..2]),
200 receive_buffer_size: <u16>::from_le_byte_slice(&bytes[2..4]),
201 }
202 }
203}
204
205#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
206pub struct BufferStatus {
207 pub send_buffer_used: u16,
208 pub receive_buffer_used: u16,
209}
210impl FromByteSlice for BufferStatus {
211 fn bytes_expected() -> usize {
212 4
213 }
214 fn from_le_byte_slice(bytes: &[u8]) -> BufferStatus {
215 BufferStatus {
216 send_buffer_used: <u16>::from_le_byte_slice(&bytes[0..2]),
217 receive_buffer_used: <u16>::from_le_byte_slice(&bytes[2..4]),
218 }
219 }
220}
221
222#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
223pub struct ErrorCount {
224 pub error_count_overrun: u32,
225 pub error_count_parity: u32,
226}
227impl FromByteSlice for ErrorCount {
228 fn bytes_expected() -> usize {
229 8
230 }
231 fn from_le_byte_slice(bytes: &[u8]) -> ErrorCount {
232 ErrorCount {
233 error_count_overrun: <u32>::from_le_byte_slice(&bytes[0..4]),
234 error_count_parity: <u32>::from_le_byte_slice(&bytes[4..8]),
235 }
236 }
237}
238
239#[derive(Clone, Copy)]
240pub struct ReadLowLevelEvent {
241 pub message_length: u16,
242 pub message_chunk_offset: u16,
243 pub message_chunk_data: [char; 60],
244}
245impl FromByteSlice for ReadLowLevelEvent {
246 fn bytes_expected() -> usize {
247 64
248 }
249 fn from_le_byte_slice(bytes: &[u8]) -> ReadLowLevelEvent {
250 ReadLowLevelEvent {
251 message_length: <u16>::from_le_byte_slice(&bytes[0..2]),
252 message_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
253 message_chunk_data: <[char; 60]>::from_le_byte_slice(&bytes[4..64]),
254 }
255 }
256}
257impl LowLevelRead<char, ReadResult> for ReadLowLevelEvent {
258 fn ll_message_length(&self) -> usize {
259 self.message_length as usize
260 }
261
262 fn ll_message_chunk_offset(&self) -> usize {
263 self.message_chunk_offset as usize
264 }
265
266 fn ll_message_chunk_data(&self) -> &[char] {
267 &self.message_chunk_data
268 }
269
270 fn get_result(&self) -> ReadResult {
271 ReadResult {}
272 }
273}
274
275#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
276pub struct ErrorCountEvent {
277 pub error_count_overrun: u32,
278 pub error_count_parity: u32,
279}
280impl FromByteSlice for ErrorCountEvent {
281 fn bytes_expected() -> usize {
282 8
283 }
284 fn from_le_byte_slice(bytes: &[u8]) -> ErrorCountEvent {
285 ErrorCountEvent {
286 error_count_overrun: <u32>::from_le_byte_slice(&bytes[0..4]),
287 error_count_parity: <u32>::from_le_byte_slice(&bytes[4..8]),
288 }
289 }
290}
291
292#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
293pub struct SpitfpErrorCount {
294 pub error_count_ack_checksum: u32,
295 pub error_count_message_checksum: u32,
296 pub error_count_frame: u32,
297 pub error_count_overflow: u32,
298}
299impl FromByteSlice for SpitfpErrorCount {
300 fn bytes_expected() -> usize {
301 16
302 }
303 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
304 SpitfpErrorCount {
305 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
306 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
307 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
308 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
309 }
310 }
311}
312
313#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
314pub struct Identity {
315 pub uid: String,
316 pub connected_uid: String,
317 pub position: char,
318 pub hardware_version: [u8; 3],
319 pub firmware_version: [u8; 3],
320 pub device_identifier: u16,
321}
322impl FromByteSlice for Identity {
323 fn bytes_expected() -> usize {
324 25
325 }
326 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
327 Identity {
328 uid: <String>::from_le_byte_slice(&bytes[0..8]),
329 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
330 position: <char>::from_le_byte_slice(&bytes[16..17]),
331 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
332 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
333 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
334 }
335 }
336}
337
338#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
339pub struct WriteResult {}
340
341#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
342pub struct ReadResult {}
343
344#[derive(Clone)]
346pub struct Rs232V2Bricklet {
347 device: Device,
348}
349impl Rs232V2Bricklet {
350 pub const DEVICE_IDENTIFIER: u16 = 2108;
351 pub const DEVICE_DISPLAY_NAME: &'static str = "RS232 Bricklet 2.0";
352 pub fn new(uid: Uid, connection: AsyncIpConnection) -> Rs232V2Bricklet {
354 let mut result = Rs232V2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
355 result.device.response_expected[u8::from(Rs232V2BrickletFunction::WriteLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
356 result.device.response_expected[u8::from(Rs232V2BrickletFunction::ReadLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
357 result.device.response_expected[u8::from(Rs232V2BrickletFunction::EnableReadCallback) as usize] = ResponseExpectedFlag::True;
358 result.device.response_expected[u8::from(Rs232V2BrickletFunction::DisableReadCallback) as usize] = ResponseExpectedFlag::True;
359 result.device.response_expected[u8::from(Rs232V2BrickletFunction::IsReadCallbackEnabled) as usize] =
360 ResponseExpectedFlag::AlwaysTrue;
361 result.device.response_expected[u8::from(Rs232V2BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
362 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
363 result.device.response_expected[u8::from(Rs232V2BrickletFunction::SetBufferConfig) as usize] = ResponseExpectedFlag::False;
364 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetBufferConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
365 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetBufferStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
366 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
367 result.device.response_expected[u8::from(Rs232V2BrickletFunction::SetFrameReadableCallbackConfiguration) as usize] =
368 ResponseExpectedFlag::True;
369 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetFrameReadableCallbackConfiguration) as usize] =
370 ResponseExpectedFlag::AlwaysTrue;
371 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
372 result.device.response_expected[u8::from(Rs232V2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
373 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
374 result.device.response_expected[u8::from(Rs232V2BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
375 result.device.response_expected[u8::from(Rs232V2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
376 result.device.response_expected[u8::from(Rs232V2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
377 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
378 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
379 result.device.response_expected[u8::from(Rs232V2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
380 result.device.response_expected[u8::from(Rs232V2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
381 result.device.response_expected[u8::from(Rs232V2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
382 result.device.response_expected[u8::from(Rs232V2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
383 result
384 }
385
386 pub fn get_response_expected(&mut self, fun: Rs232V2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
401 self.device.get_response_expected(u8::from(fun))
402 }
403
404 pub fn set_response_expected(&mut self, fun: Rs232V2BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
413 self.device.set_response_expected(u8::from(fun), response_expected)
414 }
415
416 pub fn set_response_expected_all(&mut self, response_expected: bool) {
418 self.device.set_response_expected_all(response_expected)
419 }
420
421 pub fn get_api_version(&self) -> [u8; 3] {
424 self.device.api_version
425 }
426
427 pub async fn get_read_low_level_callback_receiver(&mut self) -> impl Stream<Item = ReadLowLevelEvent> {
429 self.device
430 .get_callback_receiver(u8::from(Rs232V2BrickletFunction::CallbackReadLowLevel))
431 .await
432 .map(|p| ReadLowLevelEvent::from_le_byte_slice(p.body()))
433 }
434
435 pub async fn get_error_count_callback_receiver(&mut self) -> impl Stream<Item = ErrorCountEvent> {
438 self.device
439 .get_callback_receiver(u8::from(Rs232V2BrickletFunction::CallbackErrorCount))
440 .await
441 .map(|p| ErrorCountEvent::from_le_byte_slice(p.body()))
442 }
443
444 pub async fn get_frame_readable_callback_receiver(&mut self) -> impl Stream<Item = u16> {
452 self.device
453 .get_callback_receiver(u8::from(Rs232V2BrickletFunction::CallbackFrameReadable))
454 .await
455 .map(|p| u16::from_le_byte_slice(p.body()))
456 }
457
458 pub async fn write_low_level(
466 &mut self,
467 message_length: u16,
468 message_chunk_offset: u16,
469 message_chunk_data: &[char; 60],
470 ) -> Result<WriteLowLevel, TinkerforgeError> {
471 let mut payload = [0; 64];
472 message_length.write_to_slice(&mut payload[0..2]);
473 message_chunk_offset.write_to_slice(&mut payload[2..4]);
474 message_chunk_data.write_to_slice(&mut payload[4..64]);
475
476 #[allow(unused_variables)]
477 let result = self.device.get(u8::from(Rs232V2BrickletFunction::WriteLowLevel), &payload).await?;
478 Ok(WriteLowLevel::from_le_byte_slice(result.body()))
479 }
480
481 pub async fn read_low_level(&mut self, length: u16) -> Result<ReadLowLevel, TinkerforgeError> {
488 let mut payload = [0; 2];
489 length.write_to_slice(&mut payload[0..2]);
490
491 #[allow(unused_variables)]
492 let result = self.device.get(u8::from(Rs232V2BrickletFunction::ReadLowLevel), &payload).await?;
493 Ok(ReadLowLevel::from_le_byte_slice(result.body()))
494 }
495
496 pub async fn enable_read_callback(&mut self) -> Result<(), TinkerforgeError> {
500 let payload = [0; 0];
501
502 #[allow(unused_variables)]
503 let result = self.device.set(u8::from(Rs232V2BrickletFunction::EnableReadCallback), &payload).await?;
504 Ok(())
505 }
506
507 pub async fn disable_read_callback(&mut self) -> Result<(), TinkerforgeError> {
511 let payload = [0; 0];
512
513 #[allow(unused_variables)]
514 let result = self.device.set(u8::from(Rs232V2BrickletFunction::DisableReadCallback), &payload).await?;
515 Ok(())
516 }
517
518 pub async fn is_read_callback_enabled(&mut self) -> Result<bool, TinkerforgeError> {
521 let payload = [0; 0];
522
523 #[allow(unused_variables)]
524 let result = self.device.get(u8::from(Rs232V2BrickletFunction::IsReadCallbackEnabled), &payload).await?;
525 Ok(bool::from_le_byte_slice(result.body()))
526 }
527
528 pub async fn set_configuration(
544 &mut self,
545 baudrate: u32,
546 parity: u8,
547 stopbits: u8,
548 wordlength: u8,
549 flowcontrol: u8,
550 ) -> Result<(), TinkerforgeError> {
551 let mut payload = [0; 8];
552 baudrate.write_to_slice(&mut payload[0..4]);
553 parity.write_to_slice(&mut payload[4..5]);
554 stopbits.write_to_slice(&mut payload[5..6]);
555 wordlength.write_to_slice(&mut payload[6..7]);
556 flowcontrol.write_to_slice(&mut payload[7..8]);
557
558 #[allow(unused_variables)]
559 let result = self.device.set(u8::from(Rs232V2BrickletFunction::SetConfiguration), &payload).await?;
560 Ok(())
561 }
562
563 pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
579 let payload = [0; 0];
580
581 #[allow(unused_variables)]
582 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetConfiguration), &payload).await?;
583 Ok(Configuration::from_le_byte_slice(result.body()))
584 }
585
586 pub async fn set_buffer_config(&mut self, send_buffer_size: u16, receive_buffer_size: u16) -> Result<(), TinkerforgeError> {
596 let mut payload = [0; 4];
597 send_buffer_size.write_to_slice(&mut payload[0..2]);
598 receive_buffer_size.write_to_slice(&mut payload[2..4]);
599
600 #[allow(unused_variables)]
601 let result = self.device.set(u8::from(Rs232V2BrickletFunction::SetBufferConfig), &payload).await?;
602 Ok(())
603 }
604
605 pub async fn get_buffer_config(&mut self) -> Result<BufferConfig, TinkerforgeError> {
607 let payload = [0; 0];
608
609 #[allow(unused_variables)]
610 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetBufferConfig), &payload).await?;
611 Ok(BufferConfig::from_le_byte_slice(result.body()))
612 }
613
614 pub async fn get_buffer_status(&mut self) -> Result<BufferStatus, TinkerforgeError> {
618 let payload = [0; 0];
619
620 #[allow(unused_variables)]
621 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetBufferStatus), &payload).await?;
622 Ok(BufferStatus::from_le_byte_slice(result.body()))
623 }
624
625 pub async fn get_error_count(&mut self) -> Result<ErrorCount, TinkerforgeError> {
627 let payload = [0; 0];
628
629 #[allow(unused_variables)]
630 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetErrorCount), &payload).await?;
631 Ok(ErrorCount::from_le_byte_slice(result.body()))
632 }
633
634 pub async fn set_frame_readable_callback_configuration(&mut self, frame_size: u16) -> Result<(), TinkerforgeError> {
642 let mut payload = [0; 2];
643 frame_size.write_to_slice(&mut payload[0..2]);
644
645 #[allow(unused_variables)]
646 let result = self.device.set(u8::from(Rs232V2BrickletFunction::SetFrameReadableCallbackConfiguration), &payload).await?;
647 Ok(())
648 }
649
650 pub async fn get_frame_readable_callback_configuration(&mut self) -> Result<u16, TinkerforgeError> {
655 let payload = [0; 0];
656
657 #[allow(unused_variables)]
658 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetFrameReadableCallbackConfiguration), &payload).await?;
659 Ok(u16::from_le_byte_slice(result.body()))
660 }
661
662 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
674 let payload = [0; 0];
675
676 #[allow(unused_variables)]
677 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
678 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
679 }
680
681 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
704 let mut payload = [0; 1];
705 mode.write_to_slice(&mut payload[0..1]);
706
707 #[allow(unused_variables)]
708 let result = self.device.get(u8::from(Rs232V2BrickletFunction::SetBootloaderMode), &payload).await?;
709 Ok(u8::from_le_byte_slice(result.body()))
710 }
711
712 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
721 let payload = [0; 0];
722
723 #[allow(unused_variables)]
724 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetBootloaderMode), &payload).await?;
725 Ok(u8::from_le_byte_slice(result.body()))
726 }
727
728 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
735 let mut payload = [0; 4];
736 pointer.write_to_slice(&mut payload[0..4]);
737
738 #[allow(unused_variables)]
739 let result = self.device.set(u8::from(Rs232V2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
740 Ok(())
741 }
742
743 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
752 let mut payload = [0; 64];
753 data.write_to_slice(&mut payload[0..64]);
754
755 #[allow(unused_variables)]
756 let result = self.device.get(u8::from(Rs232V2BrickletFunction::WriteFirmware), &payload).await?;
757 Ok(u8::from_le_byte_slice(result.body()))
758 }
759
760 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
774 let mut payload = [0; 1];
775 config.write_to_slice(&mut payload[0..1]);
776
777 #[allow(unused_variables)]
778 let result = self.device.set(u8::from(Rs232V2BrickletFunction::SetStatusLedConfig), &payload).await?;
779 Ok(())
780 }
781
782 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
790 let payload = [0; 0];
791
792 #[allow(unused_variables)]
793 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetStatusLedConfig), &payload).await?;
794 Ok(u8::from_le_byte_slice(result.body()))
795 }
796
797 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
804 let payload = [0; 0];
805
806 #[allow(unused_variables)]
807 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetChipTemperature), &payload).await?;
808 Ok(i16::from_le_byte_slice(result.body()))
809 }
810
811 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
818 let payload = [0; 0];
819
820 #[allow(unused_variables)]
821 let result = self.device.set(u8::from(Rs232V2BrickletFunction::Reset), &payload).await?;
822 Ok(())
823 }
824
825 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
831 let mut payload = [0; 4];
832 uid.write_to_slice(&mut payload[0..4]);
833
834 #[allow(unused_variables)]
835 let result = self.device.set(u8::from(Rs232V2BrickletFunction::WriteUid), &payload).await?;
836 Ok(())
837 }
838
839 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
842 let payload = [0; 0];
843
844 #[allow(unused_variables)]
845 let result = self.device.get(u8::from(Rs232V2BrickletFunction::ReadUid), &payload).await?;
846 Ok(u32::from_le_byte_slice(result.body()))
847 }
848
849 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
860 let payload = [0; 0];
861
862 #[allow(unused_variables)]
863 let result = self.device.get(u8::from(Rs232V2BrickletFunction::GetIdentity), &payload).await?;
864 Ok(Identity::from_le_byte_slice(result.body()))
865 }
866}