problem with Modbus communication

hello my friends,
I have some basic problem with Modbus libraries, I can't understand these codes and how to use of these codes......could you help me?

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

what reason for use of this code, I mean What is "enum" for? what is "TOTAL_NO_OF_PACKETS" for?

and these codes------>>>>>

Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
packetPointer packet2 = &packets[PACKET2];
packetPointer packet3 = &packets[PACKET3];
packetPointer packet4 = &packets[PACKET4];
packetPointer packet5 = &packets[PACKET5];

and this code---->>

unsigned int readRegs4[1];
unsigned int writeRegs[1];

thank you

what reason for use of this code, I mean What is "enum" for? what is "TOTAL_NO_OF_PACKETS" for?

That's a not very elegant way to catch the number of packets available.

It's probably easier and much more intuitive to simply define the TOTAL_NO_OF_PACKETS in a precompiler directive.
Choose another ModBus library if you don't have another good reason to stay with this.

first of all post a link to the library you are talking about.

enum is an enumeration. It can be used to avoid "magic numbers" in the code.

consider the code doing following

enum
{
  PACKET1,                     // const byte PACKET1 = 0; 
  PACKET2,                     // const byte PACKET2 = 1;
  PACKET3,                     // const byte PACKET3 = 2;
  PACKET4,                     // const byte PACKET4 = 3;
  PACKET5,                     // const byte PACKET5 = 4;
  TOTAL_NO_OF_PACKETS // const byte TOTAL_NO_OF_PACKETS  = 5; // totally right, isn't it?
};

afterwards, instead of refering to the 3rd packet, you don't have to write "2" (C++ counts start at 0), but you can use PACKET3 instead.
If you need the Total Number of Packets ... you have it clearly defined as TOTAL_NO_OF_PACKETS.

if you want to test your code and you comment out PACKET2 - PACKET5, leaving just PACKET1 and PACKET2 active, TOTAL_NO_OF_PACKETS gets "automatically" 2 ... perfect right again.

So this construct is very handy (at least for me).