emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.
Other
534 stars 190 forks source link

Question: is it possible to have multiple servers on the same ESP8266 / serial line ? #355

Closed MichielfromNL closed 3 weeks ago

MichielfromNL commented 5 months ago

HI,

I need some help with getting a multi-server configuration to work on ESP8266. Setup: I emulate two DTSU666 3-phase power meters, for a power unit that is connected to my ESP8266/485MAX The power unit subsequently reads on address 1 and address 2

When I run the sketch with 1 server instance (on address1) everything works fine. But when I add a second ModbusRTU server (address2) one the same line, I can't get it to work , and I can't figure out why not, I suspect that only one will read the serial line so data is "lost" for server 2 when server 1 decides that it is not adressed. Hence the question: is it possible to have 2 servers running on the same ESP8266/MAX485, with different adresses?

Thanks!

emelianov commented 5 months ago

For sure, multiple servers(slaves) are okay on single line. If client(master) is also driven by the library code? That case could you share the code to review?

MichielfromNL commented 4 months ago

HI, I looked further into it, and it makes sense that it won't work for multiple slaves listening on the same serial port. reason: modbusRTU.cpp lines 236 -245. If there is data available on the serial port, the address is read. When not a valid address, the frame is discarded. And data which is read from a port can't be unread - and made available for another slave. Solution: multiple max(3)485\s, connected both on the same AB RS485 lines, then it works like a charm. Sorry for bothering you with this question.

emelianov commented 4 months ago

Under 'serial line' I've assumed sharing physical line not device Serial port. The library object instances unable to share the same port. So your solution to use multiple ports|converters is right. Also it's possible to configure the library object instance to answer on multiple SlaveID: https://github.com/emelianov/modbus-esp8266/blob/master/examples/Bridge/MultipleServerID/MultipleServerID.ino