I have a problem with modbus master and slave TCP communication,
On windows computer: When Master and Slave connect each other they communicate successfuly on 50905->502 ports, when I disconnect to ethernet cable from master device and connect again ethernet port changing for master like 50908->502 ( than master send ack to slave but least tcp connection alive for the slave (50905->502 ) and anyone close it. Master PC couldnt close before socket, so slave device ended all new connection request for master, slave try to close before connection every connection trying. Q1) Why pc open new tcp port when on plug ethernet connection ? Why is current communication not resumed from the previous port when the connection is restored? Is that correct situation or not ? Q2) Should slave manage port close operation, or master responsible for this ?
How can I analyse my problem and solve please help me ?
According to command : I change below values:
/* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */ #ifndef TCP_KEEPIDLE_DEFAULT #define TCP_KEEPIDLE_DEFAULT 1000UL /* Default KEEPALIVE timer in milliseconds */ #endif #ifndef TCP_KEEPINTVL_DEFAULT #define TCP_KEEPINTVL_DEFAULT 1000UL /* Default Time between KEEPALIVE probes in milliseconds */ #endif
and I add below line in lwipopth.h:
#define LWIP_TCP_KEEPALIVE 1// enable "kepp-alive"
When I un plug ethernet cable and connect again I get below packets forever. I couldnt solve above solution how can I solve this problem ? enter image description here
1.40 => slave, other master