Need help Modbusmaster library

Hello All,

I found failed to compile below code. I intend to use Mega as a master to read data from slave device.

I have attached library I use for reference. Much appreciated for the guidance or lead me to similar issue where can I learn from.

[//#include <Wire.h>
#include <SimpleModbusMaster.h>
//#include <SoftwareSerial.h>
////////// Prot information ////////////
#define baud 9600
#define timeout 100
#define polling 100
#define retry_count 10
#define TxEnablePin 2
#define TOTAL_NO_OF_REGISTERS 13

enum
{
PACKET1,
PACKET2,
PACKET3,
PACKET4,
//PACKET2,
TOTAL_NO_OF_PACKETS //leave this last entry.
};

Packet packets[TOTAL_NO_OF_PACKETS];
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
Serial.begin(9600);
modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10);
modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

}

void loop() {
modbus_update();
float RDSS;
RDSS = regs[10];
Serial.print("READ = ");
Serial.println(RDSS);
delay(1000);
}[

C:\Users\hp\Downloads\Modbus\Modbus.ino: In function ‘void setup()’:

Modbus:34:42: error: ‘READ_INPUT_REGISTERS’ was not declared in this scope

modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

^~~~~~~~~~~~~~~~~~~~

C:\Users\hp\Downloads\Modbus\Modbus.ino:34:42: note: suggested alternative: ‘READ_HOLDING_REGISTERS’

modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

^~~~~~~~~~~~~~~~~~~~

READ_HOLDING_REGISTERS

Modbus:34:3: error: ‘modbus_construct’ was not declared in this scope

modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

^~~~~~~~~~~~~~~~

C:\Users\hp\Downloads\Modbus\Modbus.ino:34:3: note: suggested alternative: ‘modbus_configure’

modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

^~~~~~~~~~~~~~~~

modbus_configure

Modbus:35:21: error: ‘Serial1’ was not declared in this scope

modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs); //กำหนดค่าตามเครื่องที่จะใช้อ่านค่า

^~~~~~~

C:\Users\hp\Downloads\Modbus\Modbus.ino:35:21: note: suggested alternative: ‘Serial’

modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs); //กำหนดค่าตามเครื่องที่จะใช้อ่านค่า

^~~~~~~

Serial

C:\Users\hp\Downloads\Modbus\Modbus.ino: In function ‘void loop()’:

Modbus:40:17: error: too few arguments to function ‘unsigned int modbus_update(Packet*)’

modbus_update();

^

In file included from C:\Users\hp\Downloads\Modbus\Modbus.ino:8:0:

C:\Program Files (x86)\Arduino\libraries\SimpleModbusMaster/SimpleModbusMaster.h:142:14: note: declared here

unsigned int modbus_update(Packet* packets);

^~~~~~~~~~~~~

exit status 1
‘READ_INPUT_REGISTERS’ was not declared in this scope

]

simplemodbusng-master (1).zip (37.4 KB)

Here is my code

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  For Arduino Mega 2560   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 //    https://www.myarduino.net/product/32/arduino-mega-2560-r3-%E0%B8%9E%E0%B8%A3%E0%B9%89%E0%B8%AD%E0%B8%A1-%E0%B8%AA%E0%B8%B2%E0%B8%A2usb
 //    https://www.myarduino.net/product/768/max485-module-rs485-module-ttl-turn-rs-485-module
 //    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#include <Wire.h>
#include <SimpleModbusMaster.h>
//#include <SoftwareSerial.h>
////////// Prot information ////////////
#define baud 9600  
#define timeout 100 
#define polling 100 
#define retry_count 10
#define TxEnablePin 2 
#define TOTAL_NO_OF_REGISTERS 13 

enum 
{
  PACKET1,
  PACKET2,
  PACKET3,
  PACKET4,
  //PACKET2,
  TOTAL_NO_OF_PACKETS //leave this last entry.
};

Packet packets[TOTAL_NO_OF_PACKETS]; 
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup() 
{
  Serial.begin(9600);
  modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); 
  modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);  

}

void loop() {
  modbus_update(); 
  float RDSS;
  RDSS = regs[10];
  Serial.print("READ = ");
  Serial.println(RDSS);
  delay(1000);
}

Here is error

C:\Users\hp\Downloads\Modbus\Modbus.ino: In function 'void setup()':

Modbus:34:42: error: 'READ_INPUT_REGISTERS' was not declared in this scope

   modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

                                          ^~~~~~~~~~~~~~~~~~~~

C:\Users\hp\Downloads\Modbus\Modbus.ino:34:42: note: suggested alternative: 'READ_HOLDING_REGISTERS'

   modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

                                          ^~~~~~~~~~~~~~~~~~~~

                                          READ_HOLDING_REGISTERS

Modbus:34:3: error: 'modbus_construct' was not declared in this scope

   modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

   ^~~~~~~~~~~~~~~~

C:\Users\hp\Downloads\Modbus\Modbus.ino:34:3: note: suggested alternative: 'modbus_configure'

   modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 512, 1, 10); // 1 ตัวแรกคือตำแหน่งเครื่องที่จะอ่านค่า/512 คือค่าตำแหน่ง Register.

   ^~~~~~~~~~~~~~~~

   modbus_configure

Modbus:35:21: error: 'Serial1' was not declared in this scope

   modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);   //กำหนดค่าตามเครื่องที่จะใช้อ่านค่า

                     ^~~~~~~

C:\Users\hp\Downloads\Modbus\Modbus.ino:35:21: note: suggested alternative: 'Serial'

   modbus_configure(&Serial1, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);   //กำหนดค่าตามเครื่องที่จะใช้อ่านค่า

                     ^~~~~~~

                     Serial

C:\Users\hp\Downloads\Modbus\Modbus.ino: In function 'void loop()':

Modbus:40:17: error: too few arguments to function 'unsigned int modbus_update(Packet*)'

   modbus_update();

                 ^

In file included from C:\Users\hp\Downloads\Modbus\Modbus.ino:8:0:

C:\Program Files (x86)\Arduino\libraries\SimpleModbusMaster/SimpleModbusMaster.h:142:14: note: declared here

 unsigned int modbus_update(Packet* packets);

              ^~~~~~~~~~~~~

exit status 1
'READ_INPUT_REGISTERS' was not declared in this scope