5

I have this project where I need a modbus tcp server that will host a series of sensor data for other modbus client devices to read. I use this Library by Andresoarmento

This is the code i am using from the library example:

#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>
//Modbus Registers Offsets (0-9999)
const int SENSOR_IREG = 100;
//Used Pins
//const int sensorPin = A0;
//ModbusIP object
ModbusIP mb;
long ts;
void setup() {
 // The media access control (ethernet hardware) address for the shield
 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 // The IP address for the shield
 byte ip[] = { 192, 168, 1, 120 };
 //Config Modbus IP
 mb.config(mac, ip);
 // Add SENSOR_IREG register - Use addIreg() for analog Inputs
 int i = 2200;
 mb.addIreg(SENSOR_IREG,i);
 ts = millis();
}
void loop() {
 //Call once inside loop() - all magic here
 mb.task();
 //Read each two seconds
 if (millis() > ts + 2000) {
 ts = millis();
 //Setting raw value (0-1024)
 int i = 0;
 i++;
 mb.Ireg(SENSOR_IREG, i);
 }

The enj28j60 module is working as i tested it. So, I used a modbus scanner(CAS SCANNER) which was unable to detect it. Can anyone tell me how to get this all working and test it?

Thank you in advance.

asked Sep 11, 2020 at 6:36

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.