diff --git a/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino b/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino index bedc2b7..06f6590 100644 --- a/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino +++ b/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino @@ -14,6 +14,9 @@ #include #include +#if defined(ARDUINO_ARCH_ZEPHYR) +#include +#endif #include // ArduinoModbus depends on the ArduinoRS485 library #include @@ -26,7 +29,11 @@ byte mac[] = { }; IPAddress ip(192, 168, 1, 177); +#if defined(ARDUINO_ARCH_ZEPHYR) +ZephyrServer ethServer(502); +#else EthernetServer ethServer(502); +#endif ModbusTCPServer modbusTCPServer; @@ -81,8 +88,12 @@ void setup() { void loop() { // listen for incoming clients +#if defined(ARDUINO_ARCH_ZEPHYR) + EthernetClient client = ethServer.accept(); +#else EthernetClient client = ethServer.available(); - +#endif + if (client) { // a new client connected Serial.println("new client"); diff --git a/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino b/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino index 0322c89..ba8884e 100644 --- a/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino +++ b/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino @@ -12,8 +12,12 @@ */ #include +#if defined(ARDUINO_ARCH_ZEPHYR) +#include +#else #include // for MKR WiFi 1010 // #include // for MKR1000 +#endif #include // ArduinoModbus depends on the ArduinoRS485 library #include diff --git a/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino b/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino index 60276c0..27f0f0d 100644 --- a/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino +++ b/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino @@ -12,8 +12,13 @@ */ #include +#if defined(ARDUINO_ARCH_ZEPHYR) +#include +#include +#else #include // for MKR WiFi 1010 // #include // for MKR1000 +#endif #include // ArduinoModbus depends on the ArduinoRS485 library #include @@ -28,7 +33,11 @@ const int ledPin = LED_BUILTIN; int status = WL_IDLE_STATUS; +#if defined(ARDUINO_ARCH_ZEPHYR) +ZephyrServer wifiServer(502); +#else WiFiServer wifiServer(502); +#endif ModbusTCPServer modbusTCPServer; @@ -74,8 +83,12 @@ void setup() { void loop() { // listen for incoming clients +#if defined(ARDUINO_ARCH_ZEPHYR) + WiFiClient client = wifiServer.accept(); +#else WiFiClient client = wifiServer.available(); - +#endif + if (client) { // a new client connected Serial.println("new client"); diff --git a/library.properties b/library.properties index 84aace6..4a82667 100644 --- a/library.properties +++ b/library.properties @@ -6,6 +6,6 @@ sentence=Use Modbus equipment with your Arduino. paragraph=Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. category=Communication url=https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus -architectures=megaavr,samd,mbed_nano,mbed_portenta,mbed_opta +architectures=megaavr,samd,mbed_nano,mbed_portenta,mbed_opta,zephyr,zephyr_main,zephyr_contrib includes=ArduinoModbus.h depends=ArduinoRS485 diff --git a/src/ModbusClient.cpp b/src/ModbusClient.cpp index bf4b329..b7dc982 100644 --- a/src/ModbusClient.cpp +++ b/src/ModbusClient.cpp @@ -411,7 +411,7 @@ const char* ModbusClient::lastError() return NULL; } - return modbus_strerror(errno); + return modbus_strerror(errno); } void ModbusClient::setTimeout(unsigned long ms) diff --git a/src/libmodbus/modbus-private.h b/src/libmodbus/modbus-private.h index 79e7b93..663df70 100644 --- a/src/libmodbus/modbus-private.h +++ b/src/libmodbus/modbus-private.h @@ -20,6 +20,7 @@ struct timeval { uint32_t tv_usec; }; #else +# include # include #endif #else diff --git a/src/libmodbus/modbus.c b/src/libmodbus/modbus.c index 3afeb3b..2bf59e7 100644 --- a/src/libmodbus/modbus.c +++ b/src/libmodbus/modbus.c @@ -25,6 +25,7 @@ #ifndef DEBUG #define printf(...) {} #define fprintf(...) {} +#define vfprintf(...) {} #endif #endif