Giter Club home page Giter Club logo

Comments (4)

goddland16 avatar goddland16 commented on July 20, 2024

Define it in your code which module is used ENC28J60 or wiznet module. Read user guide and make necessary changes in the code.

from modbus-tcp.

santhosh1211 avatar santhosh1211 commented on July 20, 2024

I did defining module which i'm using was ENC28J60. but the example program given is giving the same compilation error

from modbus-tcp.

santhosh1211 avatar santhosh1211 commented on July 20, 2024

`/*
This is Modbus test code to demonstrate all the Modbus functions with
with Ethernet IC ENC28J60

ModbusTCP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ModbusTCP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ModbusTCP. If not, see http://www.gnu.org/licenses/.

Adopted from ModbusMaster for RTU over RS-485 by Doc Walker
Modified by Narendra Dehury for TCP.
copyright @ phoenixrobotix.com

*/
#define ENC28J60 = 1
#define WIZNET_W5100 = 0
#define ESP8266 = 0

unsigned int param_value_int[7];
#include <UIPEthernet.h>
#include <avr/wdt.h>

IPAddress ModbusDeviceIP(10, 10, 108, 211);
IPAddress moduleIPAddress(10, 10, 108, 23); // Anything other than the device IP Address
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE1 };

#include <ModbusTCP.h>

ModbusTCP node(1);

void setup()
{
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

Serial.begin(9600);
//wdt_enable(WDTO_4S);
//WDTCSR |= _BV(WDIE);
wdt_disable();
delay(1000);
Ethernet.begin(mac, moduleIPAddress);
node.setServerIPAddress(ModbusDeviceIP);
Serial.println("Setup");
delay(6000);

}

void loop()
{
uint8_t result;

// node.setTransactionID(random(100));
result = node.readHoldingRegisters(1, 12);
Serial.print("hola: ");
Serial.println(result, HEX);
//if(result == node.MBServerConnectionTimeOut)
if(result != 0)
{
node.MBconnectionFlag = 0;
Serial.println("TimeOut");
if(result == 5) {

  //Ethernet.begin(mac, moduleIPAddress);
  wdt_enable(WDTO_8S);
  WDTCSR |= _BV(WDIE);
}

delay(6000);

}
int len = node.getResponseBufferLength();
Serial.println("Response Length: " + String(len));
for (byte j = 0; j < len; j++)
{
Serial.print(node.getResponseBuffer(j));
Serial.print(" ");
}
Serial.println();
node.clearResponseBuffer();
delay(100);

// node.writeSingleRegister(5, 3);
// Serial.println(result, HEX);
// delay(500);

// for (byte i = 0; i < 5; i++)
// {
// node.setTransmitBuffer(i, (i+100));
// }
// node.writeMultipleRegisters(2, 5);
// Serial.println(result, HEX);
// delay(500);

// node.writeSingleCoil(20, 1);
// delay(500);

node.setTransmitBuffer(0, 0b1010101001010101);
//
node.writeMultipleCoils(20, 16);
delay(500);
result = node.readCoils(20, 18);
len = node.getResponseBufferLength();
Serial.println("Response Length: " + String(len));
Serial.println(node.getResponseBuffer(0), BIN);
delay(200);

result = node.readHoldingRegisters(2, 8);
len = node.getResponseBufferLength();
Serial.println("Response Length: " + String(len));
for (byte j = 0; j < len; j++)
{
param_value_int[j] = node.getResponseBuffer(j);
Serial.print(param_value_int[j]);
Serial.print(" ");
}
Serial.println();
node.clearResponseBuffer();
delay(10000);
}

`

pls give some suggestion if anything wrong i'm using arduino compiler.

from modbus-tcp.

tuantran1501 avatar tuantran1501 commented on July 20, 2024

Hi santhosh1211,
In "ModbusTCP.h" file, you should comment out 3 lines below by ' // ':
#ifndef WIZNET_W5100
#ifndef ENC28J60
#ifndef ESP8266

You will solve the problem.

from modbus-tcp.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.