I have programmed Arduino as a modbus TCP/IP Server (Slave) and have 1 HC-SR04 Ultrasonic sensor wired to the arduino using the HC-SR04 in 3 pin mode. I am also using the NewPing Library.
I am using Modscan32 and/or Reliance 4 SCADA software as the Client (Master).
I keep getting a timeout error with both Modscan32 and Reliance 4 SCADA and don't know what to do about it.
If you have experienced similar or know of a solution please let us know on this forum.
I am using this Modbus TCP/IP Library GitHub - andresarmento/modbus-arduino: A library that allows your Arduino to communicate via Modbus protocol, acting as a slave (master in development). Supports serial (RS-232, RS-485) and IP via Ethernet (Modbus IP)..
#include <ModbusIP.h>
#include <Modbus.h>
#include <Ethernet.h>
#include <SPI.h>
#include <NewPing.h>
#define Ultra_1_TRIG_PIN A0
#define Ultra_1_ECHO_PIN A0
// Declare Variables
int distance;
// Input Registers
const int distance_ir = 100;
NewPing sonar(Ultra_1_TRIG_PIN, Ultra_1_ECHO_PIN);
ModbusIP mb;
long ts;
void setup() {
Serial.begin(115200);
// The media access control (ethernet hardware) address for the shield
byte mac[] = { 0x6A, 0xC1, 0x51, 0x4B, 0x51, 0xE9 };
// The IP address for the shield
byte ip[] = { 192, 168, 1, 120 };
mb.config(mac, ip);
mb.addIreg(distance_ir);
mb.Ireg (distance_ir, distance);
ts = millis();
}
void loop() {
mb.task();
if (millis() > ts + 100) {
ts = millis();
distance = sonar.ping_cm();
mb.Ireg(distance_ir, distance);
}
}[code]
Reliance 4 Socket disconnect