Arduino server can't find clients to connect 2

Hello,

I am working on a little project to interface modbus TCP messages (with an ethernet shield) to RS-232 messages for an envirmental chamber.

My problem right now is that I can’t connect with the modbus tester I am using. I was able to connect to it last week and I haven’t uploaded any other code since then so I don’t know what went wrong. I am able to ping it from the computer and there are no errors from the auduino so it knows that the Ethernet shield is there.

Not really sure what is wrong with it. I want to know if I am doing something wrong with my code or if I should just get a new Ethernet shield and try and see if that is the problem.

Here is the code.

Thanks.

#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoModbus.h>

EthernetServer server(502);
ModbusTCPServer modbusinterface;
byte mac = { 0xA8, 0x61, 0x0B, 0xAE, 0x23, 0x88 };
IPAddress ip (192,168,0,223);
IPAddress myDns(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetClient client;
int temp_send=25;
bool start = true;
void setup() {

// put your setup code here, to run once:
Ethernet.init(10);

Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Ethernet.begin(mac, ip, myDns, gateway, subnet);
delay(1000);

// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(F(“Ethernet shield was not found. Sorry, can’t run without hardware.”));
while (true) {
; // do nothing, no point running without Ethernet hardware
}
}

if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(F(“Ethernet cable is not connected.”));
}
server.begin();

if(!modbusinterface.begin()){
Serial.println(“Modbus server could not start”);
}
modbusinterface.configureHoldingRegisters(0x00, 2);
Serial.println(“step up done”);
}

/*int readascii(){
String value;
bool isneg=false;
char input;
uint8_t len = 0;
int ans = 200;
while(Serial.available()){

input = Serial.read();

isneg=(input == ‘-’);
if((input-‘0’)>=0 ||(input-‘0’)<=9||(input==’.’)&&(len<8)){
value += input;
len++;
Serial.println(len);
}
}
if(len==0){
//Serial.println(F(“made it here”));
return ans;
}
char valuechararray[len];
value.toCharArray(valuechararray,len);
ans = atoi(valuechararray);
if(isneg){
ans=ans*-1;
}
return ans;
}*/

void loop() {
// waits for client to be available
EthernetClient client = server.available();

if(client){
modbusinterface.accept(client);

if(start){ //init of chamber
Serial.print(“start system”);
delay(100);
Serial.print(“set circulators = on”);
delay(100);
start = false;
}

// poll for Modbus TCP requests, while client connected
modbusinterface.poll();
Serial.print("set setpoint 1 = ");
Serial.println(modbusinterface.holdingRegisterRead(0x00)); //set setpoint for chamber

//Serial.print(“read pv 1”);
//delay(500);

//temp_send=readascii(); //read chamber temp
//if(temp_send!=200){
//modbusinterface.holdingRegisterWrite(0x01,temp_send);//if different send to client
//}
delay(100);
}
}

To get started off right, follow the below.

You should read the "Read this before posting a program question..." at the top of the discussion list.