Project

General

Profile

modbus tcp for enc28j60

Added by teding over 5 years ago

I want to create a libary for modbus master/slave,
I started out with the MgsModbus.h libary (for ethernet shield)
So I start polling on port 502 as slave, using the Ethernet::buffer to process the incoming message.
But now i’am stucked on how to send a response back
Can i use tcpSend() and do i use bufferFiller or stash ?
Any sugestions,

Marc

void MgsModbus::MbsRun()
{  
  //****************** Read from socket ****************
  byte len = ether.packetReceive();
  byte pos = ether.packetLoop(len);
  MbsByteArray = &Ethernet::buffer[pos];
    for (int i =0 ; i< (len-pos) ; i++) {
      if (MbsByteArray[i] < 0x10) Serial.print("0");
      Serial.print(MbsByteArray[i],HEX);
      Serial.print(" ");
    }  

   MbsFC = SetFC(MbsByteArray[7]);  //Byte 7 of request is FC

Replies (1)

RE: modbus tcp for enc28j60 - Added by teding over 5 years ago

Update,
I send out the response of the slave with a modified
httpServerReply(), I removed |TCP_FLAGS_FIN_V from
gPB[TCP_FLAGS_P] = TCP_FLAGS_ACK_V|TCP_FLAGS_PUSH_V|TCP_FLAGS_FIN_V;
To keep the connection open.

As master i use a modified verion of tcpSend(), this one is not using the stash, because with the stash buffer it seems
impossible to send byte’s with 0x00.
All seems to start working, But i really hate to alter the core ethercard files for this,
I just want to add a extra modbus.cpp.
Any sugestions please comment

    (1-1/1)