Program COmpile Error

I have Below code . i am getting Error like this.

main:24: error: 'Modbus' does not name a type
main.ino: In function 'void setup()':
main:55: error: 'slave' was not declared in this scope
main.ino: In function 'void loop()':
main:64: error: 'slave' was not declared in this scope
Modbus_c.ino: At global scope:
Modbus_c:20: error: expected identifier before numeric constant
Modbus_c:20: error: expected `}' before numeric constant
Modbus_c:20: error: expected unqualified-id before numeric constant
Modbus_c:27: error: expected declaration before '}' token

main.zip (6.03 KB)

/**
 *  Modbus object declaration
 *  u8id : node id = 0 for master, = 1..247 for slave
 *  u8serno : serial port (use 0 for Serial)
 *  u8txenpin : 0 for RS-232 and USB-FTDI
 *               or any pin number > 1 for RS-485
 *
 * pin maping:
 * 2 - digital input
 * 3 - digital input
 * 4 - digital input
 * 5 - digital input
 * 6 - digital output
 * 7 - digital output
 * 8 - digital output
 * 9 - digital output
 * 10 - analog output
 * 11 - analog output
 * 14 - analog input
 * 15 - analog input
 */
#define ID   3

Modbus slave(ID, 0, 0);

Do you see anything there that tells the compiler what a "Modbus" is?
No, me neither.

Modbus_c:20: error: expected identifier before numeric constant

What you see  uint8_t au8Buffer[MAX_BUFFER];
what the compiler sees uint8_t au8Buffer[64 /];

Its class defined Under MOdbus right.
Which is defined under modbus file already

#define  MAX_BUFFER  64

Its class defined Under MOdbus right.

Yes.
But you haven’t told “main” about it.

#define  MAX_BUFFER  64

That’s better.

Start here

But its not library to add. Its just program which contain main and another c file

Please see reply #1

since compilation start from main.ino and there is not any forward declaration of Modbus class
so that it is showing error

main:24: error: 'Modbus' does not name a type

i started compilation from Modbus_c.ino after putting

#define MAX_BUFFER 64

and not got any error

since compilation start from main.ino and there is not any forward declaration of Modbus class
so that it is showing error

How to compile this code

create a folder with name Modbus_c
and inside this folder paste your code Modbus_c.ino and main.ino
after that open Modbus_c (it is on 1st tab and main.ino on 2nd tab ).
then changes

#define MAX_BUFFER 64

and then compile it.

still the same error..??

how to put address in any MODBUS software

which address??

Be careful, you use a define named ‘ID’ in your sketch.

This is defined in an enum in Modbus_c. If you try and use that enum value in code after the define, you will get your define instead, you will most probably never receive an error ( unless assigning to an enum object ).

Here i have above code. Here they specify the slave ID, Function code,slave address and NUm of coil.
Assume that i want to blink led 13 how to provide information here
slave ID know:

#define ID   1

Function code can be given read or write format.
How to give address here,
What Does it means.

pin maping:

  • 2 - digital input
  • 3 - digital input
  • 4 - digital input
  • 5 - digital input
  • 6 - digital output
  • 7 - digital output
  • 8 - digital output
  • 9 - digital output
  • 10 - analog output
  • 11 - analog output
  • 14 - analog input
  • 15 - analog input

The program is compiled properly and also uploaded succesfully. I am facing problem getting responses from slave. Some time i get data. Some time i am getting error message like this. I have assigned slave ID from 3 to 1.I have attached error I am getting . Let me know what situation i get this error

How to give address here,

you can give addrss when u create an object.
Modbus ob(1,0,0);
first parameter is address of your slave (1 to 127).

that i have already created

.Modbus slave(ID, 0, 0);

where  u8id : node id = 0 for master, = 1..247 for slave
 *  u8serno : serial port (use 0 for Serial)
 *  u8txenpin : 0 for RS-232 and USB-FTDI
 *               or any pin number > 1 for RS-485

It Gives error like this.