1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
/* ***********************************************************
 * This file was automatically generated on 2019-11-25.      *
 *                                                           *
 * Rust Bindings Version 2.0.13                              *
 *                                                           *
 * If you have a bugfix for this file and want to commit it, *
 * please fix the bug in the generator. You can find a link  *
 * to the generators git repository on tinkerforge.com       *
 *************************************************************/

//! Communicates with RS485/Modbus devices with full- or half-duplex.
//!
//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/RS485_Bricklet_Rust.html).
use crate::{
    byte_converter::*,
    converting_callback_receiver::ConvertingCallbackReceiver,
    converting_high_level_callback_receiver::ConvertingHighLevelCallbackReceiver,
    converting_receiver::{BrickletRecvTimeoutError, ConvertingReceiver},
    device::*,
    ip_connection::GetRequestSender,
    low_level_traits::*,
};
pub enum Rs485BrickletFunction {
    WriteLowLevel,
    ReadLowLevel,
    EnableReadCallback,
    DisableReadCallback,
    IsReadCallbackEnabled,
    SetRs485Configuration,
    GetRs485Configuration,
    SetModbusConfiguration,
    GetModbusConfiguration,
    SetMode,
    GetMode,
    SetCommunicationLedConfig,
    GetCommunicationLedConfig,
    SetErrorLedConfig,
    GetErrorLedConfig,
    SetBufferConfig,
    GetBufferConfig,
    GetBufferStatus,
    EnableErrorCountCallback,
    DisableErrorCountCallback,
    IsErrorCountCallbackEnabled,
    GetErrorCount,
    GetModbusCommonErrorCount,
    ModbusSlaveReportException,
    ModbusSlaveAnswerReadCoilsRequestLowLevel,
    ModbusMasterReadCoils,
    ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel,
    ModbusMasterReadHoldingRegisters,
    ModbusSlaveAnswerWriteSingleCoilRequest,
    ModbusMasterWriteSingleCoil,
    ModbusSlaveAnswerWriteSingleRegisterRequest,
    ModbusMasterWriteSingleRegister,
    ModbusSlaveAnswerWriteMultipleCoilsRequest,
    ModbusMasterWriteMultipleCoilsLowLevel,
    ModbusSlaveAnswerWriteMultipleRegistersRequest,
    ModbusMasterWriteMultipleRegistersLowLevel,
    ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel,
    ModbusMasterReadDiscreteInputs,
    ModbusSlaveAnswerReadInputRegistersRequestLowLevel,
    ModbusMasterReadInputRegisters,
    GetSpitfpErrorCount,
    SetBootloaderMode,
    GetBootloaderMode,
    SetWriteFirmwarePointer,
    WriteFirmware,
    SetStatusLedConfig,
    GetStatusLedConfig,
    GetChipTemperature,
    Reset,
    WriteUid,
    ReadUid,
    GetIdentity,
    CallbackReadLowLevel,
    CallbackErrorCount,
    CallbackModbusSlaveReadCoilsRequest,
    CallbackModbusMasterReadCoilsResponseLowLevel,
    CallbackModbusSlaveReadHoldingRegistersRequest,
    CallbackModbusMasterReadHoldingRegistersResponseLowLevel,
    CallbackModbusSlaveWriteSingleCoilRequest,
    CallbackModbusMasterWriteSingleCoilResponse,
    CallbackModbusSlaveWriteSingleRegisterRequest,
    CallbackModbusMasterWriteSingleRegisterResponse,
    CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel,
    CallbackModbusMasterWriteMultipleCoilsResponse,
    CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel,
    CallbackModbusMasterWriteMultipleRegistersResponse,
    CallbackModbusSlaveReadDiscreteInputsRequest,
    CallbackModbusMasterReadDiscreteInputsResponseLowLevel,
    CallbackModbusSlaveReadInputRegistersRequest,
    CallbackModbusMasterReadInputRegistersResponseLowLevel,
}
impl From<Rs485BrickletFunction> for u8 {
    fn from(fun: Rs485BrickletFunction) -> Self {
        match fun {
            Rs485BrickletFunction::WriteLowLevel => 1,
            Rs485BrickletFunction::ReadLowLevel => 2,
            Rs485BrickletFunction::EnableReadCallback => 3,
            Rs485BrickletFunction::DisableReadCallback => 4,
            Rs485BrickletFunction::IsReadCallbackEnabled => 5,
            Rs485BrickletFunction::SetRs485Configuration => 6,
            Rs485BrickletFunction::GetRs485Configuration => 7,
            Rs485BrickletFunction::SetModbusConfiguration => 8,
            Rs485BrickletFunction::GetModbusConfiguration => 9,
            Rs485BrickletFunction::SetMode => 10,
            Rs485BrickletFunction::GetMode => 11,
            Rs485BrickletFunction::SetCommunicationLedConfig => 12,
            Rs485BrickletFunction::GetCommunicationLedConfig => 13,
            Rs485BrickletFunction::SetErrorLedConfig => 14,
            Rs485BrickletFunction::GetErrorLedConfig => 15,
            Rs485BrickletFunction::SetBufferConfig => 16,
            Rs485BrickletFunction::GetBufferConfig => 17,
            Rs485BrickletFunction::GetBufferStatus => 18,
            Rs485BrickletFunction::EnableErrorCountCallback => 19,
            Rs485BrickletFunction::DisableErrorCountCallback => 20,
            Rs485BrickletFunction::IsErrorCountCallbackEnabled => 21,
            Rs485BrickletFunction::GetErrorCount => 22,
            Rs485BrickletFunction::GetModbusCommonErrorCount => 23,
            Rs485BrickletFunction::ModbusSlaveReportException => 24,
            Rs485BrickletFunction::ModbusSlaveAnswerReadCoilsRequestLowLevel => 25,
            Rs485BrickletFunction::ModbusMasterReadCoils => 26,
            Rs485BrickletFunction::ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel => 27,
            Rs485BrickletFunction::ModbusMasterReadHoldingRegisters => 28,
            Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleCoilRequest => 29,
            Rs485BrickletFunction::ModbusMasterWriteSingleCoil => 30,
            Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleRegisterRequest => 31,
            Rs485BrickletFunction::ModbusMasterWriteSingleRegister => 32,
            Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleCoilsRequest => 33,
            Rs485BrickletFunction::ModbusMasterWriteMultipleCoilsLowLevel => 34,
            Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleRegistersRequest => 35,
            Rs485BrickletFunction::ModbusMasterWriteMultipleRegistersLowLevel => 36,
            Rs485BrickletFunction::ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel => 37,
            Rs485BrickletFunction::ModbusMasterReadDiscreteInputs => 38,
            Rs485BrickletFunction::ModbusSlaveAnswerReadInputRegistersRequestLowLevel => 39,
            Rs485BrickletFunction::ModbusMasterReadInputRegisters => 40,
            Rs485BrickletFunction::GetSpitfpErrorCount => 234,
            Rs485BrickletFunction::SetBootloaderMode => 235,
            Rs485BrickletFunction::GetBootloaderMode => 236,
            Rs485BrickletFunction::SetWriteFirmwarePointer => 237,
            Rs485BrickletFunction::WriteFirmware => 238,
            Rs485BrickletFunction::SetStatusLedConfig => 239,
            Rs485BrickletFunction::GetStatusLedConfig => 240,
            Rs485BrickletFunction::GetChipTemperature => 242,
            Rs485BrickletFunction::Reset => 243,
            Rs485BrickletFunction::WriteUid => 248,
            Rs485BrickletFunction::ReadUid => 249,
            Rs485BrickletFunction::GetIdentity => 255,
            Rs485BrickletFunction::CallbackReadLowLevel => 41,
            Rs485BrickletFunction::CallbackErrorCount => 42,
            Rs485BrickletFunction::CallbackModbusSlaveReadCoilsRequest => 43,
            Rs485BrickletFunction::CallbackModbusMasterReadCoilsResponseLowLevel => 44,
            Rs485BrickletFunction::CallbackModbusSlaveReadHoldingRegistersRequest => 45,
            Rs485BrickletFunction::CallbackModbusMasterReadHoldingRegistersResponseLowLevel => 46,
            Rs485BrickletFunction::CallbackModbusSlaveWriteSingleCoilRequest => 47,
            Rs485BrickletFunction::CallbackModbusMasterWriteSingleCoilResponse => 48,
            Rs485BrickletFunction::CallbackModbusSlaveWriteSingleRegisterRequest => 49,
            Rs485BrickletFunction::CallbackModbusMasterWriteSingleRegisterResponse => 50,
            Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel => 51,
            Rs485BrickletFunction::CallbackModbusMasterWriteMultipleCoilsResponse => 52,
            Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel => 53,
            Rs485BrickletFunction::CallbackModbusMasterWriteMultipleRegistersResponse => 54,
            Rs485BrickletFunction::CallbackModbusSlaveReadDiscreteInputsRequest => 55,
            Rs485BrickletFunction::CallbackModbusMasterReadDiscreteInputsResponseLowLevel => 56,
            Rs485BrickletFunction::CallbackModbusSlaveReadInputRegistersRequest => 57,
            Rs485BrickletFunction::CallbackModbusMasterReadInputRegistersResponseLowLevel => 58,
        }
    }
}
pub const RS485_BRICKLET_PARITY_NONE: u8 = 0;
pub const RS485_BRICKLET_PARITY_ODD: u8 = 1;
pub const RS485_BRICKLET_PARITY_EVEN: u8 = 2;
pub const RS485_BRICKLET_STOPBITS_1: u8 = 1;
pub const RS485_BRICKLET_STOPBITS_2: u8 = 2;
pub const RS485_BRICKLET_WORDLENGTH_5: u8 = 5;
pub const RS485_BRICKLET_WORDLENGTH_6: u8 = 6;
pub const RS485_BRICKLET_WORDLENGTH_7: u8 = 7;
pub const RS485_BRICKLET_WORDLENGTH_8: u8 = 8;
pub const RS485_BRICKLET_DUPLEX_HALF: u8 = 0;
pub const RS485_BRICKLET_DUPLEX_FULL: u8 = 1;
pub const RS485_BRICKLET_MODE_RS485: u8 = 0;
pub const RS485_BRICKLET_MODE_MODBUS_MASTER_RTU: u8 = 1;
pub const RS485_BRICKLET_MODE_MODBUS_SLAVE_RTU: u8 = 2;
pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_OFF: u8 = 0;
pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_ON: u8 = 1;
pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
pub const RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION: u8 = 3;
pub const RS485_BRICKLET_ERROR_LED_CONFIG_OFF: u8 = 0;
pub const RS485_BRICKLET_ERROR_LED_CONFIG_ON: u8 = 1;
pub const RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
pub const RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR: u8 = 3;
pub const RS485_BRICKLET_EXCEPTION_CODE_TIMEOUT: i8 = -1;
pub const RS485_BRICKLET_EXCEPTION_CODE_SUCCESS: i8 = 0;
pub const RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_FUNCTION: i8 = 1;
pub const RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS: i8 = 2;
pub const RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_VALUE: i8 = 3;
pub const RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_FAILURE: i8 = 4;
pub const RS485_BRICKLET_EXCEPTION_CODE_ACKNOWLEDGE: i8 = 5;
pub const RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_BUSY: i8 = 6;
pub const RS485_BRICKLET_EXCEPTION_CODE_MEMORY_PARITY_ERROR: i8 = 8;
pub const RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE: i8 = 10;
pub const RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: i8 = 11;
pub const RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
pub const RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
pub const RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
pub const RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
pub const RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
pub const RS485_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
pub const RS485_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
pub const RS485_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
pub const RS485_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
pub const RS485_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
pub const RS485_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
pub const RS485_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
pub const RS485_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
pub const RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
pub const RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct WriteLowLevel {
    pub message_chunk_written: u8,
}
impl FromByteSlice for WriteLowLevel {
    fn bytes_expected() -> usize { 1 }
    fn from_le_byte_slice(bytes: &[u8]) -> WriteLowLevel { WriteLowLevel { message_chunk_written: <u8>::from_le_byte_slice(&bytes[0..1]) } }
}
impl LowLevelWrite<WriteResult> for WriteLowLevel {
    fn ll_message_written(&self) -> usize { self.message_chunk_written as usize }

