Hi,
Currently I'm working on a project where I need a connection between an Arduino and a PLC operating on Codesys software. For this connection I've chosen to use an Arduino Ethernet shield and Modbus to communciate with the PLC.
I've got the connection set up and I can set registers with the Arduino, and read registers with the PLC, but there is a problem: the PLC only updates the variables every 4 seconds. I've read some online forums where people talked about a TCP Push bit and a 'nodelay' activation or something, but i can't seem to find this anywhere in the Mudbus Library. Any ideas how to get a faster connection?
Hardware and software:
- Arduino: Uno and access to a Mega
- Mudbus library - mudbus/Mudbus at master · luizcantoni/mudbus · GitHub
- PLC: Hitachi PLC with Codesys
#include <SPI.h>
#include <Ethernet.h>
#include "Mudbus.h"
Mudbus Mb;
//Function codes 1(read coils), 3(read registers), 5(write coil), 6(write register)
//signed int Mb.R[0 to 125] and bool Mb.C[0 to 128] MB_N_R MB_N_C
//Port 502 (defined in Mudbus.h) MB_PORT
void setup()
{
uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x51, 0x06 };
uint8_t ip[] = { 172, 16, 40, 215 };
uint8_t gateway[] = { 172, 16, 40, 254 };
uint8_t subnet[] = { 255, 255, 0, 0 };
Ethernet.begin(mac, ip, gateway, subnet);
//Avoid pins 4,10,11,12,13 when using ethernet shield
delay(5000);
Serial.begin(9600);
}
void loop()
{
Mb.Run();
Mb.R[0] = Mb.R[0] + 123;
Mb.R[1] = Mb.R[1] + 123;
delay(1000);
}