Skip to content

Commit fee9b6d

Browse files
committed
Add RTU compatibility to DUE
1 parent 581a61f commit fee9b6d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/libmodbus/modbus-rtu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,11 @@ static int _modbus_rtu_connect(modbus_t *ctx)
654654
return -1;
655655
}
656656
#elif defined(ARDUINO)
657+
#ifdef ARDUINO_ARCH_SAM
658+
ctx_rtu->rs485->begin(ctx_rtu->baud, static_cast<UARTClass::UARTModes>(ctx_rtu->config));
659+
#else
657660
ctx_rtu->rs485->begin(ctx_rtu->baud, ctx_rtu->config);
661+
#endif
658662
ctx_rtu->rs485->receive();
659663
#else
660664
/* The O_NOCTTY flag tells UNIX that this program doesn't want

src/libmodbus/modbus.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
/*
2-
* Copyright © 2001-2011 Stéphane Raimbault <[email protected]>
3-
* Copyright © 2018 Arduino SA. All rights reserved.
2+
* Copyright © 2001-2011 Stéphane Raimbault <[email protected]>
3+
* Copyright © 2018 Arduino SA. All rights reserved.
44
*
55
* SPDX-License-Identifier: LGPL-2.1+
66
*
77
* This library implements the Modbus protocol.
88
* http://libmodbus.org/
99
*/
1010

11+
#ifdef ARDUINO_SAM_DUE
12+
#include <Arduino.h> //moust be include here to compile
13+
#endif
14+
15+
16+
#ifndef _MSC_VER
17+
#ifndef ARDUINO_SAM_DUE
18+
//compile with DUE without those includes
1119
#include <stdio.h>
1220
#include <string.h>
1321
#include <stdlib.h>
1422
#include <stdarg.h>
15-
#include <errno.h>
1623
#include <limits.h>
1724
#include <time.h>
18-
#ifndef _MSC_VER
25+
//make due not compile if included
1926
#include <unistd.h>
2027
#endif
28+
#include <errno.h>
29+
#endif
2130
#ifdef ARDUINO
2231
#include <stdbool.h>
32+
33+
#ifndef ARDUINO_SAM_DUE
2334
#include <Arduino.h>
35+
#endif
36+
2437

2538
#ifndef DEBUG
2639
#define printf(...) {}
@@ -1926,4 +1939,4 @@ size_t strlcpy(char *dest, const char *src, size_t dest_size)
19261939

19271940
return (s - src - 1); /* count does not include NUL */
19281941
}
1929-
#endif
1942+
#endif

0 commit comments

Comments
 (0)