I want to connect modbus TCP/IP from mega2560 using W5100 to Laptop and read the holding register, using modbus simulation, here is the code but it not work, it shows " no matching function for call to ' modbustTCP(int)', Could you show me how to fix that problem ? thanks you. This code is example modbus TCP Master W5100.!
[code] :
/
This is Modbus test code to demonstrate all the Modbus functions with
with Ethernet IC WIZNET W5100
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 WIZNET_W5100 1unsigned int param_value_int[7];
#include <Ethernet.h>IPAddress ModbusDeviceIP(192, 168, 1, 8); // Put IP Address of PLC here
IPAddress moduleIPAddress(192, 168, 1, 7); // Assign Anything other than the PLC IP Addressbyte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
#include <ModbusTCP.h>
ModbusTCP node(1); // Unit Identifier.
void setup()
{pinMode(4, OUTPUT);
digitalWrite(4, HIGH); // To disable slave select for SD card; depricated.Serial.begin(9600);
delay(1000);
Ethernet.begin(mac, moduleIPAddress);
node.setServerIPAddress(ModbusDeviceIP);
delay(500); // To provide sufficient time to initialize.}
void loop()
{
uint8_t result;node.setTransactionID(random(100)); // Not necessary; but good to distinguish each frame individually.
result = node.readHoldingRegisters(0, 1); // Read Holding RegistersSerial.println(result, HEX);
if (result != 0)
{
Serial.println("TimeOut");delay(6000);
}int len = node.getResponseBufferLength();
Serial.println("Response Length: " + String(len));// See the length of data packet received.
for (byte j = 0; j < len; j++)
{
Serial.print(node.getResponseBuffer(j)); // Inspect the data.
Serial.print(" ");
}
Serial.println();
node.clearResponseBuffer();
delay(100);/
node.writeSingleRegister(5, 3); // Write single register
Serial.println(result, HEX);
delay(500);
for (byte i = 0; i < 5; i++)
{
node.setTransmitBuffer(i, (i+100));
}
node.writeMultipleRegisters(2, 5); // Write multiple register
Serial.println(result, HEX);
delay(500);
node.writeSingleCoil(20, 1); // Write Single coil
delay(500);
node.setTransmitBuffer(0, 0b1010101001010101);
node.writeMultipleCoils(20, 16); // Write multiple coils
delay(500);
result = node.readCoils(20, 18);
len = node.getResponseBufferLength();
Serial.println("Response Length: " + String(len));
Serial.println(node.getResponseBuffer(0), BIN);
node.clearResponseBuffer();/
delay(500);
}`