Read Sense Sht Series Modbus Rtu then connect Tcp/ip to PC

Guys i have a question. i am waiting for your helps.
i have Sense Sht series sensor. i read the sensor over Rtu with modbus poll. But now i need the connect Tcp/ip to modbus. sensor working Rtu . long story short i communicate max485 sensor and arduino and connect ethernet to pc. can you help guys any suggestions?? i knew tcp and rtu protocols.
thank you all .

Did I get your intention correctly, are you trying to build a ModBus RTU -> ModBus TCP gateway?
The PC will probably be the master, that sense anything device (you forget the link to that device) is probably the slave.
That means you have to look for a ModBus TCP slave (= server) library and a ModBus RTU master library. I'm not aware of a single library that would fulfill your needs.

thank you for help.
i understand you said ok i'll try but i am connecting pc from tcp. so tcp master rtu slave ?? or your way works??
and any suggestion link or web site build a ModBus RTU -> ModBus TCP gateway ??
thanks all.

but i am connecting pc from tcp. so tcp master rtu slave ?

I guess you're trying to read some values from a ModBus device with your PC. So you have some ModBus TCP client on your PC and a ModBus RTU slave device (you called it sense SHT, BTW, post a link to that sensor!). If these guesses are correct, you need the libraries as I wrote in my first answer.

yes you are right. like you said i am looking for that. ok thank you your help i am gonna try that libraries. thanks again.

Now i am trying read data rtu from sensor with master arduino and with SPI send data to slave arduino and connect ethernet to modbus. any suggestions ??

sensor is this http://www.senseandcontrol.com/wp-content/uploads/2016/10/SHT-Datasheet-v300916.pdf

its no need to definition any register for read data. so i see data on modbus poll but i cant send data with SPI to slave arduino ?? how can i do this??
thanks all.

Now i am trying read data rtu from sensor with master arduino and with SPI send data to slave arduino and connect ethernet to modbus. any suggestions ??

Why increasing the complexity and introducing a second Arduino? I don't see a problem in handling the complete converter in one Arduino, you just cannot expect finished software for that purpose.

sensor is this http://www.senseandcontrol.com/wp-content/uploads/2016/10/SHT-Datasheet-v300916.pdf

That's just a very expensive module to access an SHT-x1 sensor by ModBus. Why don't you read the SHT-31 sensor by the Arduino directly (I2C) and make the value available by ModBus TCP?

i have to do this way because my boss want it . i think i can't one arduino. i dont know i am stucking right now i need your help please.

i think i can't one arduino.

Why? I don't see a need for two Arduinos. I would just increase complexity and makes nothing easier.

i have to do this way because my boss want it

So your boss wants you to use a ModBus RTU sensor but it wants you to read that sensor by ModBus TCP? I think your boss shouldn't make technical decisions then. Sounds quite stupid to me.

i dont know i am stucking right now i need your help please.

I'll try to help you but I won't do your job. Try to implement that and ask questions and post your code if you get into a problem.

hi
i did everything and it's worked.but i read to sensor over modbus rtu.and i did not definition any register adress its already define in sensor. so i am gonna serial read to registers and send spi to other arduino. spi its worked. but i did not read serial read to sensor. i think i do not definition the register. how can i read serial or another way it doesnt matter just read the sensor. i need your help please.
thanks all

i did everything and it's worked.but i read to sensor over modbus rtu.and i did not definition any register adress its already define in sensor. so i am gonna serial read to registers and send spi to other arduino. spi its worked. but i did not read serial read to sensor. i think i do not definition the register. how can i read serial or another way it doesnt matter just read the sensor. i need your help please.

Sorry, that makes no sense to me.

First, it did not work else you won't ask here again.

The rest of the post seems to describe the behavior of a sketch. But you didn't post the code as I asked you to.
Forget the SPI to another Arduino! That makes your setup too complex and is not necessary. Stick with one Arduino! Post the code you put on that Arduino. And post links to the used hardware (Ethernet shield/module, RS-485 adapter)!

ok thank you again.
that’s my code master and slave.
master code
// master
#include <SimpleModbusSlave.h>
#include <SPI.h>
#include “SPI_anything.h”
unsigned int holdingRegs[1];
int c;
// create a structure to store the different data values:

typedef struct myStruct
{

int b;

};

myStruct foo;

void setup ()
{
modbus_configure(&Serial, 19200, SERIAL_8N1, 1, 2, 1, holdingRegs);
SPI.begin ();
// Slow down the master a bit
SPI.setClockDivider(SPI_CLOCK_DIV8);
Serial.begin(19200);

} // end of setup

void loop ()
{
modbus_update();

int c=holdingRegs[0];
Serial.println(c);
digitalWrite(SS, LOW);
SPI_writeAnything (c);
digitalWrite(SS, HIGH);
delay (1000); // for testing

//foo.c++;
} // end of loop

slave code

// slave

#include <SPI.h>
#include “SPI_anything.h”
int c;
// create a structure to store the different data values:
typedef struct myStruct
{
//byte a;
int b;
//ong c;
};

volatile myStruct foo;
volatile bool haveData = false;

void setup ()
{
Serial.begin (19200); // debugging

// have to send on master in, slave out
pinMode(MISO, OUTPUT);

// turn on SPI in slave mode
SPCR |= _BV(SPE);

// now turn on interrupts
SPI.attachInterrupt();

} // end of setup

void loop ()
{
if (haveData)
{
//Serial.println ((int) foo.a);
Serial.println (c);
//Serial.println (foo.c);
Serial.println ();
haveData = false;
}
} // end of loop

// SPI interrupt routine
ISR (SPI_STC_vect)
{
SPI_readAnything_ISR (c);
haveData = true;
} // end of interrupt routine SPI_STC_vect

i just want to read sensor register and send the other orduino. sending is ok spi is ok but not read sensor register cause i didnt definition register at first i think. and ethernet part not important right now. just read registor and send spi. i read master arduino’ registers over modbus rtu and send it. but sensor’s register not read it. int c=holdingRegs[0]; thats the tricky one i think. and i used rs485 usb connect with pc. and i said my sensor is sense sht series.http://www.senseandcontrol.com/wp-content/uploads/2016/10/SHT-Datasheet-v300916.pdf . i hope is everything you want is there. thank you again. regards.

i just want to read sensor register and send the other orduino. sending is ok spi is ok but not read sensor register cause i didnt definition register at first i think. and ethernet part not important right now. just read registor and send spi.

I repeat: Forget to have two Arduinos for this setup. It’s nonsense to increase complexity without a need.

i read master arduino’ registers over modbus rtu and send it.

You cannot read the registers of a master. It’s always the other way around, the master reads the registers of the slave. That’s the reason why you’re choice of using the SimpleModbusSlave library is wrong.

If you post code, always use code tags! (that’s the </> button in the editor)

thanks for the reply .
ok i will try your way one arduino master rtu and tcp slave. thank you again.

i did it finally. it's worked.
thanks for your help dude .