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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use with STM32

tpcorrea opened this issue · comments

Dear All,

I am trying to use this library with STM32. So far, I found that STM32Ethernet has some differences to Arduino Ethernet. In the earlier, accept() is a private function, so we have to call available() instead at this point of ModbusTCPTemplate.h:

while (millis() - taskStart < MODBUSIP_MAX_READMS && (c = tcpserver->available())) {

The issue I am facing now is that the code only comes out of this while with data when the TCP connection is closed (and tcpserver becomes not available).

The solution I found so far was to change the continue keyword to break down in the code, once the tcpclient[n] has been assigned with the currentClient

if (n > -1) {
   tcpclient[n] = currentClient;
   BIT_SET(tcpServerConnection, n);
#if defined(MODBUSIP_DEBUG)
   Serial.print("IP: Conn ");
   Serial.println(n);
#endif
   break; // (BREAK INSTEAD OF CONTINUE while
}

Is this an acceptable solution? Is there any better one?

Best regards,
Tomas

It will work this way without issues.
I've included enhancement you provided as option to the library code.
You may now just uncomment
#define MODBUSIP_USE_AVAILABLE
to use .available() and break implementation instead default one.