1

I am using the following https://code.google.com/p/simple-modbus/ arduino master library code. In order to communicate with my industrial drive.

All seems right but I am getting some weird errors. I am using the arduino master code as it is. With just the difference in modbus_construct.

Here is the error I am getting

 This report would have more information with
 "Show verbose output during compilation"


enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
In file included from SimpleModbusMasterArduino.ino:29:

C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:131: error: expected ',' or '...' before numeric constant
In file included from C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:28,
                 from C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:215,
                 from SimpleModbusMasterArduino.ino:29:
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Stream.h:57: error: expected ',' or '...' before numeric constant
In file included from SimpleModbusMasterArduino.ino:29:
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:222: error: expected ',' or '...' before numeric constant
SimpleModbusMasterArduino:37: error: 'Packet' does not name a type
SimpleModbusMasterArduino.ino: In function 'void setup()':
SimpleModbusMasterArduino:45: error: 'packets' was not declared in this scope
SimpleModbusMasterArduino:45: error: 'READ_HOLDING_REGISTERS' was not declared in this scope
SimpleModbusMasterArduino:45: error: 'modbus_construct' was not declared in this scope

SimpleModbusMasterArduino:49: error: 'modbus_configure' was not declared in this scope SimpleModbusMasterArduino.ino: In function 'void loop()': SimpleModbusMasterArduino:56: error: 'modbus_update' was not declared in this scope

Here is my code:

#include <SimpleModbusMaster.h>

/*
   The example will use packet1 to read a register from address 0 (the adc ch0 value)
   from the arduino slave (id=1). It will then use this value to adjust the brightness
   of an led on pin 9 using PWM.
   It will then use packet2 to write a register (its own adc ch0 value) to address 1 
   on the arduino slave (id=1) adjusting the brightness of an led on pin 9 using PWM.
*/

//////////////////// Port information ///////////////////
#define baud 115200
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2 
#define LED 13


// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 8
#define TOTAL_NO_OF_CONSTANTS 1

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  //PACKET2,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Initialize each packet
  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0x3000, 8, 0);
  //modbus_construct(&packets[PACKET2], 2, READ_HOLDING_REGISTERS, 0x3000, 8, 16);

  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);

  pinMode(LED, OUTPUT);
}

void loop()
{
  modbus_update();
  Serial.println(regs[0]);
  //regs[0] = analogRead(0); // update data to be written to arduino slave

  //analogWrite(LED, regs[0]>>2); // constrain adc value from the arduino slave to 255
}

migrated from electronics.stackexchange.com Jan 8 '16 at 6:44

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

1

Your issue is that you define constants, such as timeout, which are widely used in Arduino library as parameter names. After preprocessing your definitions, correct code in "Arduino.h" such as

unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);

becomes

unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long 1000);

No wonder the latter line fails to compile.

You will need to find unique names for your defines, or use constant variables instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy