Communicating Between Arduino and HMI Through Modbus TCP/IP

Hello Guys,

I have an Arduino Mega 2560 (W5100 Ethernet shield plugged on it ) and an HMI which is PRO-FACE GP-4301TM.

I want to make an application using them over the Modbus TCP/IP protocol.

At the moment, I provided a connection among them with the following code;

#include <Ethernet.h>



byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //ethernet modülün mac adresi

byte ip[] = { 192, 168, 1, 80 };                      // yerel ağ içerisinde kullanabileceğiniz ip adresi örneğin ("192.168.1.178")

byte gateway[] = { 192, 168, 1, 1 };                   // vereceğiniz ip nin ilk değerinden sonra iki tane 0 ve sona 1 vermeniz yeterli

byte subnet[] = { 255, 255, 255, 0 };                  // bu ayarları ip4 üzerinden manuel yapmanız gerektiğine dikkat edin

EthernetServer server(502);                             //haberleşeceğimiz port adresi

String readString;                                // tarayıcı üzerinden göndereceğimiz string (dizi) tanımlaması



void setup() {





Ethernet.begin(mac, ip, gateway, subnet); // ethernet başlatıldı

server.begin(); // sunucu başlatıldı

}



void loop() {

EthernetClient client = server.available(); // sunucu mevcutken ethernet kullanıcısı tanımlandı

Serial.print(client.connected());

if (client) {

while (client.connected()) { // kullanıcı bağlıyken

if (client.available()) { // ve de mevcutken

char c = client.read();  // kullanıcı isteğini okuyup karakter c ye eşitleme





Serial.print(c); // isterseniz serial monitörden çift // kaldırarak görüntüleyebilirsiniz

}





client.stop(); // kullanıcı sonlandırma



}

}

}

I corresponded to the communication right now, checked with the ModBul Master program.
However, I am not able to send any command right now because I don't know how to send a specific command over the Modbus TCP/IP protocol.

Do you have any recommends or examples that will provide me to be more familiar with how can I send a command over Modbus TCP IP?

Thanks,
Halit.

I guess your HMI is a display. Does that act as a Modbus TCP server or client? Why did you fail to provide a link to the relevant manual?

In fact, HMI is a touchscreen and I will use it as a display only. My aim is reading Digital and/or Analog inputs via something (Arduino etc) and delivering it to the PC via Serial or Ethernet. On PC we will process the values on Python and then we will deploy to the HMI's. I rather use all communication as Ethernet, you can see the topology enclosed.

Therefore, I didn't find many examples of TCP/IP protocols on the internet, it may seem legit to use Serial for Arduino maybe but I will give a shot for ethernet! However, I'm open to suggestions.

Thanks,
Halit.