    fn get_result(&self) -> WriteResult { WriteResult {} }
}

#[derive(Clone, Copy)]
pub struct ReadLowLevel {
    pub message_length: u16,
    pub message_chunk_offset: u16,
    pub message_chunk_data: [char; 60],
}
impl FromByteSlice for ReadLowLevel {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ReadLowLevel {
        ReadLowLevel {
            message_length: <u16>::from_le_byte_slice(&bytes[0..2]),
            message_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
            message_chunk_data: <[char; 60]>::from_le_byte_slice(&bytes[4..64]),
        }
    }
}
impl LowLevelRead<char, ReadResult> for ReadLowLevel {
    fn ll_message_length(&self) -> usize { self.message_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.message_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[char] { &self.message_chunk_data }

    fn get_result(&self) -> ReadResult { ReadResult {} }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Rs485Configuration {
    pub baudrate: u32,
    pub parity: u8,
    pub stopbits: u8,
    pub wordlength: u8,
    pub duplex: u8,
}
impl FromByteSlice for Rs485Configuration {
    fn bytes_expected() -> usize { 8 }
    fn from_le_byte_slice(bytes: &[u8]) -> Rs485Configuration {
        Rs485Configuration {
            baudrate: <u32>::from_le_byte_slice(&bytes[0..4]),
            parity: <u8>::from_le_byte_slice(&bytes[4..5]),
            stopbits: <u8>::from_le_byte_slice(&bytes[5..6]),
            wordlength: <u8>::from_le_byte_slice(&bytes[6..7]),
            duplex: <u8>::from_le_byte_slice(&bytes[7..8]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusConfiguration {
    pub slave_address: u8,
    pub master_request_timeout: u32,
}
impl FromByteSlice for ModbusConfiguration {
    fn bytes_expected() -> usize { 5 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusConfiguration {
        ModbusConfiguration {
            slave_address: <u8>::from_le_byte_slice(&bytes[0..1]),
            master_request_timeout: <u32>::from_le_byte_slice(&bytes[1..5]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct BufferConfig {
    pub send_buffer_size: u16,
    pub receive_buffer_size: u16,
}
impl FromByteSlice for BufferConfig {
    fn bytes_expected() -> usize { 4 }
    fn from_le_byte_slice(bytes: &[u8]) -> BufferConfig {
        BufferConfig {
            send_buffer_size: <u16>::from_le_byte_slice(&bytes[0..2]),
            receive_buffer_size: <u16>::from_le_byte_slice(&bytes[2..4]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct BufferStatus {
    pub send_buffer_used: u16,
    pub receive_buffer_used: u16,
}
impl FromByteSlice for BufferStatus {
    fn bytes_expected() -> usize { 4 }
    fn from_le_byte_slice(bytes: &[u8]) -> BufferStatus {
        BufferStatus {
            send_buffer_used: <u16>::from_le_byte_slice(&bytes[0..2]),
            receive_buffer_used: <u16>::from_le_byte_slice(&bytes[2..4]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ErrorCount {
    pub overrun_error_count: u32,
    pub parity_error_count: u32,
}
impl FromByteSlice for ErrorCount {
    fn bytes_expected() -> usize { 8 }
    fn from_le_byte_slice(bytes: &[u8]) -> ErrorCount {
        ErrorCount {
            overrun_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
            parity_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusCommonErrorCount {
    pub timeout_error_count: u32,
    pub checksum_error_count: u32,
    pub frame_too_big_error_count: u32,
    pub illegal_function_error_count: u32,
    pub illegal_data_address_error_count: u32,
    pub illegal_data_value_error_count: u32,
    pub slave_device_failure_error_count: u32,
}
impl FromByteSlice for ModbusCommonErrorCount {
    fn bytes_expected() -> usize { 28 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusCommonErrorCount {
        ModbusCommonErrorCount {
            timeout_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
            checksum_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
            frame_too_big_error_count: <u32>::from_le_byte_slice(&bytes[8..12]),
            illegal_function_error_count: <u32>::from_le_byte_slice(&bytes[12..16]),
            illegal_data_address_error_count: <u32>::from_le_byte_slice(&bytes[16..20]),
            illegal_data_value_error_count: <u32>::from_le_byte_slice(&bytes[20..24]),
            slave_device_failure_error_count: <u32>::from_le_byte_slice(&bytes[24..28]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadCoilsRequestLowLevel {}
impl FromByteSlice for ModbusSlaveAnswerReadCoilsRequestLowLevel {
    fn bytes_expected() -> usize { 0 }
    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadCoilsRequestLowLevel { ModbusSlaveAnswerReadCoilsRequestLowLevel {} }
}
impl LowLevelWrite<ModbusSlaveAnswerReadCoilsRequestResult> for ModbusSlaveAnswerReadCoilsRequestLowLevel {
    fn ll_message_written(&self) -> usize { 472 }

    fn get_result(&self) -> ModbusSlaveAnswerReadCoilsRequestResult { ModbusSlaveAnswerReadCoilsRequestResult {} }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {}
impl FromByteSlice for ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {
    fn bytes_expected() -> usize { 0 }
    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {
        ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {}
    }
}
impl LowLevelWrite<ModbusSlaveAnswerReadHoldingRegistersRequestResult> for ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel {
    fn ll_message_written(&self) -> usize { 29 }

    fn get_result(&self) -> ModbusSlaveAnswerReadHoldingRegistersRequestResult { ModbusSlaveAnswerReadHoldingRegistersRequestResult {} }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteMultipleCoilsLowLevel {
    pub request_id: u8,
}
impl FromByteSlice for ModbusMasterWriteMultipleCoilsLowLevel {
    fn bytes_expected() -> usize { 1 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleCoilsLowLevel {
        ModbusMasterWriteMultipleCoilsLowLevel { request_id: <u8>::from_le_byte_slice(&bytes[0..1]) }
    }
}
impl LowLevelWrite<ModbusMasterWriteMultipleCoilsResult> for ModbusMasterWriteMultipleCoilsLowLevel {
    fn ll_message_written(&self) -> usize { 440 }

    fn get_result(&self) -> ModbusMasterWriteMultipleCoilsResult { ModbusMasterWriteMultipleCoilsResult { request_id: self.request_id } }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteMultipleRegistersLowLevel {
    pub request_id: u8,
}
impl FromByteSlice for ModbusMasterWriteMultipleRegistersLowLevel {
    fn bytes_expected() -> usize { 1 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleRegistersLowLevel {
        ModbusMasterWriteMultipleRegistersLowLevel { request_id: <u8>::from_le_byte_slice(&bytes[0..1]) }
    }
}
impl LowLevelWrite<ModbusMasterWriteMultipleRegistersResult> for ModbusMasterWriteMultipleRegistersLowLevel {
    fn ll_message_written(&self) -> usize { 27 }

    fn get_result(&self) -> ModbusMasterWriteMultipleRegistersResult {
        ModbusMasterWriteMultipleRegistersResult { request_id: self.request_id }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {}
impl FromByteSlice for ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {
    fn bytes_expected() -> usize { 0 }
    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {
        ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {}
    }
}
impl LowLevelWrite<ModbusSlaveAnswerReadDiscreteInputsRequestResult> for ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel {
    fn ll_message_written(&self) -> usize { 472 }

    fn get_result(&self) -> ModbusSlaveAnswerReadDiscreteInputsRequestResult { ModbusSlaveAnswerReadDiscreteInputsRequestResult {} }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadInputRegistersRequestLowLevel {}
impl FromByteSlice for ModbusSlaveAnswerReadInputRegistersRequestLowLevel {
    fn bytes_expected() -> usize { 0 }
    fn from_le_byte_slice(_bytes: &[u8]) -> ModbusSlaveAnswerReadInputRegistersRequestLowLevel {
        ModbusSlaveAnswerReadInputRegistersRequestLowLevel {}
    }
}
impl LowLevelWrite<ModbusSlaveAnswerReadInputRegistersRequestResult> for ModbusSlaveAnswerReadInputRegistersRequestLowLevel {
    fn ll_message_written(&self) -> usize { 29 }

    fn get_result(&self) -> ModbusSlaveAnswerReadInputRegistersRequestResult { ModbusSlaveAnswerReadInputRegistersRequestResult {} }
}

#[derive(Clone, Copy)]
pub struct ReadLowLevelEvent {
    pub message_length: u16,
    pub message_chunk_offset: u16,
    pub message_chunk_data: [char; 60],
}
impl FromByteSlice for ReadLowLevelEvent {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ReadLowLevelEvent {
        ReadLowLevelEvent {
            message_length: <u16>::from_le_byte_slice(&bytes[0..2]),
            message_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
            message_chunk_data: <[char; 60]>::from_le_byte_slice(&bytes[4..64]),
        }
    }
}
impl LowLevelRead<char, ReadResult> for ReadLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.message_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.message_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[char] { &self.message_chunk_data }

    fn get_result(&self) -> ReadResult { ReadResult {} }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ErrorCountEvent {
    pub overrun_error_count: u32,
    pub parity_error_count: u32,
}
impl FromByteSlice for ErrorCountEvent {
    fn bytes_expected() -> usize { 8 }
    fn from_le_byte_slice(bytes: &[u8]) -> ErrorCountEvent {
        ErrorCountEvent {
            overrun_error_count: <u32>::from_le_byte_slice(&bytes[0..4]),
            parity_error_count: <u32>::from_le_byte_slice(&bytes[4..8]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveReadCoilsRequestEvent {
    pub request_id: u8,
    pub starting_address: u32,
    pub count: u16,
}
impl FromByteSlice for ModbusSlaveReadCoilsRequestEvent {
    fn bytes_expected() -> usize { 7 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadCoilsRequestEvent {
        ModbusSlaveReadCoilsRequestEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            count: <u16>::from_le_byte_slice(&bytes[5..7]),
        }
    }
}

#[derive(Clone, Copy)]
pub struct ModbusMasterReadCoilsResponseLowLevelEvent {
    pub request_id: u8,
    pub exception_code: i8,
    pub coils_length: u16,
    pub coils_chunk_offset: u16,
    pub coils_chunk_data: [bool; 464],
}
impl FromByteSlice for ModbusMasterReadCoilsResponseLowLevelEvent {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadCoilsResponseLowLevelEvent {
        ModbusMasterReadCoilsResponseLowLevelEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
            coils_length: <u16>::from_le_byte_slice(&bytes[2..4]),
            coils_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
            coils_chunk_data: <[bool; 464]>::from_le_byte_slice(&bytes[6..64]),
        }
    }
}
impl LowLevelRead<bool, ModbusMasterReadCoilsResponseResult> for ModbusMasterReadCoilsResponseLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.coils_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.coils_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[bool] { &self.coils_chunk_data }

    fn get_result(&self) -> ModbusMasterReadCoilsResponseResult {
        ModbusMasterReadCoilsResponseResult { request_id: self.request_id, exception_code: self.exception_code }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveReadHoldingRegistersRequestEvent {
    pub request_id: u8,
    pub starting_address: u32,
    pub count: u16,
}
impl FromByteSlice for ModbusSlaveReadHoldingRegistersRequestEvent {
    fn bytes_expected() -> usize { 7 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadHoldingRegistersRequestEvent {
        ModbusSlaveReadHoldingRegistersRequestEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            count: <u16>::from_le_byte_slice(&bytes[5..7]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
    pub request_id: u8,
    pub exception_code: i8,
    pub holding_registers_length: u16,
    pub holding_registers_chunk_offset: u16,
    pub holding_registers_chunk_data: [u16; 29],
}
impl FromByteSlice for ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
        ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
            holding_registers_length: <u16>::from_le_byte_slice(&bytes[2..4]),
            holding_registers_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
            holding_registers_chunk_data: <[u16; 29]>::from_le_byte_slice(&bytes[6..64]),
        }
    }
}
impl LowLevelRead<u16, ModbusMasterReadHoldingRegistersResponseResult> for ModbusMasterReadHoldingRegistersResponseLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.holding_registers_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.holding_registers_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[u16] { &self.holding_registers_chunk_data }

    fn get_result(&self) -> ModbusMasterReadHoldingRegistersResponseResult {
        ModbusMasterReadHoldingRegistersResponseResult { request_id: self.request_id, exception_code: self.exception_code }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveWriteSingleCoilRequestEvent {
    pub request_id: u8,
    pub coil_address: u32,
    pub coil_value: bool,
}
impl FromByteSlice for ModbusSlaveWriteSingleCoilRequestEvent {
    fn bytes_expected() -> usize { 6 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteSingleCoilRequestEvent {
        ModbusSlaveWriteSingleCoilRequestEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            coil_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            coil_value: <bool>::from_le_byte_slice(&bytes[5..6]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteSingleCoilResponseEvent {
    pub request_id: u8,
    pub exception_code: i8,
}
impl FromByteSlice for ModbusMasterWriteSingleCoilResponseEvent {
    fn bytes_expected() -> usize { 2 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteSingleCoilResponseEvent {
        ModbusMasterWriteSingleCoilResponseEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveWriteSingleRegisterRequestEvent {
    pub request_id: u8,
    pub register_address: u32,
    pub register_value: u16,
}
impl FromByteSlice for ModbusSlaveWriteSingleRegisterRequestEvent {
    fn bytes_expected() -> usize { 7 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteSingleRegisterRequestEvent {
        ModbusSlaveWriteSingleRegisterRequestEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            register_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            register_value: <u16>::from_le_byte_slice(&bytes[5..7]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteSingleRegisterResponseEvent {
    pub request_id: u8,
    pub exception_code: i8,
}
impl FromByteSlice for ModbusMasterWriteSingleRegisterResponseEvent {
    fn bytes_expected() -> usize { 2 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteSingleRegisterResponseEvent {
        ModbusMasterWriteSingleRegisterResponseEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
        }
    }
}

#[derive(Clone, Copy)]
pub struct ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
    pub request_id: u8,
    pub starting_address: u32,
    pub coils_length: u16,
    pub coils_chunk_offset: u16,
    pub coils_chunk_data: [bool; 440],
}
impl FromByteSlice for ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
        ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            coils_length: <u16>::from_le_byte_slice(&bytes[5..7]),
            coils_chunk_offset: <u16>::from_le_byte_slice(&bytes[7..9]),
            coils_chunk_data: <[bool; 440]>::from_le_byte_slice(&bytes[9..64]),
        }
    }
}
impl LowLevelRead<bool, ModbusSlaveWriteMultipleCoilsRequestResult> for ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.coils_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.coils_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[bool] { &self.coils_chunk_data }

    fn get_result(&self) -> ModbusSlaveWriteMultipleCoilsRequestResult {
        ModbusSlaveWriteMultipleCoilsRequestResult { request_id: self.request_id, starting_address: self.starting_address }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteMultipleCoilsResponseEvent {
    pub request_id: u8,
    pub exception_code: i8,
}
impl FromByteSlice for ModbusMasterWriteMultipleCoilsResponseEvent {
    fn bytes_expected() -> usize { 2 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleCoilsResponseEvent {
        ModbusMasterWriteMultipleCoilsResponseEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
    pub request_id: u8,
    pub starting_address: u32,
    pub registers_length: u16,
    pub registers_chunk_offset: u16,
    pub registers_chunk_data: [u16; 27],
}
impl FromByteSlice for ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
    fn bytes_expected() -> usize { 63 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
        ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            registers_length: <u16>::from_le_byte_slice(&bytes[5..7]),
            registers_chunk_offset: <u16>::from_le_byte_slice(&bytes[7..9]),
            registers_chunk_data: <[u16; 27]>::from_le_byte_slice(&bytes[9..63]),
        }
    }
}
impl LowLevelRead<u16, ModbusSlaveWriteMultipleRegistersRequestResult> for ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.registers_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.registers_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[u16] { &self.registers_chunk_data }

    fn get_result(&self) -> ModbusSlaveWriteMultipleRegistersRequestResult {
        ModbusSlaveWriteMultipleRegistersRequestResult { request_id: self.request_id, starting_address: self.starting_address }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteMultipleRegistersResponseEvent {
    pub request_id: u8,
    pub exception_code: i8,
}
impl FromByteSlice for ModbusMasterWriteMultipleRegistersResponseEvent {
    fn bytes_expected() -> usize { 2 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterWriteMultipleRegistersResponseEvent {
        ModbusMasterWriteMultipleRegistersResponseEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveReadDiscreteInputsRequestEvent {
    pub request_id: u8,
    pub starting_address: u32,
    pub count: u16,
}
impl FromByteSlice for ModbusSlaveReadDiscreteInputsRequestEvent {
    fn bytes_expected() -> usize { 7 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadDiscreteInputsRequestEvent {
        ModbusSlaveReadDiscreteInputsRequestEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            count: <u16>::from_le_byte_slice(&bytes[5..7]),
        }
    }
}

#[derive(Clone, Copy)]
pub struct ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
    pub request_id: u8,
    pub exception_code: i8,
    pub discrete_inputs_length: u16,
    pub discrete_inputs_chunk_offset: u16,
    pub discrete_inputs_chunk_data: [bool; 464],
}
impl FromByteSlice for ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
        ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
            discrete_inputs_length: <u16>::from_le_byte_slice(&bytes[2..4]),
            discrete_inputs_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
            discrete_inputs_chunk_data: <[bool; 464]>::from_le_byte_slice(&bytes[6..64]),
        }
    }
}
impl LowLevelRead<bool, ModbusMasterReadDiscreteInputsResponseResult> for ModbusMasterReadDiscreteInputsResponseLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.discrete_inputs_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.discrete_inputs_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[bool] { &self.discrete_inputs_chunk_data }

    fn get_result(&self) -> ModbusMasterReadDiscreteInputsResponseResult {
        ModbusMasterReadDiscreteInputsResponseResult { request_id: self.request_id, exception_code: self.exception_code }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveReadInputRegistersRequestEvent {
    pub request_id: u8,
    pub starting_address: u32,
    pub count: u16,
}
impl FromByteSlice for ModbusSlaveReadInputRegistersRequestEvent {
    fn bytes_expected() -> usize { 7 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusSlaveReadInputRegistersRequestEvent {
        ModbusSlaveReadInputRegistersRequestEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            starting_address: <u32>::from_le_byte_slice(&bytes[1..5]),
            count: <u16>::from_le_byte_slice(&bytes[5..7]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterReadInputRegistersResponseLowLevelEvent {
    pub request_id: u8,
    pub exception_code: i8,
    pub input_registers_length: u16,
    pub input_registers_chunk_offset: u16,
    pub input_registers_chunk_data: [u16; 29],
}
impl FromByteSlice for ModbusMasterReadInputRegistersResponseLowLevelEvent {
    fn bytes_expected() -> usize { 64 }
    fn from_le_byte_slice(bytes: &[u8]) -> ModbusMasterReadInputRegistersResponseLowLevelEvent {
        ModbusMasterReadInputRegistersResponseLowLevelEvent {
            request_id: <u8>::from_le_byte_slice(&bytes[0..1]),
            exception_code: <i8>::from_le_byte_slice(&bytes[1..2]),
            input_registers_length: <u16>::from_le_byte_slice(&bytes[2..4]),
            input_registers_chunk_offset: <u16>::from_le_byte_slice(&bytes[4..6]),
            input_registers_chunk_data: <[u16; 29]>::from_le_byte_slice(&bytes[6..64]),
        }
    }
}
impl LowLevelRead<u16, ModbusMasterReadInputRegistersResponseResult> for ModbusMasterReadInputRegistersResponseLowLevelEvent {
    fn ll_message_length(&self) -> usize { self.input_registers_length as usize }

    fn ll_message_chunk_offset(&self) -> usize { self.input_registers_chunk_offset as usize }

    fn ll_message_chunk_data(&self) -> &[u16] { &self.input_registers_chunk_data }

    fn get_result(&self) -> ModbusMasterReadInputRegistersResponseResult {
        ModbusMasterReadInputRegistersResponseResult { request_id: self.request_id, exception_code: self.exception_code }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpErrorCount {
    pub error_count_ack_checksum: u32,
    pub error_count_message_checksum: u32,
    pub error_count_frame: u32,
    pub error_count_overflow: u32,
}
impl FromByteSlice for SpitfpErrorCount {
    fn bytes_expected() -> usize { 16 }
    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
        SpitfpErrorCount {
            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
        }
    }
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Identity {
    pub uid: String,
    pub connected_uid: String,
    pub position: char,
    pub hardware_version: [u8; 3],
    pub firmware_version: [u8; 3],
    pub device_identifier: u16,
}
impl FromByteSlice for Identity {
    fn bytes_expected() -> usize { 25 }
    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
        Identity {
            uid: <String>::from_le_byte_slice(&bytes[0..8]),
            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
            position: <char>::from_le_byte_slice(&bytes[16..17]),
            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
        }
    }
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct WriteResult {}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ReadResult {}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadCoilsRequestResult {}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadHoldingRegistersRequestResult {}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteMultipleCoilsResult {
    pub request_id: u8,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterWriteMultipleRegistersResult {
    pub request_id: u8,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadDiscreteInputsRequestResult {}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveAnswerReadInputRegistersRequestResult {}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterReadCoilsResponseResult {
    pub request_id: u8,
    pub exception_code: i8,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterReadHoldingRegistersResponseResult {
    pub request_id: u8,
    pub exception_code: i8,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveWriteMultipleCoilsRequestResult {
    pub request_id: u8,
    pub starting_address: u32,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusSlaveWriteMultipleRegistersRequestResult {
    pub request_id: u8,
    pub starting_address: u32,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterReadDiscreteInputsResponseResult {
    pub request_id: u8,
    pub exception_code: i8,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ModbusMasterReadInputRegistersResponseResult {
    pub request_id: u8,
    pub exception_code: i8,
}

/// Communicates with RS485/Modbus devices with full- or half-duplex
#[derive(Clone)]
pub struct Rs485Bricklet {
    device: Device,
}
impl Rs485Bricklet {
    pub const DEVICE_IDENTIFIER: u16 = 277;
    pub const DEVICE_DISPLAY_NAME: &'static str = "RS485 Bricklet";
    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
    pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> Rs485Bricklet {
        let mut result = Rs485Bricklet { device: Device::new([2, 0, 0], uid, req_sender, 15) };
        result.device.response_expected[u8::from(Rs485BrickletFunction::WriteLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ReadLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::EnableReadCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::DisableReadCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::IsReadCallbackEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetRs485Configuration) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetRs485Configuration) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetModbusConfiguration) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetModbusConfiguration) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetMode) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetCommunicationLedConfig) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetCommunicationLedConfig) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetErrorLedConfig) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetErrorLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetBufferConfig) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetBufferConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetBufferStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::EnableErrorCountCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::DisableErrorCountCallback) as usize] = ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::IsErrorCountCallbackEnabled) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetModbusCommonErrorCount) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveReportException) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadCoilsRequestLowLevel) as usize] =
            ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadCoils) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel) as usize] =
            ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadHoldingRegisters) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleCoilRequest) as usize] =
            ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleCoil) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleRegisterRequest) as usize] =
            ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleRegister) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleCoilsRequest) as usize] =
            ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleCoilsLowLevel) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleRegistersRequest) as usize] =
            ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleRegistersLowLevel) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel) as usize] =
            ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadDiscreteInputs) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadInputRegistersRequestLowLevel) as usize] =
            ResponseExpectedFlag::True;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ModbusMasterReadInputRegisters) as usize] =
            ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
        result.device.response_expected[u8::from(Rs485BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result.device.response_expected[u8::from(Rs485BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
        result
    }

    /// Returns the response expected flag for the function specified by the function ID parameter.
    /// It is true if the function is expected to send a response, false otherwise.
    ///
    /// For getter functions this is enabled by default and cannot be disabled, because those
    /// functions will always send a response. For callback configuration functions it is enabled
    /// by default too, but can be disabled by [`set_response_expected`](crate::rs485_bricklet::Rs485Bricklet::set_response_expected).
    /// For setter functions it is disabled by default and can be enabled.
    ///
    /// Enabling the response expected flag for a setter function allows to detect timeouts
    /// and other error conditions calls of this setter as well. The device will then send a response
    /// for this purpose. If this flag is disabled for a setter function then no response is send
    /// and errors are silently ignored, because they cannot be detected.
    ///
    /// See [`set_response_expected`](crate::rs485_bricklet::Rs485Bricklet::set_response_expected) for the list of function ID constants available for this function.
    pub fn get_response_expected(&mut self, fun: Rs485BrickletFunction) -> Result<bool, GetResponseExpectedError> {
        self.device.get_response_expected(u8::from(fun))
    }

    /// Changes the response expected flag of the function specified by the function ID parameter.
    /// This flag can only be changed for setter (default value: false) and callback configuration
    /// functions (default value: true). For getter functions it is always enabled.
    ///
    /// Enabling the response expected flag for a setter function allows to detect timeouts and
    /// other error conditions calls of this setter as well. The device will then send a response
    /// for this purpose. If this flag is disabled for a setter function then no response is send
    /// and errors are silently ignored, because they cannot be detected.
    pub fn set_response_expected(&mut self, fun: Rs485BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
        self.device.set_response_expected(u8::from(fun), response_expected)
    }

    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
    pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }

    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
    pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }

    /// See [`get_read_callback_receiver`](crate::rs485::RS485::get_read_callback_receiver)
    pub fn get_read_low_level_callback_receiver(&self) -> ConvertingCallbackReceiver<ReadLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackReadLowLevel))
    }

    /// This receiver is called if new data is available.
    ///
    /// To enable this receiver, use [`enable_read_callback`].
    ///
    /// [`enable_read_callback`]: #method.enable_read_callback
    pub fn get_read_callback_receiver(&self) -> ConvertingHighLevelCallbackReceiver<char, ReadResult, ReadLowLevelEvent> {
        ConvertingHighLevelCallbackReceiver::new(self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackReadLowLevel)))
    }

    /// This receiver is called if a new error occurs. It returns
    /// the current overrun and parity error count.
    pub fn get_error_count_callback_receiver(&self) -> ConvertingCallbackReceiver<ErrorCountEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackErrorCount))
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to read coils. The parameters are
    /// request ID of the request, the number of the first coil to be read and the number of coils to
    /// be read as received by the request. The number of the first coil is called starting address for backwards compatibility reasons.
    /// It is not an address, but instead a coil number in the range of 1 to 65536.
    ///
    /// To send a response of this request use [`modbus_slave_answer_read_coils_request`].
    ///
    /// [`modbus_slave_answer_read_coils_request`]: #method.modbus_slave_answer_read_coils_request
    pub fn get_modbus_slave_read_coils_request_callback_receiver(&self) -> ConvertingCallbackReceiver<ModbusSlaveReadCoilsRequestEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadCoilsRequest))
    }

    /// See [`get_modbus_master_read_coils_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_coils_response_callback_receiver)
    pub fn get_modbus_master_read_coils_response_low_level_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterReadCoilsResponseLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadCoilsResponseLowLevel))
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to read coils.
    ///
    /// The parameters are request ID
    /// of the request, exception code of the response and the data as received by the
    /// response.
    ///
    /// Any non-zero exception code indicates a problem. If the exception code
    /// is greater than 0 then the number represents a Modbus exception code. If it is
    /// less than 0 then it represents other errors. For example, -1 indicates that
    /// the request timed out or that the master did not receive any valid response of the
    /// request within the master request timeout period as set by
    /// [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_read_coils_response_callback_receiver(
        &self,
    ) -> ConvertingHighLevelCallbackReceiver<bool, ModbusMasterReadCoilsResponseResult, ModbusMasterReadCoilsResponseLowLevelEvent> {
        ConvertingHighLevelCallbackReceiver::new(
            self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadCoilsResponseLowLevel)),
        )
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to read holding registers. The parameters
    /// are request ID of the request, the number of the first holding register to be read and the number of holding
    /// registers to be read as received by the request. The number of the first holding register is called starting address for backwards compatibility reasons.
    /// 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.
    ///
    /// To send a response of this request use [`modbus_slave_answer_read_holding_registers_request`].
    ///
    /// [`modbus_slave_answer_read_holding_registers_request`]: #method.modbus_slave_answer_read_holding_registers_request
    pub fn get_modbus_slave_read_holding_registers_request_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveReadHoldingRegistersRequestEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadHoldingRegistersRequest))
    }

    /// See [`get_modbus_master_read_holding_registers_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_holding_registers_response_callback_receiver)
    pub fn get_modbus_master_read_holding_registers_response_low_level_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterReadHoldingRegistersResponseLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadHoldingRegistersResponseLowLevel))
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to read holding registers.
    ///
    /// The parameters are
    /// request ID of the request, exception code of the response and the data as received
    /// by the response.
    ///
    /// Any non-zero exception code indicates a problem. If the exception
    /// code is greater than 0 then the number represents a Modbus exception code. If
    /// it is less than 0 then it represents other errors. For example, -1 indicates that
    /// the request timed out or that the master did not receive any valid response of the
    /// request within the master request timeout period as set by
    /// [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_read_holding_registers_response_callback_receiver(
        &self,
    ) -> ConvertingHighLevelCallbackReceiver<
        u16,
        ModbusMasterReadHoldingRegistersResponseResult,
        ModbusMasterReadHoldingRegistersResponseLowLevelEvent,
    > {
        ConvertingHighLevelCallbackReceiver::new(
            self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadHoldingRegistersResponseLowLevel)),
        )
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to write a single coil. The parameters
    /// are request ID of the request, the number of the coil and the value of coil to be
    /// written as received by the request. The number of the coil is called coil address for backwards compatibility reasons.
    /// It is not an address, but instead a coil number in the range of 1 to 65536.
    ///
    /// To send a response of this request use [`modbus_slave_answer_write_single_coil_request`].
    ///
    /// [`modbus_slave_answer_write_single_coil_request`]: #method.modbus_slave_answer_write_single_coil_request
    pub fn get_modbus_slave_write_single_coil_request_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveWriteSingleCoilRequestEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteSingleCoilRequest))
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to write a single coil.
    ///
    /// The parameters are
    /// request ID of the request and exception code of the response.
    ///
    /// Any non-zero exception code indicates a problem.
    /// If the exception code is greater than 0 then the number represents a Modbus
    /// exception code. If it is less than 0 then it represents other errors. For
    /// example, -1 indicates that the request timed out or that the master did not receive
    /// any valid response of the request within the master request timeout period as set
    /// by [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_write_single_coil_response_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterWriteSingleCoilResponseEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteSingleCoilResponse))
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to write a single holding register. The parameters
    /// are request ID of the request, the number of the holding register and the register value to
    /// be written as received by the request. The number of the holding register is called starting address for backwards compatibility reasons.
    /// 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.
    ///
    /// To send a response of this request use [`modbus_slave_answer_write_single_register_request`].
    ///
    /// [`modbus_slave_answer_write_single_register_request`]: #method.modbus_slave_answer_write_single_register_request
    pub fn get_modbus_slave_write_single_register_request_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveWriteSingleRegisterRequestEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteSingleRegisterRequest))
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to write a single register.
    ///
    /// The parameters are
    /// request ID of the request and exception code of the response.
    ///
    /// Any non-zero exception code
    /// indicates a problem. If the exception code is greater than 0 then the number
    /// represents a Modbus exception code. If it is less than 0 then it represents
    /// other errors. For example, -1 indicates that the request timed out or that the
    /// master did not receive any valid response of the request within the master request
    /// timeout period as set by [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_write_single_register_response_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterWriteSingleRegisterResponseEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteSingleRegisterResponse))
    }

    /// See [`get_modbus_slave_write_multiple_coils_request_callback_receiver`](crate::rs485::RS485::get_modbus_slave_write_multiple_coils_request_callback_receiver)
    pub fn get_modbus_slave_write_multiple_coils_request_low_level_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel))
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to write multiple coils. The parameters
    /// are request ID of the request, the number of the first coil and the data to be written as
    /// received by the request. The number of the first coil is called starting address for backwards compatibility reasons.
    /// It is not an address, but instead a coil number in the range of 1 to 65536.
    ///
    /// To send a response of this request use [`modbus_slave_answer_write_multiple_coils_request`].
    ///
    /// [`modbus_slave_answer_write_multiple_coils_request`]: #method.modbus_slave_answer_write_multiple_coils_request
    pub fn get_modbus_slave_write_multiple_coils_request_callback_receiver(
        &self,
    ) -> ConvertingHighLevelCallbackReceiver<
        bool,
        ModbusSlaveWriteMultipleCoilsRequestResult,
        ModbusSlaveWriteMultipleCoilsRequestLowLevelEvent,
    > {
        ConvertingHighLevelCallbackReceiver::new(
            self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleCoilsRequestLowLevel)),
        )
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to read coils.
    ///
    /// The parameters are
    /// request ID of the request and exception code of the response.
    ///
    /// Any non-zero exception code
    /// indicates a problem. If the exception code is greater than 0 then the number
    /// represents a Modbus exception code. If it is less than 0 then it represents
    /// other errors. For example, -1 indicates that the request timedout or that the
    /// master did not receive any valid response of the request within the master request
    /// timeout period as set by [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_write_multiple_coils_response_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterWriteMultipleCoilsResponseEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteMultipleCoilsResponse))
    }

    /// See [`get_modbus_slave_write_multiple_registers_request_callback_receiver`](crate::rs485::RS485::get_modbus_slave_write_multiple_registers_request_callback_receiver)
    pub fn get_modbus_slave_write_multiple_registers_request_low_level_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel))
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to write multiple holding registers. The parameters
    /// are request ID of the request, the number of the first holding register and the data to be written as
    /// received by the request. The number of the first holding register is called starting address for backwards compatibility reasons.
    /// 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.
    ///
    /// To send a response of this request use [`modbus_slave_answer_write_multiple_registers_request`].
    ///
    /// [`modbus_slave_answer_write_multiple_registers_request`]: #method.modbus_slave_answer_write_multiple_registers_request
    pub fn get_modbus_slave_write_multiple_registers_request_callback_receiver(
        &self,
    ) -> ConvertingHighLevelCallbackReceiver<
        u16,
        ModbusSlaveWriteMultipleRegistersRequestResult,
        ModbusSlaveWriteMultipleRegistersRequestLowLevelEvent,
    > {
        ConvertingHighLevelCallbackReceiver::new(
            self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveWriteMultipleRegistersRequestLowLevel)),
        )
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to write multiple registers.
    ///
    /// The parameters
    /// are request ID of the request and exception code of the response.
    ///
    /// Any non-zero
    /// exception code indicates a problem. If the exception code is greater than 0 then
    /// the number represents a Modbus exception code. If it is less than 0 then it
    /// represents other errors. For example, -1 indicates that the request timedout or
    /// that the master did not receive any valid response of the request within the master
    /// request timeout period as set by [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_write_multiple_registers_response_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterWriteMultipleRegistersResponseEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterWriteMultipleRegistersResponse))
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to read discrete inputs. The parameters
    /// are request ID of the request, the number of the first discrete input and the number of discrete
    /// inputs to be read as received by the request. The number of the first discrete input is called starting address for backwards compatibility reasons.
    /// 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.
    ///
    /// To send a response of this request use [`modbus_slave_answer_read_discrete_inputs_request`].
    ///
    /// [`modbus_slave_answer_read_discrete_inputs_request`]: #method.modbus_slave_answer_read_discrete_inputs_request
    pub fn get_modbus_slave_read_discrete_inputs_request_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveReadDiscreteInputsRequestEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadDiscreteInputsRequest))
    }

    /// See [`get_modbus_master_read_discrete_inputs_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_discrete_inputs_response_callback_receiver)
    pub fn get_modbus_master_read_discrete_inputs_response_low_level_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterReadDiscreteInputsResponseLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadDiscreteInputsResponseLowLevel))
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to read discrete inputs.
    ///
    /// The parameters are
    /// request ID of the request, exception code of the response and the data as received
    /// by the response.
    ///
    /// Any non-zero exception code indicates a problem. If the exception
    /// code is greater than 0 then the number represents a Modbus exception code. If
    /// it is less than 0 then it represents other errors. For example, -1 indicates that
    /// the request timedout or that the master did not receive any valid response of the
    /// request within the master request timeout period as set by
    /// [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_read_discrete_inputs_response_callback_receiver(
        &self,
    ) -> ConvertingHighLevelCallbackReceiver<
        bool,
        ModbusMasterReadDiscreteInputsResponseResult,
        ModbusMasterReadDiscreteInputsResponseLowLevelEvent,
    > {
        ConvertingHighLevelCallbackReceiver::new(
            self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadDiscreteInputsResponseLowLevel)),
        )
    }

    /// This receiver is called only in Modbus slave mode when the slave receives a
    /// valid request from a Modbus master to read input registers. The parameters
    /// are request ID of the request, the number of the first input register and the number of input
    /// registers to be read as received by the request. The number of the first input register is called starting address for backwards compatibility reasons.
    /// 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.
    ///
    /// To send a response of this request use [`modbus_slave_answer_read_input_registers_request`].
    ///
    /// [`modbus_slave_answer_read_input_registers_request`]: #method.modbus_slave_answer_read_input_registers_request
    pub fn get_modbus_slave_read_input_registers_request_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusSlaveReadInputRegistersRequestEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusSlaveReadInputRegistersRequest))
    }

    /// See [`get_modbus_master_read_input_registers_response_callback_receiver`](crate::rs485::RS485::get_modbus_master_read_input_registers_response_callback_receiver)
    pub fn get_modbus_master_read_input_registers_response_low_level_callback_receiver(
        &self,
    ) -> ConvertingCallbackReceiver<ModbusMasterReadInputRegistersResponseLowLevelEvent> {
        self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadInputRegistersResponseLowLevel))
    }

    /// This receiver is called only in Modbus master mode when the master receives a
    /// valid response of a request to read input registers.
    ///
    /// The parameters are
    /// request ID of the request, exception code of the response and the data as received
    /// by the response.
    ///
    /// Any non-zero exception code indicates a problem. If the exception
    /// code is greater than 0 then the number represents a Modbus exception code. If
    /// it is less than 0 then it represents other errors. For example, -1 indicates that
    /// the request timedout or that the master did not receive any valid response of the
    /// request within the master request timeout period as set by
    /// [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_master_read_input_registers_response_callback_receiver(
        &self,
    ) -> ConvertingHighLevelCallbackReceiver<
        u16,
        ModbusMasterReadInputRegistersResponseResult,
        ModbusMasterReadInputRegistersResponseLowLevelEvent,
    > {
        ConvertingHighLevelCallbackReceiver::new(
            self.device.get_callback_receiver(u8::from(Rs485BrickletFunction::CallbackModbusMasterReadInputRegistersResponseLowLevel)),
        )
    }

    /// Writes characters to the RS485 interface. The characters can be binary data,
    /// ASCII or similar is not necessary.
    ///
    /// The return value is the number of characters that were written.
    ///
    /// See [`set_rs485_configuration`] for configuration possibilities
    /// regarding baudrate, parity and so on.
    ///
    /// [`set_rs485_configuration`]: #method.set_rs485_configuration
    pub fn write_low_level(
        &self,
        message_length: u16,
        message_chunk_offset: u16,
        message_chunk_data: [char; 60],
    ) -> ConvertingReceiver<WriteLowLevel> {
        let mut payload = vec![0; 64];
        payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(message_length));
        payload[2..4].copy_from_slice(&<u16>::to_le_byte_vec(message_chunk_offset));
        payload[4..64].copy_from_slice(&<[char; 60]>::to_le_byte_vec(message_chunk_data));

        self.device.get(u8::from(Rs485BrickletFunction::WriteLowLevel), payload)
    }

    /// Writes characters to the RS485 interface. The characters can be binary data,
    /// ASCII or similar is not necessary.
    ///
    /// The return value is the number of characters that were written.
    ///
    /// See [`set_rs485_configuration`] for configuration possibilities
    /// regarding baudrate, parity and so on.
    ///
    /// [`set_rs485_configuration`]: #method.set_rs485_configuration
    pub fn write(&self, message: &[char]) -> Result<usize, BrickletRecvTimeoutError> {
        let ll_result = self.device.set_high_level(0, message, 65535, 60, &mut |length: usize, chunk_offset: usize, chunk: &[char]| {
            let chunk_length = chunk.len() as u16;
            let mut chunk_array = [<char>::default(); 60];
            chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

            self.write_low_level(length as u16, chunk_offset as u16, chunk_array).recv()
        })?;
        Ok(ll_result.0)
    }

    /// Returns up to *length* characters from receive buffer.
    ///
    /// Instead of polling with this function, you can also use
    /// callbacks. But note that this function will return available
    /// data only when the read receiver is disabled.
    /// See [`enable_read_callback`] and [`get_read_callback_receiver`] receiver.
    ///
    /// [`enable_read_callback`]: #method.enable_read_callback
    /// [`get_read_callback_receiver`]: #method.get_read_callback_receiver
    pub fn read_low_level(&self, length: u16) -> ConvertingReceiver<ReadLowLevel> {
        let mut payload = vec![0; 2];
        payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(length));

        self.device.get(u8::from(Rs485BrickletFunction::ReadLowLevel), payload)
    }

    /// Returns up to *length* characters from receive buffer.
    ///
    /// Instead of polling with this function, you can also use
    /// callbacks. But note that this function will return available
    /// data only when the read receiver is disabled.
    /// See [`enable_read_callback`] and [`get_read_callback_receiver`] receiver.
    ///
    /// [`enable_read_callback`]: #method.enable_read_callback
    /// [`get_read_callback_receiver`]: #method.get_read_callback_receiver
    pub fn read(&self, length: u16) -> Result<Vec<char>, BrickletRecvTimeoutError> {
        let ll_result = self.device.get_high_level(1, &mut || self.read_low_level(length).recv())?;
        Ok(ll_result.0)
    }

    /// Enables the [`get_read_callback_receiver`] receiver.
    ///
    /// By default the receiver is disabled.
    ///
    /// [`get_read_callback_receiver`]: #method.get_read_callback_receiver
    pub fn enable_read_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(Rs485BrickletFunction::EnableReadCallback), payload)
    }

    /// Disables the [`get_read_callback_receiver`] receiver.
    ///
    /// By default the receiver is disabled.
    ///
    /// [`get_read_callback_receiver`]: #method.get_read_callback_receiver
    pub fn disable_read_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(Rs485BrickletFunction::DisableReadCallback), payload)
    }

    /// Returns *true* if the [`get_read_callback_receiver`] receiver is enabled,
    /// *false* otherwise.
    ///
    /// [`get_read_callback_receiver`]: #method.get_read_callback_receiver
    pub fn is_read_callback_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::IsReadCallbackEnabled), payload)
    }

    /// Sets the configuration for the RS485 communication. Available options:
    ///
    /// * Baudrate between 100 and 2000000 baud.
    /// * Parity of none, odd or even.
    /// * Stopbits can be 1 or 2.
    /// * Word length of 5 to 8.
    /// * Half- or Full-Duplex.
    ///
    /// The default is: 115200 baud, parity none, 1 stop bit, word length 8, half duplex.
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_PARITY_NONE
    ///	* RS485_BRICKLET_PARITY_ODD
    ///	* RS485_BRICKLET_PARITY_EVEN
    ///	* RS485_BRICKLET_STOPBITS_1
    ///	* RS485_BRICKLET_STOPBITS_2
    ///	* RS485_BRICKLET_WORDLENGTH_5
    ///	* RS485_BRICKLET_WORDLENGTH_6
    ///	* RS485_BRICKLET_WORDLENGTH_7
    ///	* RS485_BRICKLET_WORDLENGTH_8
    ///	* RS485_BRICKLET_DUPLEX_HALF
    ///	* RS485_BRICKLET_DUPLEX_FULL
    pub fn set_rs485_configuration(&self, baudrate: u32, parity: u8, stopbits: u8, wordlength: u8, duplex: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 8];
        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(baudrate));
        payload[4..5].copy_from_slice(&<u8>::to_le_byte_vec(parity));
        payload[5..6].copy_from_slice(&<u8>::to_le_byte_vec(stopbits));
        payload[6..7].copy_from_slice(&<u8>::to_le_byte_vec(wordlength));
        payload[7..8].copy_from_slice(&<u8>::to_le_byte_vec(duplex));

        self.device.set(u8::from(Rs485BrickletFunction::SetRs485Configuration), payload)
    }

    /// Returns the configuration as set by [`set_rs485_configuration`].
    ///
    /// [`set_rs485_configuration`]: #method.set_rs485_configuration
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_PARITY_NONE
    ///	* RS485_BRICKLET_PARITY_ODD
    ///	* RS485_BRICKLET_PARITY_EVEN
    ///	* RS485_BRICKLET_STOPBITS_1
    ///	* RS485_BRICKLET_STOPBITS_2
    ///	* RS485_BRICKLET_WORDLENGTH_5
    ///	* RS485_BRICKLET_WORDLENGTH_6
    ///	* RS485_BRICKLET_WORDLENGTH_7
    ///	* RS485_BRICKLET_WORDLENGTH_8
    ///	* RS485_BRICKLET_DUPLEX_HALF
    ///	* RS485_BRICKLET_DUPLEX_FULL
    pub fn get_rs485_configuration(&self) -> ConvertingReceiver<Rs485Configuration> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetRs485Configuration), payload)
    }

    /// Sets the configuration for the RS485 Modbus communication. Available options:
    ///
    /// * Slave Address: Address to be used as the Modbus slave address in Modbus slave mode. Valid Modbus slave address range is 1 to 247.
    /// * Master Request Timeout: Specifies how long the master should wait for a response from a slave in milliseconds when in Modbus master mode.
    ///
    /// The default is: Slave Address = 1 and Master Request Timeout = 1000 milliseconds (1 second).
    pub fn set_modbus_configuration(&self, slave_address: u8, master_request_timeout: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 5];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(master_request_timeout));

        self.device.set(u8::from(Rs485BrickletFunction::SetModbusConfiguration), payload)
    }

    /// Returns the configuration as set by [`set_modbus_configuration`].
    ///
    /// [`set_modbus_configuration`]: #method.set_modbus_configuration
    pub fn get_modbus_configuration(&self) -> ConvertingReceiver<ModbusConfiguration> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetModbusConfiguration), payload)
    }

    /// Sets the mode of the Bricklet in which it operates. Available options are
    ///
    /// * RS485,
    /// * Modbus Master RTU and
    /// * Modbus Slave RTU.
    ///
    /// The default is: RS485 mode.
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_MODE_RS485
    ///	* RS485_BRICKLET_MODE_MODBUS_MASTER_RTU
    ///	* RS485_BRICKLET_MODE_MODBUS_SLAVE_RTU
    pub fn set_mode(&self, mode: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));

        self.device.set(u8::from(Rs485BrickletFunction::SetMode), payload)
    }

    /// Returns the configuration as set by [`set_mode`].
    ///
    /// [`set_mode`]: #method.set_mode
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_MODE_RS485
    ///	* RS485_BRICKLET_MODE_MODBUS_MASTER_RTU
    ///	* RS485_BRICKLET_MODE_MODBUS_SLAVE_RTU
    pub fn get_mode(&self) -> ConvertingReceiver<u8> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetMode), payload)
    }

    /// Sets the communication LED configuration. By default the LED shows RS485
    /// communication traffic by flickering.
    ///
    /// You can also turn the LED permanently on/off or show a heartbeat.
    ///
    /// If the Bricklet is in bootloader mode, the LED is off.
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_COMMUNICATION_LED_CONFIG_OFF
    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_ON
    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT
    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION
    pub fn set_communication_led_config(&self, config: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));

        self.device.set(u8::from(Rs485BrickletFunction::SetCommunicationLedConfig), payload)
    }

    /// Returns the configuration as set by [`set_communication_led_config`]
    ///
    /// [`set_communication_led_config`]: #method.set_communication_led_config
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_COMMUNICATION_LED_CONFIG_OFF
    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_ON
    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT
    ///	* RS485_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION
    pub fn get_communication_led_config(&self) -> ConvertingReceiver<u8> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetCommunicationLedConfig), payload)
    }

    /// Sets the error LED configuration.
    ///
    /// By default the error LED turns on if there is any error (see [`get_error_count_callback_receiver`]
    /// callback). If you call this function with the SHOW ERROR option again, the LED
    /// will turn off until the next error occurs.
    ///
    /// You can also turn the LED permanently on/off or show a heartbeat.
    ///
    /// If the Bricklet is in bootloader mode, the LED is off.
    ///
    /// [`get_error_count_callback_receiver`]: #method.get_error_count_callback_receiver
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_ERROR_LED_CONFIG_OFF
    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_ON
    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT
    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR
    pub fn set_error_led_config(&self, config: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));

        self.device.set(u8::from(Rs485BrickletFunction::SetErrorLedConfig), payload)
    }

    /// Returns the configuration as set by [`set_error_led_config`].
    ///
    /// [`set_error_led_config`]: #method.set_error_led_config
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_ERROR_LED_CONFIG_OFF
    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_ON
    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT
    ///	* RS485_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR
    pub fn get_error_led_config(&self) -> ConvertingReceiver<u8> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetErrorLedConfig), payload)
    }

    /// Sets the send and receive buffer size in byte. In sum there is
    /// 10240 byte (10kb) buffer available and the minimum buffer size
    /// is 1024 byte (1kb) for both.
    ///
    /// The current buffer content is lost if this function is called.
    ///
    /// The send buffer holds data that was given by [`write`] and
    /// could not be written yet. The receive buffer holds data that is
    /// received through RS485 but could not yet be send to the
    /// user, either by [`read`] or through [`get_read_callback_receiver`] receiver.
    ///
    /// The default configuration is 5120 byte (5kb) per buffer.
    ///
    /// [`write`]: #method.write
    /// [`read`]: #method.read
    /// [`get_read_callback_receiver`]: #method.get_read_callback_receiver
    pub fn set_buffer_config(&self, send_buffer_size: u16, receive_buffer_size: u16) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(send_buffer_size));
        payload[2..4].copy_from_slice(&<u16>::to_le_byte_vec(receive_buffer_size));

        self.device.set(u8::from(Rs485BrickletFunction::SetBufferConfig), payload)
    }

    /// Returns the buffer configuration as set by [`set_buffer_config`].
    ///
    /// [`set_buffer_config`]: #method.set_buffer_config
    pub fn get_buffer_config(&self) -> ConvertingReceiver<BufferConfig> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetBufferConfig), payload)
    }

    /// Returns the currently used bytes for the send and received buffer.
    ///
    /// See [`set_buffer_config`] for buffer size configuration.
    ///
    /// [`set_buffer_config`]: #method.set_buffer_config
    pub fn get_buffer_status(&self) -> ConvertingReceiver<BufferStatus> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetBufferStatus), payload)
    }

    /// Enables the [`get_error_count_callback_receiver`] receiver.
    ///
    /// By default the receiver is disabled.
    ///
    /// [`get_error_count_callback_receiver`]: #method.get_error_count_callback_receiver
    pub fn enable_error_count_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(Rs485BrickletFunction::EnableErrorCountCallback), payload)
    }

    /// Disables the [`get_error_count_callback_receiver`] receiver.
    ///
    /// By default the receiver is disabled.
    ///
    /// [`get_error_count_callback_receiver`]: #method.get_error_count_callback_receiver
    pub fn disable_error_count_callback(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(Rs485BrickletFunction::DisableErrorCountCallback), payload)
    }

    /// Returns *true* if the [`get_error_count_callback_receiver`] receiver is enabled,
    /// *false* otherwise.
    ///
    /// [`get_error_count_callback_receiver`]: #method.get_error_count_callback_receiver
    pub fn is_error_count_callback_enabled(&self) -> ConvertingReceiver<bool> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::IsErrorCountCallbackEnabled), payload)
    }

    /// Returns the current number of overrun and parity errors.
    pub fn get_error_count(&self) -> ConvertingReceiver<ErrorCount> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetErrorCount), payload)
    }

    /// Returns the current number of errors occurred in Modbus mode.
    ///
    /// * Timeout Error Count: Number of timeouts occurred.
    /// * Checksum Error Count: Number of failures due to Modbus frame CRC16 checksum mismatch.
    /// * Frame Too Big Error Count: Number of times frames were rejected because they exceeded maximum Modbus frame size which is 256 bytes.
    /// * Illegal Function Error Count: Number of errors when an unimplemented or illegal function is requested. This corresponds to Modbus exception code 1.
    /// * Illegal Data Address Error Count: Number of errors due to invalid data address. This corresponds to Modbus exception code 2.
    /// * Illegal Data Value Error Count: Number of errors due to invalid data value. This corresponds to Modbus exception code 3.
    /// * Slave Device Failure Error Count: Number of errors occurred on the slave device which were unrecoverable. This corresponds to Modbus exception code 4.
    pub fn get_modbus_common_error_count(&self) -> ConvertingReceiver<ModbusCommonErrorCount> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetModbusCommonErrorCount), payload)
    }

    /// In Modbus slave mode this function can be used to report a Modbus exception for
    /// a Modbus master request.
    ///
    /// * Request ID: Request ID of the request received by the slave.
    /// * Exception Code: Modbus exception code to report to the Modbus master.
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_EXCEPTION_CODE_TIMEOUT
    ///	* RS485_BRICKLET_EXCEPTION_CODE_SUCCESS
    ///	* RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_FUNCTION
    ///	* RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_ADDRESS
    ///	* RS485_BRICKLET_EXCEPTION_CODE_ILLEGAL_DATA_VALUE
    ///	* RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_FAILURE
    ///	* RS485_BRICKLET_EXCEPTION_CODE_ACKNOWLEDGE
    ///	* RS485_BRICKLET_EXCEPTION_CODE_SLAVE_DEVICE_BUSY
    ///	* RS485_BRICKLET_EXCEPTION_CODE_MEMORY_PARITY_ERROR
    ///	* RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_PATH_UNAVAILABLE
    ///	* RS485_BRICKLET_EXCEPTION_CODE_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
    pub fn modbus_slave_report_exception(&self, request_id: u8, exception_code: i8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 2];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));
        payload[1..2].copy_from_slice(&<i8>::to_le_byte_vec(exception_code));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveReportException), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read coils.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Coils: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_coils_request_callback_receiver`] receiver
    /// with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_coils_request_callback_receiver`]: #method.get_modbus_slave_read_coils_request_callback_receiver
    pub fn modbus_slave_answer_read_coils_request_low_level(
        &self,
        request_id: u8,
        coils_length: u16,
        coils_chunk_offset: u16,
        coils_chunk_data: [bool; 472],
    ) -> ConvertingReceiver<ModbusSlaveAnswerReadCoilsRequestLowLevel> {
        let mut payload = vec![0; 64];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));
        payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(coils_length));
        payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(coils_chunk_offset));
        payload[5..64].copy_from_slice(&<[bool; 472]>::to_le_byte_vec(coils_chunk_data));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadCoilsRequestLowLevel), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read coils.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Coils: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_coils_request_callback_receiver`] receiver
    /// with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_coils_request_callback_receiver`]: #method.get_modbus_slave_read_coils_request_callback_receiver
    pub fn modbus_slave_answer_read_coils_request(&self, request_id: u8, coils: &[bool]) -> Result<(), BrickletRecvTimeoutError> {
        let _ll_result = self.device.set_high_level(2, coils, 65535, 472, &mut |length: usize, chunk_offset: usize, chunk: &[bool]| {
            let chunk_length = chunk.len() as u16;
            let mut chunk_array = [<bool>::default(); 472];
            chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

            let result =
                self.modbus_slave_answer_read_coils_request_low_level(request_id, length as u16, chunk_offset as u16, chunk_array).recv();
            if let Err(BrickletRecvTimeoutError::SuccessButResponseExpectedIsDisabled) = result {
                Ok(Default::default())
            } else {
                result
            }
        })?;
        Ok(())
    }

    /// In Modbus master mode this function can be used to read coils from a slave. This
    /// function creates a Modbus function code 1 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    /// * Count: Number of coils to read.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_read_coils_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be
    /// matched with the Request ID returned from this function to verify that the receiver
    /// is indeed for a particular request.
    ///
    /// [`get_modbus_master_read_coils_response_callback_receiver`]: #method.get_modbus_master_read_coils_response_callback_receiver
    pub fn modbus_master_read_coils(&self, slave_address: u8, starting_address: u32, count: u16) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 7];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(starting_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(count));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadCoils), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read holding registers.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Holding Registers: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_holding_registers_request_callback_receiver`]
    /// receiver with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_holding_registers_request_callback_receiver`]: #method.get_modbus_slave_read_holding_registers_request_callback_receiver
    pub fn modbus_slave_answer_read_holding_registers_request_low_level(
        &self,
        request_id: u8,
        holding_registers_length: u16,
        holding_registers_chunk_offset: u16,
        holding_registers_chunk_data: [u16; 29],
    ) -> ConvertingReceiver<ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel> {
        let mut payload = vec![0; 63];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));
        payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(holding_registers_length));
        payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(holding_registers_chunk_offset));
        payload[5..63].copy_from_slice(&<[u16; 29]>::to_le_byte_vec(holding_registers_chunk_data));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadHoldingRegistersRequestLowLevel), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read holding registers.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Holding Registers: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_holding_registers_request_callback_receiver`]
    /// receiver with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_holding_registers_request_callback_receiver`]: #method.get_modbus_slave_read_holding_registers_request_callback_receiver
    pub fn modbus_slave_answer_read_holding_registers_request(
        &self,
        request_id: u8,
        holding_registers: &[u16],
    ) -> Result<(), BrickletRecvTimeoutError> {
        let _ll_result =
            self.device.set_high_level(3, holding_registers, 65535, 29, &mut |length: usize, chunk_offset: usize, chunk: &[u16]| {
                let chunk_length = chunk.len() as u16;
                let mut chunk_array = [<u16>::default(); 29];
                chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

                let result = self
                    .modbus_slave_answer_read_holding_registers_request_low_level(
                        request_id,
                        length as u16,
                        chunk_offset as u16,
                        chunk_array,
                    )
                    .recv();
                if let Err(BrickletRecvTimeoutError::SuccessButResponseExpectedIsDisabled) = result {
                    Ok(Default::default())
                } else {
                    result
                }
            })?;
        Ok(())
    }

    /// In Modbus master mode this function can be used to read holding registers from a slave.
    /// This function creates a Modbus function code 3 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    /// * Count: Number of holding registers to read.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_read_holding_registers_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_read_holding_registers_response_callback_receiver`]: #method.get_modbus_master_read_holding_registers_response_callback_receiver
    pub fn modbus_master_read_holding_registers(&self, slave_address: u8, starting_address: u32, count: u16) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 7];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(starting_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(count));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadHoldingRegisters), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// write a single coil.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    ///
    /// This function must be called from the [`get_modbus_slave_write_single_coil_request_callback_receiver`]
    /// receiver with the Request ID as provided by the arguments of the receiver.
    ///
    /// [`get_modbus_slave_write_single_coil_request_callback_receiver`]: #method.get_modbus_slave_write_single_coil_request_callback_receiver
    pub fn modbus_slave_answer_write_single_coil_request(&self, request_id: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleCoilRequest), payload)
    }

    /// In Modbus master mode this function can be used to write a single coil of a slave.
    /// This function creates a Modbus function code 5 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    /// * Coil Value: Value to be written.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_write_single_coil_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_write_single_coil_response_callback_receiver`]: #method.get_modbus_master_write_single_coil_response_callback_receiver
    pub fn modbus_master_write_single_coil(&self, slave_address: u8, coil_address: u32, coil_value: bool) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 6];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(coil_address));
        payload[5..6].copy_from_slice(&<bool>::to_le_byte_vec(coil_value));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleCoil), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// write a single register.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    ///
    /// This function must be called from the [`get_modbus_slave_write_single_register_request_callback_receiver`]
    /// receiver with the Request ID, Register Address and Register Value as provided by
    /// the arguments of the receiver.
    ///
    /// [`get_modbus_slave_write_single_register_request_callback_receiver`]: #method.get_modbus_slave_write_single_register_request_callback_receiver
    pub fn modbus_slave_answer_write_single_register_request(&self, request_id: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteSingleRegisterRequest), payload)
    }

    /// In Modbus master mode this function can be used to write a single holding register of a
    /// slave. This function creates a Modbus function code 6 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    /// * Register Value: Value to be written.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_write_single_register_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_write_single_register_response_callback_receiver`]: #method.get_modbus_master_write_single_register_response_callback_receiver
    pub fn modbus_master_write_single_register(
        &self,
        slave_address: u8,
        register_address: u32,
        register_value: u16,
    ) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 7];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(register_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(register_value));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteSingleRegister), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// write multiple coils.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    ///
    /// This function must be called from the [`get_modbus_slave_write_multiple_coils_request_callback_receiver`]
    /// receiver with the Request ID of the receiver.
    ///
    /// [`get_modbus_slave_write_multiple_coils_request_callback_receiver`]: #method.get_modbus_slave_write_multiple_coils_request_callback_receiver
    pub fn modbus_slave_answer_write_multiple_coils_request(&self, request_id: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleCoilsRequest), payload)
    }

    /// In Modbus master mode this function can be used to write multiple coils of a slave.
    /// This function creates a Modbus function code 15 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_write_multiple_coils_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_write_multiple_coils_response_callback_receiver`]: #method.get_modbus_master_write_multiple_coils_response_callback_receiver
    pub fn modbus_master_write_multiple_coils_low_level(
        &self,
        slave_address: u8,
        starting_address: u32,
        coils_length: u16,
        coils_chunk_offset: u16,
        coils_chunk_data: [bool; 440],
    ) -> ConvertingReceiver<ModbusMasterWriteMultipleCoilsLowLevel> {
        let mut payload = vec![0; 64];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(starting_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(coils_length));
        payload[7..9].copy_from_slice(&<u16>::to_le_byte_vec(coils_chunk_offset));
        payload[9..64].copy_from_slice(&<[bool; 440]>::to_le_byte_vec(coils_chunk_data));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleCoilsLowLevel), payload)
    }

    /// In Modbus master mode this function can be used to write multiple coils of a slave.
    /// This function creates a Modbus function code 15 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_write_multiple_coils_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_write_multiple_coils_response_callback_receiver`]: #method.get_modbus_master_write_multiple_coils_response_callback_receiver
    pub fn modbus_master_write_multiple_coils(
        &self,
        slave_address: u8,
        starting_address: u32,
        coils: &[bool],
    ) -> Result<u8, BrickletRecvTimeoutError> {
        let ll_result = self.device.set_high_level(4, coils, 65535, 440, &mut |length: usize, chunk_offset: usize, chunk: &[bool]| {
            let chunk_length = chunk.len() as u16;
            let mut chunk_array = [<bool>::default(); 440];
            chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

            self.modbus_master_write_multiple_coils_low_level(
                slave_address,
                starting_address,
                length as u16,
                chunk_offset as u16,
                chunk_array,
            )
            .recv()
        })?;
        Ok(ll_result.1.request_id)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// write multiple registers.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    ///
    /// This function must be called from the [`get_modbus_slave_write_multiple_registers_request_callback_receiver`]
    /// receiver with the Request ID of the receiver.
    ///
    /// [`get_modbus_slave_write_multiple_registers_request_callback_receiver`]: #method.get_modbus_slave_write_multiple_registers_request_callback_receiver
    pub fn modbus_slave_answer_write_multiple_registers_request(&self, request_id: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerWriteMultipleRegistersRequest), payload)
    }

    /// In Modbus master mode this function can be used to write multiple registers of a slave.
    /// This function creates a Modbus function code 16 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_write_multiple_registers_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_write_multiple_registers_response_callback_receiver`]: #method.get_modbus_master_write_multiple_registers_response_callback_receiver
    pub fn modbus_master_write_multiple_registers_low_level(
        &self,
        slave_address: u8,
        starting_address: u32,
        registers_length: u16,
        registers_chunk_offset: u16,
        registers_chunk_data: [u16; 27],
    ) -> ConvertingReceiver<ModbusMasterWriteMultipleRegistersLowLevel> {
        let mut payload = vec![0; 63];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(starting_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(registers_length));
        payload[7..9].copy_from_slice(&<u16>::to_le_byte_vec(registers_chunk_offset));
        payload[9..63].copy_from_slice(&<[u16; 27]>::to_le_byte_vec(registers_chunk_data));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterWriteMultipleRegistersLowLevel), payload)
    }

    /// In Modbus master mode this function can be used to write multiple registers of a slave.
    /// This function creates a Modbus function code 16 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_write_multiple_registers_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_write_multiple_registers_response_callback_receiver`]: #method.get_modbus_master_write_multiple_registers_response_callback_receiver
    pub fn modbus_master_write_multiple_registers(
        &self,
        slave_address: u8,
        starting_address: u32,
        registers: &[u16],
    ) -> Result<u8, BrickletRecvTimeoutError> {
        let ll_result = self.device.set_high_level(5, registers, 65535, 27, &mut |length: usize, chunk_offset: usize, chunk: &[u16]| {
            let chunk_length = chunk.len() as u16;
            let mut chunk_array = [<u16>::default(); 27];
            chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

            self.modbus_master_write_multiple_registers_low_level(
                slave_address,
                starting_address,
                length as u16,
                chunk_offset as u16,
                chunk_array,
            )
            .recv()
        })?;
        Ok(ll_result.1.request_id)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read discrete inputs.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Discrete Inputs: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_discrete_inputs_request_callback_receiver`]
    /// receiver with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_discrete_inputs_request_callback_receiver`]: #method.get_modbus_slave_read_discrete_inputs_request_callback_receiver
    pub fn modbus_slave_answer_read_discrete_inputs_request_low_level(
        &self,
        request_id: u8,
        discrete_inputs_length: u16,
        discrete_inputs_chunk_offset: u16,
        discrete_inputs_chunk_data: [bool; 472],
    ) -> ConvertingReceiver<ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel> {
        let mut payload = vec![0; 64];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));
        payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(discrete_inputs_length));
        payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(discrete_inputs_chunk_offset));
        payload[5..64].copy_from_slice(&<[bool; 472]>::to_le_byte_vec(discrete_inputs_chunk_data));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadDiscreteInputsRequestLowLevel), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read discrete inputs.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Discrete Inputs: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_discrete_inputs_request_callback_receiver`]
    /// receiver with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_discrete_inputs_request_callback_receiver`]: #method.get_modbus_slave_read_discrete_inputs_request_callback_receiver
    pub fn modbus_slave_answer_read_discrete_inputs_request(
        &self,
        request_id: u8,
        discrete_inputs: &[bool],
    ) -> Result<(), BrickletRecvTimeoutError> {
        let _ll_result =
            self.device.set_high_level(6, discrete_inputs, 65535, 472, &mut |length: usize, chunk_offset: usize, chunk: &[bool]| {
                let chunk_length = chunk.len() as u16;
                let mut chunk_array = [<bool>::default(); 472];
                chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

                let result = self
                    .modbus_slave_answer_read_discrete_inputs_request_low_level(request_id, length as u16, chunk_offset as u16, chunk_array)
                    .recv();
                if let Err(BrickletRecvTimeoutError::SuccessButResponseExpectedIsDisabled) = result {
                    Ok(Default::default())
                } else {
                    result
                }
            })?;
        Ok(())
    }

    /// In Modbus master mode this function can be used to read discrete inputs from a slave.
    /// This function creates a Modbus function code 2 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    /// * Count: Number of discrete inputs to read.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_read_discrete_inputs_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_read_discrete_inputs_response_callback_receiver`]: #method.get_modbus_master_read_discrete_inputs_response_callback_receiver
    pub fn modbus_master_read_discrete_inputs(&self, slave_address: u8, starting_address: u32, count: u16) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 7];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(starting_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(count));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadDiscreteInputs), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read input registers.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Input Registers: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_input_registers_request_callback_receiver`] receiver
    /// with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_input_registers_request_callback_receiver`]: #method.get_modbus_slave_read_input_registers_request_callback_receiver
    pub fn modbus_slave_answer_read_input_registers_request_low_level(
        &self,
        request_id: u8,
        input_registers_length: u16,
        input_registers_chunk_offset: u16,
        input_registers_chunk_data: [u16; 29],
    ) -> ConvertingReceiver<ModbusSlaveAnswerReadInputRegistersRequestLowLevel> {
        let mut payload = vec![0; 63];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(request_id));
        payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(input_registers_length));
        payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(input_registers_chunk_offset));
        payload[5..63].copy_from_slice(&<[u16; 29]>::to_le_byte_vec(input_registers_chunk_data));

        self.device.set(u8::from(Rs485BrickletFunction::ModbusSlaveAnswerReadInputRegistersRequestLowLevel), payload)
    }

    /// In Modbus slave mode this function can be used to answer a master request to
    /// read input registers.
    ///
    /// * Request ID: Request ID of the corresponding request that is being answered.
    /// * Input Registers: Data that is to be sent to the Modbus master for the corresponding request.
    ///
    /// This function must be called from the [`get_modbus_slave_read_input_registers_request_callback_receiver`] receiver
    /// with the Request ID as provided by the argument of the receiver.
    ///
    /// [`get_modbus_slave_read_input_registers_request_callback_receiver`]: #method.get_modbus_slave_read_input_registers_request_callback_receiver
    pub fn modbus_slave_answer_read_input_registers_request(
        &self,
        request_id: u8,
        input_registers: &[u16],
    ) -> Result<(), BrickletRecvTimeoutError> {
        let _ll_result =
            self.device.set_high_level(7, input_registers, 65535, 29, &mut |length: usize, chunk_offset: usize, chunk: &[u16]| {
                let chunk_length = chunk.len() as u16;
                let mut chunk_array = [<u16>::default(); 29];
                chunk_array[0..chunk_length as usize].copy_from_slice(&chunk);

                let result = self
                    .modbus_slave_answer_read_input_registers_request_low_level(request_id, length as u16, chunk_offset as u16, chunk_array)
                    .recv();
                if let Err(BrickletRecvTimeoutError::SuccessButResponseExpectedIsDisabled) = result {
                    Ok(Default::default())
                } else {
                    result
                }
            })?;
        Ok(())
    }

    /// In Modbus master mode this function can be used to read input registers from a slave.
    /// This function creates a Modbus function code 4 request.
    ///
    /// * Slave Address: Address of the target Modbus slave.
    /// * 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.
    /// * Count: Number of input registers to read.
    ///
    /// Upon success the function will return a non-zero request ID which will represent
    /// the current request initiated by the Modbus master. In case of failure the returned
    /// request ID will be 0.
    ///
    /// When successful this function will also invoke the [`get_modbus_master_read_input_registers_response_callback_receiver`]
    /// callback. In this receiver the Request ID provided by the receiver argument must be matched
    /// with the Request ID returned from this function to verify that the receiver is indeed for a
    /// particular request.
    ///
    /// [`get_modbus_master_read_input_registers_response_callback_receiver`]: #method.get_modbus_master_read_input_registers_response_callback_receiver
    pub fn modbus_master_read_input_registers(&self, slave_address: u8, starting_address: u32, count: u16) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 7];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(slave_address));
        payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(starting_address));
        payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(count));

        self.device.get(u8::from(Rs485BrickletFunction::ModbusMasterReadInputRegisters), payload)
    }

    /// Returns the error count for the communication between Brick and Bricklet.
    ///
    /// The errors are divided into
    ///
    /// * ACK checksum errors,
    /// * message checksum errors,
    /// * framing errors and
    /// * overflow errors.
    ///
    /// The errors counts are for errors that occur on the Bricklet side. All
    /// Bricks have a similar function that returns the errors on the Brick side.
    pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetSpitfpErrorCount), payload)
    }

    /// Sets the bootloader mode and returns the status after the requested
    /// mode change was instigated.
    ///
    /// You can change from bootloader mode to firmware mode and vice versa. A change
    /// from bootloader mode to firmware mode will only take place if the entry function,
    /// device identifier and CRC are present and correct.
    ///
    /// This function is used by Brick Viewer during flashing. It should not be
    /// necessary to call it in a normal user program.
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_OK
    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
    ///	* RS485_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
    pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));

        self.device.get(u8::from(Rs485BrickletFunction::SetBootloaderMode), payload)
    }

    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
    ///
    /// [`set_bootloader_mode`]: #method.set_bootloader_mode
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
    ///	* RS485_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
    pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetBootloaderMode), payload)
    }

    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
    /// to be increased by chunks of size 64. The data is written to flash
    /// every 4 chunks (which equals to one page of size 256).
    ///
    /// This function is used by Brick Viewer during flashing. It should not be
    /// necessary to call it in a normal user program.
    ///
    /// [`write_firmware`]: #method.write_firmware
    pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));

        self.device.set(u8::from(Rs485BrickletFunction::SetWriteFirmwarePointer), payload)
    }

    /// Writes 64 Bytes of firmware at the position as written by
    /// [`set_write_firmware_pointer`] before. The firmware is written
    /// to flash every 4 chunks.
    ///
    /// You can only write firmware in bootloader mode.
    ///
    /// This function is used by Brick Viewer during flashing. It should not be
    /// necessary to call it in a normal user program.
    ///
    /// [`set_write_firmware_pointer`]: #method.set_write_firmware_pointer
    pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
        let mut payload = vec![0; 64];
        payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));

        self.device.get(u8::from(Rs485BrickletFunction::WriteFirmware), payload)
    }

    /// Sets the status LED configuration. By default the LED shows
    /// communication traffic between Brick and Bricklet, it flickers once
    /// for every 10 received data packets.
    ///
    /// You can also turn the LED permanently on/off or show a heartbeat.
    ///
    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_STATUS_LED_CONFIG_OFF
    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_ON
    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
    pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 1];
        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));

        self.device.set(u8::from(Rs485BrickletFunction::SetStatusLedConfig), payload)
    }

    /// Returns the configuration as set by [`set_status_led_config`]
    ///
    /// [`set_status_led_config`]: #method.set_status_led_config
    ///
    /// Associated constants:
    /// * RS485_BRICKLET_STATUS_LED_CONFIG_OFF
    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_ON
    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
    ///	* RS485_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
    pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetStatusLedConfig), payload)
    }

    /// Returns the temperature in °C as measured inside the microcontroller. The
    /// value returned is not the ambient temperature!
    ///
    /// The temperature is only proportional to the real temperature and it has bad
    /// accuracy. Practically it is only useful as an indicator for
    /// temperature changes.
    pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetChipTemperature), payload)
    }

    /// Calling this function will reset the Bricklet. All configurations
    /// will be lost.
    ///
    /// After a reset you have to create new device objects,
    /// calling functions on the existing ones will result in
    /// undefined behavior!
    pub fn reset(&self) -> ConvertingReceiver<()> {
        let payload = vec![0; 0];

        self.device.set(u8::from(Rs485BrickletFunction::Reset), payload)
    }

    /// Writes a new UID into flash. If you want to set a new UID
    /// you have to decode the Base58 encoded UID string into an
    /// integer first.
    ///
    /// We recommend that you use Brick Viewer to change the UID.
    pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
        let mut payload = vec![0; 4];
        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));

        self.device.set(u8::from(Rs485BrickletFunction::WriteUid), payload)
    }

    /// Returns the current UID as an integer. Encode as
    /// Base58 to get the usual string version.
    pub fn read_uid(&self) -> ConvertingReceiver<u32> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::ReadUid), payload)
    }

    /// Returns the UID, the UID where the Bricklet is connected to,
    /// the position, the hardware and firmware version as well as the
    /// device identifier.
    ///
    /// The position can be 'a', 'b', 'c' or 'd'.
    ///
    /// The device identifier numbers can be found [here](device_identifier).
    /// |device_identifier_constant|
    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
        let payload = vec![0; 0];

        self.device.get(u8::from(Rs485BrickletFunction::GetIdentity), payload)
    }
}